Skip to content

Commit

Permalink
Merge pull request #9 from netglue/qa-phpcs
Browse files Browse the repository at this point in the history
QA phpcs
  • Loading branch information
gsteel committed Mar 3, 2021
2 parents 3391992 + cc51ace commit 39b09ca
Show file tree
Hide file tree
Showing 76 changed files with 395 additions and 326 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ All notable changes to this project will be documented in this file, in reverse

- [#8](https://github.com/netglue/primo/pull/8) Improves CI by using [the matrix action from the Laminas project](https://github.com/laminas/laminas-ci-matrix-action).
- [#8](https://github.com/netglue/primo/pull/8) Also updates dependencies, fixing test failures on 8 _(Out of date PHPUnit)_ and fixing a test failure due to copy/paste of a duplicate route name.
- [#9](https://github.com/netglue/primo/pull/9) Cleans up CS so it's the same as the adopted coding standard.

### Deprecated

Expand Down
6 changes: 0 additions & 6 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@

<!-- Inherit rules from Doctrine Coding Standard -->
<rule ref="Doctrine">
<exclude name="SlevomatCodingStandard.TypeHints.DeclareStrictTypes.IncorrectWhitespaceBetweenOpenTagAndDeclare"/>
<!-- I like return types to look like this: ") :? Type" or ") : Type" -->
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHintSpacing.WhitespaceAfterNullabilitySymbol" />
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHintSpacing.NoSpaceBetweenColonAndNullabilitySymbol" />
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHintSpacing.WhitespaceBeforeColon" />

<!-- Whilst this lib is compatible with 7.3, exclude this sniff -->
<exclude name="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint" />
</rule>
Expand Down
1 change: 1 addition & 0 deletions src/Cache/PrismicApiCache.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Primo\Cache;
Expand Down
7 changes: 4 additions & 3 deletions src/ConfigProvider.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Primo;
Expand All @@ -12,7 +13,7 @@ final class ConfigProvider
public const DEFAULT_WEBHOOK_URL = '/prismic-webhook';

/** @return mixed[] */
public function __invoke() : array
public function __invoke(): array
{
return [
'prismic' => [
Expand Down Expand Up @@ -48,7 +49,7 @@ public function __invoke() : array
}

/** @return mixed[] */
private function dependencies() : array
private function dependencies(): array
{
return [
'factories' => [
Expand Down Expand Up @@ -78,7 +79,7 @@ private function dependencies() : array
}

/** @return mixed[] */
private function routing() : array
private function routing(): array
{
return [
'params' => [
Expand Down
3 changes: 2 additions & 1 deletion src/Container/ApiFactory.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Primo\Container;
Expand All @@ -14,7 +15,7 @@

final class ApiFactory
{
public function __invoke(ContainerInterface $container) : Api
public function __invoke(ContainerInterface $container): Api
{
$config = $container->has('config') ? $container->get('config') : [];
$apiUrl = $config['prismic']['api'] ?? null;
Expand Down
3 changes: 2 additions & 1 deletion src/Container/LinkResolverFactory.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Primo\Container;
Expand All @@ -12,7 +13,7 @@

final class LinkResolverFactory
{
public function __invoke(ContainerInterface $container) : LinkResolver
public function __invoke(ContainerInterface $container): LinkResolver
{
return new LinkResolver(
$container->get(RouteParams::class),
Expand Down
3 changes: 2 additions & 1 deletion src/Container/StandardResultSetFactoryFactory.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Primo\Container;
Expand All @@ -9,7 +10,7 @@

final class StandardResultSetFactoryFactory
{
public function __invoke(ContainerInterface $container) : ResultSetFactory
public function __invoke(ContainerInterface $container): ResultSetFactory
{
return new StandardResultSetFactory();
}
Expand Down
5 changes: 3 additions & 2 deletions src/Content/Document.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Primo\Content;
Expand All @@ -18,13 +19,13 @@ public function __construct(DocumentData $data)
}

/** @param string|int $name */
public function get($name) : Fragment
public function get($name): Fragment
{
return $this->data->content()->get($name);
}

/** @param string|int $name */
public function has($name) : bool
public function has($name): bool
{
return $this->data->content()->has($name);
}
Expand Down
11 changes: 6 additions & 5 deletions src/Event/WebhookEvent.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Primo\Event;
Expand All @@ -23,22 +24,22 @@ private function __construct(object $payload)
$this->received = time();
}

public static function new(object $payload) : self
public static function new(object $payload): self
{
return new static($payload);
}

public function received() : DateTimeImmutable
public function received(): DateTimeImmutable
{
return DateTimeImmutable::createFromFormat('U', (string) $this->received, new DateTimeZone('UTC'));
}

public function payload() : object
public function payload(): object
{
return $this->payload;
}

public function serialize() : string
public function serialize(): string
{
return Json::encode([
'received' => $this->received,
Expand All @@ -47,7 +48,7 @@ public function serialize() : string
}

/** @param mixed $serialized */
public function unserialize($serialized) : void
public function unserialize($serialized): void
{
$object = Json::decodeObject($serialized);
$this->payload = $object->payload;
Expand Down
1 change: 1 addition & 0 deletions src/Exception/ConfigurationError.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Primo\Exception;
Expand Down
1 change: 1 addition & 0 deletions src/Exception/InvalidArgument.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Primo\Exception;
Expand Down
1 change: 1 addition & 0 deletions src/Exception/PrimoError.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Primo\Exception;
Expand Down
9 changes: 5 additions & 4 deletions src/Exception/RequestError.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Primo\Exception;
Expand All @@ -13,15 +14,15 @@ class RequestError extends RuntimeException implements PrimoError
/** @var RequestInterface|null */
private $request;

public static function withRequest(RequestInterface $request, string $message, int $code) : self
public static function withRequest(RequestInterface $request, string $message, int $code): self
{
$error = new static($message, $code);
$error->request = $request;

return $error;
}

public static function withMissingRouteResult(RequestInterface $request) : self
public static function withMissingRouteResult(RequestInterface $request): self
{
$message = sprintf(
'The request for %s failed because the route result was not available. This means that routing has ' .
Expand All @@ -32,7 +33,7 @@ public static function withMissingRouteResult(RequestInterface $request) : self
return self::withRequest($request, $message, 500);
}

public static function withMissingTemplateAttribute(RequestInterface $request, string $expectedTemplateAttribute) : self
public static function withMissingTemplateAttribute(RequestInterface $request, string $expectedTemplateAttribute): self
{
$message = sprintf(
'The request for "%s" failed because there was no template attribute found in the request. I was ' .
Expand All @@ -44,7 +45,7 @@ public static function withMissingTemplateAttribute(RequestInterface $request, s
return self::withRequest($request, $message, 500);
}

public function getRequest() :? RequestInterface
public function getRequest(): ?RequestInterface
{
return $this->request;
}
Expand Down
9 changes: 5 additions & 4 deletions src/Exception/RoutingError.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Primo\Exception;
Expand All @@ -14,7 +15,7 @@

class RoutingError extends RuntimeError
{
public static function uidMatchedWithoutType(RouteResult $routeResult) : self
public static function uidMatchedWithoutType(RouteResult $routeResult): self
{
return new static(sprintf(
'The route named "%s" matches a Prismic UID, but the type cannot be resolved. You cannot resolve documents '
Expand All @@ -24,7 +25,7 @@ public static function uidMatchedWithoutType(RouteResult $routeResult) : self
), 400);
}

public static function nonUniqueResult(RouteResult $routeResult, ResultSet $resultSet) : self
public static function nonUniqueResult(RouteResult $routeResult, ResultSet $resultSet): self
{
return new static(sprintf(
'The route named "%s" matched %d documents when transformed into a query. Route parameters were: %s',
Expand All @@ -34,14 +35,14 @@ public static function nonUniqueResult(RouteResult $routeResult, ResultSet $resu
), 400);
}

protected static function routeName(RouteResult $routeResult) : string
protected static function routeName(RouteResult $routeResult): string
{
$routeName = $routeResult->getMatchedRouteName();

return $routeName ?: '[Unnamed Route]';
}

protected static function matchedParams(RouteResult $routeResult) : string
protected static function matchedParams(RouteResult $routeResult): string
{
return json_encode($routeResult->getMatchedParams(), JSON_THROW_ON_ERROR);
}
Expand Down
1 change: 1 addition & 0 deletions src/Exception/RuntimeError.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Primo\Exception;
Expand Down
1 change: 1 addition & 0 deletions src/Http/PrismicHttpClient.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Primo\Http;
Expand Down
3 changes: 2 additions & 1 deletion src/Http/PrismicHttpClientFactory.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Primo\Http;
Expand All @@ -9,7 +10,7 @@

class PrismicHttpClientFactory
{
public function __invoke(ContainerInterface $container) : ClientInterface
public function __invoke(ContainerInterface $container): ClientInterface
{
if ($container->has(ClientInterface::class)) {
return $container->get(ClientInterface::class);
Expand Down
11 changes: 6 additions & 5 deletions src/LinkResolver.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Primo;
Expand Down Expand Up @@ -33,7 +34,7 @@ public function __construct(RouteParams $routeParams, RouteMatcher $matcher, Url
$this->urlHelper = $urlHelper;
}

public function resolve(Link $link) :? string
public function resolve(Link $link): ?string
{
if ($link instanceof UrlLink) {
return $link->url();
Expand All @@ -46,7 +47,7 @@ public function resolve(Link $link) :? string
return null;
}

private function resolveDocumentLink(DocumentLink $link) :? string
private function resolveDocumentLink(DocumentLink $link): ?string
{
if ($link->isBroken()) {
return null;
Expand All @@ -67,7 +68,7 @@ private function resolveDocumentLink(DocumentLink $link) :? string
}

/** @return string[] */
private function routeParams(DocumentLink $link) : array
private function routeParams(DocumentLink $link): array
{
/**
* You cannot use tags to construct a url from scratch because there is no way of knowing which
Expand All @@ -82,7 +83,7 @@ private function routeParams(DocumentLink $link) : array
];
}

private function bookmarkNameByDocumentId(string $id) :? string
private function bookmarkNameByDocumentId(string $id): ?string
{
foreach ($this->bookmarks as $bookmark) {
if ($bookmark->documentId() === $id) {
Expand All @@ -93,7 +94,7 @@ private function bookmarkNameByDocumentId(string $id) :? string
return null;
}

private function url(DocumentLink $link, Route $route) : string
private function url(DocumentLink $link, Route $route): string
{
$options = $route->getOptions();
$reuseResultParams = $options['defaults'][$this->routeParams->reuseResultParams()] ?? true;
Expand Down
3 changes: 2 additions & 1 deletion src/Middleware/Container/DocumentResolverFactory.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Primo\Middleware\Container;
Expand All @@ -9,7 +10,7 @@

final class DocumentResolverFactory
{
public function __invoke(ContainerInterface $container) : DocumentResolver
public function __invoke(ContainerInterface $container): DocumentResolver
{
return new DocumentResolver(
$container->get(Resolver::class)
Expand Down
3 changes: 2 additions & 1 deletion src/Middleware/Container/ExpiredPreviewHandlerFactory.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Primo\Middleware\Container;
Expand All @@ -8,7 +9,7 @@

class ExpiredPreviewHandlerFactory
{
public function __invoke(ContainerInterface $container) : ExpiredPreviewHandler
public function __invoke(ContainerInterface $container): ExpiredPreviewHandler
{
$config = $container->has('config') ? $container->get('config') : [];

Expand Down
3 changes: 2 additions & 1 deletion src/Middleware/Container/InjectRequestCookiesFactory.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Primo\Middleware\Container;
Expand All @@ -9,7 +10,7 @@

final class InjectRequestCookiesFactory
{
public function __invoke(ContainerInterface $container) : InjectRequestCookies
public function __invoke(ContainerInterface $container): InjectRequestCookies
{
return new InjectRequestCookies($container->get(ApiClient::class));
}
Expand Down
Loading

0 comments on commit 39b09ca

Please sign in to comment.