From dfe53ab7acc5db20731a4d3c278f5a8c0de7db86 Mon Sep 17 00:00:00 2001 From: George Steel Date: Fri, 4 Nov 2022 16:21:51 +0000 Subject: [PATCH 1/2] Apply PHP 8.0 Syntax Also upgrade to doctrine coding standard 10 --- composer.json | 2 +- composer.lock | 52 ++++++++++--------- phpcs.xml | 5 +- psalm-baseline.xml | 20 ------- src/Container/ApiFactory.php | 4 +- src/Container/LinkResolverFactory.php | 2 +- src/Event/WebhookEvent.php | 20 ++----- src/Exception/RequestError.php | 9 ++-- src/Exception/RoutingError.php | 5 +- src/LinkResolver.php | 43 +++++---------- .../Container/DocumentResolverFactory.php | 2 +- .../Container/PreviewHandlerFactory.php | 2 +- .../Container/PrismicTemplateFactory.php | 2 +- .../Container/WebhookHandlerFactory.php | 4 +- src/Middleware/DocumentResolver.php | 6 +-- src/Middleware/ExpiredPreviewHandler.php | 6 +-- src/Middleware/InjectRequestCookies.php | 6 +-- src/Middleware/PreviewCacheHeaders.php | 6 +-- src/Middleware/PreviewHandler.php | 23 +++----- src/Middleware/PrismicTemplate.php | 15 ++---- src/Middleware/WebhookHandler.php | 15 ++---- src/ResultSet/Container/TypeMapFactory.php | 2 +- src/ResultSet/HydratingResultSet.php | 12 ++--- src/ResultSet/HydratingResultSetFactory.php | 26 ++++------ src/ResultSet/TypeMap.php | 14 ++--- .../Container/DocumentResolverFactory.php | 2 +- src/Router/Container/RouteMatcherFactory.php | 2 +- src/Router/DocumentResolver.php | 29 ++++------- src/Router/RouteMatcher.php | 29 ++++------- src/Router/RouteParams.php | 34 ++++-------- src/Router/ScoredRoute.php | 14 ++--- test/Integration/IntegrationTestCase.php | 2 +- test/Integration/RouteProviderTest.php | 4 +- .../Container/LinkResolverFactoryTest.php | 2 +- test/Unit/Event/WebhookEventTest.php | 4 +- .../Http/PrismicHttpClientFactoryTest.php | 3 +- test/Unit/Middleware/DocumentResolverTest.php | 20 +++---- .../Middleware/ExpiredPreviewHandlerTest.php | 12 ++--- .../Middleware/InjectRequestCookiesTest.php | 9 ++-- .../Middleware/PreviewCacheHeadersTest.php | 12 ++--- test/Unit/Middleware/PreviewHandlerTest.php | 18 +++---- test/Unit/Middleware/PrismicTemplateTest.php | 22 ++++---- test/Unit/Middleware/WebhookHandlerTest.php | 9 ++-- .../Container/RouteParamsFactoryTest.php | 7 +-- test/Unit/Router/DocumentResolverTest.php | 31 +++++------ test/Unit/Router/RouteMatcherTest.php | 15 ++---- test/Unit/Router/RouteParamsTest.php | 4 +- 47 files changed, 208 insertions(+), 379 deletions(-) diff --git a/composer.json b/composer.json index 483f292..ee15f93 100644 --- a/composer.json +++ b/composer.json @@ -52,7 +52,7 @@ "psr/http-server-middleware": "^1.0.1" }, "require-dev": { - "doctrine/coding-standard": "^9.0.2", + "doctrine/coding-standard": "^10.0.0", "helmich/phpunit-psr7-assert": "^4.3", "laminas/laminas-config-aggregator": "^1.11", "laminas/laminas-servicemanager": "^3.19.0", diff --git a/composer.lock b/composer.lock index c39bd9e..ee21b56 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "7eb15ddcd81350391667603a90cdf174", + "content-hash": "10b12f46b1ba71d5fbeb53e8af8ece60", "packages": [ { "name": "clue/stream-filter", @@ -2672,23 +2672,23 @@ }, { "name": "doctrine/coding-standard", - "version": "9.0.2", + "version": "10.0.0", "source": { "type": "git", "url": "https://github.com/doctrine/coding-standard.git", - "reference": "35a2452c6025cb739c3244b3348bcd1604df07d1" + "reference": "7903671d7d33c231c8921058b7c14b8f57cbacb7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/coding-standard/zipball/35a2452c6025cb739c3244b3348bcd1604df07d1", - "reference": "35a2452c6025cb739c3244b3348bcd1604df07d1", + "url": "https://api.github.com/repos/doctrine/coding-standard/zipball/7903671d7d33c231c8921058b7c14b8f57cbacb7", + "reference": "7903671d7d33c231c8921058b7c14b8f57cbacb7", "shasum": "" }, "require": { "dealerdirect/phpcodesniffer-composer-installer": "^0.6.2 || ^0.7", - "php": "^7.1 || ^8.0", - "slevomat/coding-standard": "^7.0.0", - "squizlabs/php_codesniffer": "^3.6.0" + "php": "^7.2 || ^8.0", + "slevomat/coding-standard": "^8.2", + "squizlabs/php_codesniffer": "^3.7" }, "type": "phpcodesniffer-standard", "notification-url": "https://packagist.org/downloads/", @@ -2721,9 +2721,9 @@ ], "support": { "issues": "https://github.com/doctrine/coding-standard/issues", - "source": "https://github.com/doctrine/coding-standard/tree/9.0.2" + "source": "https://github.com/doctrine/coding-standard/tree/10.0.0" }, - "time": "2021-04-12T15:11:14+00:00" + "time": "2022-08-26T10:53:05+00:00" }, { "name": "doctrine/instantiator", @@ -6147,37 +6147,37 @@ }, { "name": "slevomat/coding-standard", - "version": "7.2.1", + "version": "8.6.2", "source": { "type": "git", "url": "https://github.com/slevomat/coding-standard.git", - "reference": "aff06ae7a84e4534bf6f821dc982a93a5d477c90" + "reference": "080f592b16f021a3a8e43d95ca8f57b87ddcf4e6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/slevomat/coding-standard/zipball/aff06ae7a84e4534bf6f821dc982a93a5d477c90", - "reference": "aff06ae7a84e4534bf6f821dc982a93a5d477c90", + "url": "https://api.github.com/repos/slevomat/coding-standard/zipball/080f592b16f021a3a8e43d95ca8f57b87ddcf4e6", + "reference": "080f592b16f021a3a8e43d95ca8f57b87ddcf4e6", "shasum": "" }, "require": { "dealerdirect/phpcodesniffer-composer-installer": "^0.6.2 || ^0.7", "php": "^7.2 || ^8.0", - "phpstan/phpdoc-parser": "^1.5.1", - "squizlabs/php_codesniffer": "^3.6.2" + "phpstan/phpdoc-parser": ">=1.11.0 <1.14.0", + "squizlabs/php_codesniffer": "^3.7.1" }, "require-dev": { - "phing/phing": "2.17.3", + "phing/phing": "2.17.4", "php-parallel-lint/php-parallel-lint": "1.3.2", - "phpstan/phpstan": "1.4.10|1.7.1", + "phpstan/phpstan": "1.4.10|1.8.10", "phpstan/phpstan-deprecation-rules": "1.0.0", "phpstan/phpstan-phpunit": "1.0.0|1.1.1", - "phpstan/phpstan-strict-rules": "1.2.3", - "phpunit/phpunit": "7.5.20|8.5.21|9.5.20" + "phpstan/phpstan-strict-rules": "1.4.4", + "phpunit/phpunit": "7.5.20|8.5.21|9.5.25" }, "type": "phpcodesniffer-standard", "extra": { "branch-alias": { - "dev-master": "7.x-dev" + "dev-master": "8.x-dev" } }, "autoload": { @@ -6190,9 +6190,13 @@ "MIT" ], "description": "Slevomat Coding Standard for PHP_CodeSniffer complements Consistence Coding Standard by providing sniffs with additional checks.", + "keywords": [ + "dev", + "phpcs" + ], "support": { "issues": "https://github.com/slevomat/coding-standard/issues", - "source": "https://github.com/slevomat/coding-standard/tree/7.2.1" + "source": "https://github.com/slevomat/coding-standard/tree/8.6.2" }, "funding": [ { @@ -6204,7 +6208,7 @@ "type": "tidelift" } ], - "time": "2022-05-25T10:58:12+00:00" + "time": "2022-10-22T15:42:49+00:00" }, { "name": "softcreatr/jsonpath", @@ -7197,7 +7201,7 @@ "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": "~8.0 || ~8.1 || ~8.2", + "php": "~8.0 || ~8.1", "ext-json": "*" }, "platform-dev": [], diff --git a/phpcs.xml b/phpcs.xml index ebb421e..9c39e40 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -14,10 +14,7 @@ test - - - - + 0 diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 3a26039..8a180ab 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -11,9 +11,6 @@ new static($message, $code) - - - $options['defaults'][$this->routeParams->reuseResultParams()] @@ -114,9 +111,6 @@ $documentData - - $data - @@ -304,23 +298,9 @@ - - method - method - method - willReturn - willReturn - with - with - $this->handler->lastRequest - - expects - expects - expects - diff --git a/src/Container/ApiFactory.php b/src/Container/ApiFactory.php index 09c33a4..4512ecc 100644 --- a/src/Container/ApiFactory.php +++ b/src/Container/ApiFactory.php @@ -29,7 +29,7 @@ public function __invoke(ContainerInterface $container): Api if (empty($apiUrl) || ! is_string($apiUrl)) { throw new ConfigurationError( 'An api url cannot be determined. Your content repository url should be available in ' . - 'configuration under [prismic][api] and should be a non-empty string.' + 'configuration under [prismic][api] and should be a non-empty string.', ); } @@ -43,7 +43,7 @@ public function __invoke(ContainerInterface $container): Api $container->has(RequestFactoryInterface::class) ? $container->get(RequestFactoryInterface::class) : null, $container->has(UriFactoryInterface::class) ? $container->get(UriFactoryInterface::class) : null, $container->has(ResultSetFactory::class) ? $container->get(ResultSetFactory::class) : null, - $container->has(PrismicApiCache::class) ? $container->get(PrismicApiCache::class) : null + $container->has(PrismicApiCache::class) ? $container->get(PrismicApiCache::class) : null, ); } } diff --git a/src/Container/LinkResolverFactory.php b/src/Container/LinkResolverFactory.php index 280a5be..2848ef5 100644 --- a/src/Container/LinkResolverFactory.php +++ b/src/Container/LinkResolverFactory.php @@ -20,7 +20,7 @@ public function __invoke(ContainerInterface $container): LinkResolver $container->get(RouteParams::class), $container->get(RouteMatcher::class), $container->get(UrlHelper::class), - $container->get(ApiClient::class)->data()->bookmarks() + $container->get(ApiClient::class)->data()->bookmarks(), ); } } diff --git a/src/Event/WebhookEvent.php b/src/Event/WebhookEvent.php index 0e95cc3..b4587af 100644 --- a/src/Event/WebhookEvent.php +++ b/src/Event/WebhookEvent.php @@ -14,14 +14,10 @@ final class WebhookEvent implements Serializable { - /** @var int */ - private $received; - /** @var object */ - private $payload; + private int $received; - private function __construct(object $payload) + private function __construct(private object $payload) { - $this->payload = $payload; $this->received = time(); } @@ -45,9 +41,7 @@ public function payload(): object return $this->payload; } - /** - * @deprecated - */ + /** @deprecated */ public function serialize(): string { return Json::encode([ @@ -70,9 +64,7 @@ public function unserialize($serialized): void $this->received = $object->received; } - /** - * @return array{received: int, payload: string} - */ + /** @return array{received: int, payload: string} */ public function __serialize(): array { return [ @@ -81,9 +73,7 @@ public function __serialize(): array ]; } - /** - * @param array{received: int, payload: string} $data - */ + /** @param array{received: int, payload: string} $data */ public function __unserialize(array $data): void { $this->received = $data['received']; diff --git a/src/Exception/RequestError.php b/src/Exception/RequestError.php index 3f4f7d9..372644a 100644 --- a/src/Exception/RequestError.php +++ b/src/Exception/RequestError.php @@ -11,8 +11,7 @@ class RequestError extends RuntimeException implements PrimoError { - /** @var RequestInterface|null */ - private $request; + private RequestInterface|null $request = null; public static function withRequest(RequestInterface $request, string $message, int $code): self { @@ -27,7 +26,7 @@ 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 ' . 'either not yet occurred or a route could not be matched.', - (string) $request->getUri() + (string) $request->getUri(), ); return self::withRequest($request, $message, 500); @@ -39,13 +38,13 @@ public static function withMissingTemplateAttribute(RequestInterface $request, s 'The request for "%s" failed because there was no template attribute found in the request. I was ' . 'expecting to find a template attribute named "%s"', (string) $request->getUri(), - $expectedTemplateAttribute + $expectedTemplateAttribute, ); return self::withRequest($request, $message, 500); } - public function getRequest(): ?RequestInterface + public function getRequest(): RequestInterface|null { return $this->request; } diff --git a/src/Exception/RoutingError.php b/src/Exception/RoutingError.php index b463610..52b31c5 100644 --- a/src/Exception/RoutingError.php +++ b/src/Exception/RoutingError.php @@ -13,6 +13,7 @@ use const JSON_THROW_ON_ERROR; +/** @final */ class RoutingError extends RuntimeError { public static function uidMatchedWithoutType(RouteResult $routeResult): self @@ -21,7 +22,7 @@ public static function uidMatchedWithoutType(RouteResult $routeResult): self 'The route named "%s" matches a Prismic UID, but the type cannot be resolved. You cannot resolve documents ' . 'by UID when the type is not known. Matched parameters: %s', self::routeName($routeResult), - self::matchedParams($routeResult) + self::matchedParams($routeResult), ), 400); } @@ -31,7 +32,7 @@ public static function nonUniqueResult(RouteResult $routeResult, ResultSet $resu 'The route named "%s" matched %d documents when transformed into a query. Route parameters were: %s', self::routeName($routeResult), count($resultSet), - self::matchedParams($routeResult) + self::matchedParams($routeResult), ), 400); } diff --git a/src/LinkResolver.php b/src/LinkResolver.php index b76c924..dace349 100644 --- a/src/LinkResolver.php +++ b/src/LinkResolver.php @@ -14,38 +14,23 @@ use Prismic\UrlLink; use Prismic\Value\Bookmark; -/** - * @psalm-suppress DeprecatedClass, DeprecatedMethod, DeprecatedProperty - */ +/** @psalm-suppress DeprecatedClass, DeprecatedMethod, DeprecatedProperty */ final class LinkResolver implements PrismicLinkResolver { - /** @var RouteParams */ - private $routeParams; - /** - * @deprecated - * - * @var Bookmark[] - */ - private $bookmarks; - /** @var RouteMatcher */ - private $routeMatcher; - /** @var UrlHelper */ - private $urlHelper; - /** * @deprecated $bookmarks * * @param Bookmark[] $bookmarks */ - public function __construct(RouteParams $routeParams, RouteMatcher $matcher, UrlHelper $urlHelper, iterable $bookmarks) - { - $this->routeParams = $routeParams; - $this->bookmarks = $bookmarks; - $this->routeMatcher = $matcher; - $this->urlHelper = $urlHelper; + public function __construct( + private RouteParams $routeParams, + private RouteMatcher $routeMatcher, + private UrlHelper $urlHelper, + private iterable $bookmarks, + ) { } - public function resolve(Link $link): ?string + public function resolve(Link $link): string|null { if ($link instanceof UrlLink) { return $link->url(); @@ -58,7 +43,7 @@ public function resolve(Link $link): ?string return null; } - private function resolveDocumentLink(DocumentLink $link): ?string + private function resolveDocumentLink(DocumentLink $link): string|null { if ($link->isBroken()) { return null; @@ -69,7 +54,7 @@ private function resolveDocumentLink(DocumentLink $link): ?string $link->type(), $link->uid(), $this->bookmarkNameByDocumentId($link->id()), - $link->tags() + $link->tags(), ); if ($route) { return $this->url($link, $route); @@ -94,10 +79,8 @@ private function routeParams(DocumentLink $link): array ]; } - /** - * @deprecated - */ - private function bookmarkNameByDocumentId(string $id): ?string + /** @deprecated */ + private function bookmarkNameByDocumentId(string $id): string|null { foreach ($this->bookmarks as $bookmark) { if ($bookmark->documentId() === $id) { @@ -118,7 +101,7 @@ private function url(DocumentLink $link, Route $route): string $this->routeParams($link), [], null, - ['reuse_result_params' => $reuseResultParams] + ['reuse_result_params' => $reuseResultParams], ); } } diff --git a/src/Middleware/Container/DocumentResolverFactory.php b/src/Middleware/Container/DocumentResolverFactory.php index 8278c48..8fb8fae 100644 --- a/src/Middleware/Container/DocumentResolverFactory.php +++ b/src/Middleware/Container/DocumentResolverFactory.php @@ -13,7 +13,7 @@ final class DocumentResolverFactory public function __invoke(ContainerInterface $container): DocumentResolver { return new DocumentResolver( - $container->get(Resolver::class) + $container->get(Resolver::class), ); } } diff --git a/src/Middleware/Container/PreviewHandlerFactory.php b/src/Middleware/Container/PreviewHandlerFactory.php index de593c1..8c64de7 100644 --- a/src/Middleware/Container/PreviewHandlerFactory.php +++ b/src/Middleware/Container/PreviewHandlerFactory.php @@ -19,7 +19,7 @@ public function __invoke(ContainerInterface $container): PreviewHandler return new PreviewHandler( $container->get(ApiClient::class), $container->get(LinkResolver::class), - $defaultUrl + $defaultUrl, ); } } diff --git a/src/Middleware/Container/PrismicTemplateFactory.php b/src/Middleware/Container/PrismicTemplateFactory.php index 524b99f..6893450 100644 --- a/src/Middleware/Container/PrismicTemplateFactory.php +++ b/src/Middleware/Container/PrismicTemplateFactory.php @@ -18,7 +18,7 @@ public function __invoke(ContainerInterface $container): PrismicTemplate return new PrismicTemplate( $container->get(TemplateRendererInterface::class), - $templateAttribute + $templateAttribute, ); } } diff --git a/src/Middleware/Container/WebhookHandlerFactory.php b/src/Middleware/Container/WebhookHandlerFactory.php index 9c7b39f..3d7caf2 100644 --- a/src/Middleware/Container/WebhookHandlerFactory.php +++ b/src/Middleware/Container/WebhookHandlerFactory.php @@ -19,7 +19,7 @@ public function __invoke(ContainerInterface $container): WebhookHandler return new WebhookHandler( $this->assertEventDispatcher($container), - $config['primo']['webhook']['secret'] ?? null + $config['primo']['webhook']['secret'] ?? null, ); } @@ -34,7 +34,7 @@ private function assertEventDispatcher(ContainerInterface $container): EventDisp 'the id "%s". If you already have an event dispatcher that implements PSR-14, alias it to the interface in ' . 'the container, or install an event dispatcher from ' . 'https://packagist.org/providers/psr/event-dispatcher-implementation', - EventDispatcherInterface::class + EventDispatcherInterface::class, )); } } diff --git a/src/Middleware/DocumentResolver.php b/src/Middleware/DocumentResolver.php index 953acea..1e583bc 100644 --- a/src/Middleware/DocumentResolver.php +++ b/src/Middleware/DocumentResolver.php @@ -15,12 +15,8 @@ final class DocumentResolver implements MiddlewareInterface { - /** @var Resolver */ - private $resolver; - - public function __construct(Resolver $resolver) + public function __construct(private Resolver $resolver) { - $this->resolver = $resolver; } public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface diff --git a/src/Middleware/ExpiredPreviewHandler.php b/src/Middleware/ExpiredPreviewHandler.php index 70717c2..e696457 100644 --- a/src/Middleware/ExpiredPreviewHandler.php +++ b/src/Middleware/ExpiredPreviewHandler.php @@ -15,12 +15,8 @@ final class ExpiredPreviewHandler implements MiddlewareInterface { - /** @var string */ - private $redirectUrl; - - public function __construct(string $redirectUrl = '/') + public function __construct(private string $redirectUrl = '/') { - $this->redirectUrl = $redirectUrl; } public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface diff --git a/src/Middleware/InjectRequestCookies.php b/src/Middleware/InjectRequestCookies.php index d462eb7..7a032ff 100644 --- a/src/Middleware/InjectRequestCookies.php +++ b/src/Middleware/InjectRequestCookies.php @@ -12,12 +12,8 @@ final class InjectRequestCookies implements MiddlewareInterface { - /** @var ApiClient */ - private $api; - - public function __construct(ApiClient $api) + public function __construct(private ApiClient $api) { - $this->api = $api; } public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface diff --git a/src/Middleware/PreviewCacheHeaders.php b/src/Middleware/PreviewCacheHeaders.php index a0b2bd0..d981535 100644 --- a/src/Middleware/PreviewCacheHeaders.php +++ b/src/Middleware/PreviewCacheHeaders.php @@ -12,12 +12,8 @@ final class PreviewCacheHeaders implements MiddlewareInterface { - /** @var ApiClient */ - private $apiClient; - - public function __construct(ApiClient $apiClient) + public function __construct(private ApiClient $apiClient) { - $this->apiClient = $apiClient; } public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface diff --git a/src/Middleware/PreviewHandler.php b/src/Middleware/PreviewHandler.php index a5d4271..7d80853 100644 --- a/src/Middleware/PreviewHandler.php +++ b/src/Middleware/PreviewHandler.php @@ -18,20 +18,11 @@ final class PreviewHandler implements MiddlewareInterface { - /** @var ApiClient */ - private $api; - - /** @var LinkResolver */ - private $linkResolver; - - /** @var string */ - private $defaultUrl; - - public function __construct(ApiClient $api, LinkResolver $linkResolver, string $defaultUrl = '/') - { - $this->api = $api; - $this->linkResolver = $linkResolver; - $this->defaultUrl = $defaultUrl; + public function __construct( + private ApiClient $api, + private LinkResolver $linkResolver, + private string $defaultUrl = '/', + ) { } public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface @@ -46,11 +37,11 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface try { $link = $this->api->previewSession($token); - } catch (InvalidPreviewToken $error) { + } catch (InvalidPreviewToken) { return $handler->handle($request); } catch (PreviewTokenExpired $expired) { return $handler->handle( - $request->withAttribute(PreviewTokenExpired::class, $expired) + $request->withAttribute(PreviewTokenExpired::class, $expired), ); } diff --git a/src/Middleware/PrismicTemplate.php b/src/Middleware/PrismicTemplate.php index 57bb0d3..1742023 100644 --- a/src/Middleware/PrismicTemplate.php +++ b/src/Middleware/PrismicTemplate.php @@ -17,15 +17,10 @@ final class PrismicTemplate implements MiddlewareInterface { public const DEFAULT_TEMPLATE_ATTRIBUTE = 'template'; - /** @var TemplateRendererInterface */ - private $renderer; - /** @var string */ - private $templateAttribute; - - public function __construct(TemplateRendererInterface $renderer, string $templateAttribute = self::DEFAULT_TEMPLATE_ATTRIBUTE) - { - $this->renderer = $renderer; - $this->templateAttribute = $templateAttribute; + public function __construct( + private TemplateRendererInterface $renderer, + private string $templateAttribute = self::DEFAULT_TEMPLATE_ATTRIBUTE, + ) { } public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface @@ -43,7 +38,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface $this->renderer->addDefaultParam( TemplateRendererInterface::TEMPLATE_ALL, 'document', - $document + $document, ); return new HtmlResponse($this->renderer->render($template), 200, [ diff --git a/src/Middleware/WebhookHandler.php b/src/Middleware/WebhookHandler.php index 8703043..df44080 100644 --- a/src/Middleware/WebhookHandler.php +++ b/src/Middleware/WebhookHandler.php @@ -15,15 +15,10 @@ final class WebhookHandler implements RequestHandlerInterface { - /** @var EventDispatcherInterface */ - private $eventDispatcher; - /** @var string|null */ - private $expectedSecret; - - public function __construct(EventDispatcherInterface $eventDispatcher, ?string $expectedSecret = null) - { - $this->eventDispatcher = $eventDispatcher; - $this->expectedSecret = $expectedSecret; + public function __construct( + private EventDispatcherInterface $eventDispatcher, + private string|null $expectedSecret = null, + ) { } public function handle(ServerRequestInterface $request): ResponseInterface @@ -36,7 +31,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface try { $payload = Json::decodeObject($body); - } catch (JsonError $error) { + } catch (JsonError) { return $this->jsonError('Invalid payload', 400); } diff --git a/src/ResultSet/Container/TypeMapFactory.php b/src/ResultSet/Container/TypeMapFactory.php index 1c5b2ea..bee91ac 100644 --- a/src/ResultSet/Container/TypeMapFactory.php +++ b/src/ResultSet/Container/TypeMapFactory.php @@ -17,7 +17,7 @@ public function __invoke(ContainerInterface $container): TypeMap return new TypeMap( $options['map'] ?? [], - $options['default'] ?? Document::class + $options['default'] ?? Document::class, ); } } diff --git a/src/ResultSet/HydratingResultSet.php b/src/ResultSet/HydratingResultSet.php index 4abfb94..ab31abf 100644 --- a/src/ResultSet/HydratingResultSet.php +++ b/src/ResultSet/HydratingResultSet.php @@ -12,9 +12,7 @@ use function count; use function max; -/** - * @template-implements ResultSet - */ +/** @template-implements ResultSet */ final class HydratingResultSet implements ResultSet { /** @use TypicalResultSetBehaviour */ @@ -26,9 +24,9 @@ public function __construct( int $resultsPerPage, int $totalResults, int $pageCount, - ?string $nextPage, - ?string $previousPage, - array $results + string|null $nextPage, + string|null $previousPage, + array $results, ) { $this->page = $page; $this->perPage = $resultsPerPage; @@ -55,7 +53,7 @@ public function merge(ResultSet $with): ResultSet max($this->pageCount - 1, 1), $with->nextPage(), $this->prevPage, - $results + $results, ); } } diff --git a/src/ResultSet/HydratingResultSetFactory.php b/src/ResultSet/HydratingResultSetFactory.php index 387dc0b..2429ca8 100644 --- a/src/ResultSet/HydratingResultSetFactory.php +++ b/src/ResultSet/HydratingResultSetFactory.php @@ -15,38 +15,34 @@ final class HydratingResultSetFactory implements ResultSetFactory { use DataAssertionBehaviour; - /** @var TypeMap */ - private $map; - - public function __construct(TypeMap $map) + public function __construct(private TypeMap $map) { - $this->map = $map; } public function withHttpResponse(ResponseInterface $response): ResultSet { return $this->withJsonObject( - Json::decodeObject((string) $response->getBody()) + Json::decodeObject((string) $response->getBody()), ); } - public function withJsonObject(object $data): ResultSet + public function withJsonObject(object $object): ResultSet { $results = []; - foreach ($data->results as $documentData) { + foreach ($object->results as $documentData) { $content = DocumentData::factory($documentData); $class = $this->map->className($content->type()); $results[] = new $class($content); } return new HydratingResultSet( - self::assertObjectPropertyIsInteger($data, 'page'), - self::assertObjectPropertyIsInteger($data, 'results_per_page'), - self::assertObjectPropertyIsInteger($data, 'total_results_size'), - self::assertObjectPropertyIsInteger($data, 'total_pages'), - self::optionalStringProperty($data, 'next_page'), - self::optionalStringProperty($data, 'prev_page'), - $results + self::assertObjectPropertyIsInteger($object, 'page'), + self::assertObjectPropertyIsInteger($object, 'results_per_page'), + self::assertObjectPropertyIsInteger($object, 'total_results_size'), + self::assertObjectPropertyIsInteger($object, 'total_pages'), + self::optionalStringProperty($object, 'next_page'), + self::optionalStringProperty($object, 'prev_page'), + $results, ); } } diff --git a/src/ResultSet/TypeMap.php b/src/ResultSet/TypeMap.php index 0c0a24c..fdb0c4b 100644 --- a/src/ResultSet/TypeMap.php +++ b/src/ResultSet/TypeMap.php @@ -15,10 +15,7 @@ final class TypeMap { /** @var string[] */ - private $map; - - /** @var string */ - private $default; + private array $map; /** * Map Prismic Types to Classes @@ -28,11 +25,10 @@ final class TypeMap * * @param string[] $map */ - public function __construct(iterable $map, string $defaultDocumentType = Document::class) + public function __construct(iterable $map, private string $defaultDocumentType = Document::class) { $this->map = []; $this->classHierarchyCheck($defaultDocumentType); - $this->default = $defaultDocumentType; foreach ($map as $class => $type) { $target = is_array($type) ? $type : [$type]; @@ -42,7 +38,7 @@ public function __construct(iterable $map, string $defaultDocumentType = Documen public function className(string $type): string { - return $this->map[$type] ?? $this->default; + return $this->map[$type] ?? $this->defaultDocumentType; } /** @param string[] $types */ @@ -64,7 +60,7 @@ private function classHierarchyCheck(string $className): void if (! class_exists($className)) { throw new InvalidArgument(sprintf( 'The target class "%s" does not exist. Please create it or check your document type mapping configuration.', - $className + $className, )); } @@ -73,7 +69,7 @@ private function classHierarchyCheck(string $className): void 'All target classes to hydrate to must descend from %s because I can guarantee the constructor accepts ' . 'a DocumentData value object. If you want to opt out of this hierarchy, you need to make your own hydrating ' . 'result set', - Document::class + Document::class, )); } } diff --git a/src/Router/Container/DocumentResolverFactory.php b/src/Router/Container/DocumentResolverFactory.php index 7eaf28a..3b05966 100644 --- a/src/Router/Container/DocumentResolverFactory.php +++ b/src/Router/Container/DocumentResolverFactory.php @@ -15,7 +15,7 @@ public function __invoke(ContainerInterface $container): DocumentResolver { return new DocumentResolver( $container->get(ApiClient::class), - $container->get(RouteParams::class) + $container->get(RouteParams::class), ); } } diff --git a/src/Router/Container/RouteMatcherFactory.php b/src/Router/Container/RouteMatcherFactory.php index e8f7b98..ac76ab8 100644 --- a/src/Router/Container/RouteMatcherFactory.php +++ b/src/Router/Container/RouteMatcherFactory.php @@ -15,7 +15,7 @@ public function __invoke(ContainerInterface $container): RouteMatcher { return new RouteMatcher( $container->get(RouteParams::class), - $container->get(RouteCollector::class) + $container->get(RouteCollector::class), ); } } diff --git a/src/Router/DocumentResolver.php b/src/Router/DocumentResolver.php index 6ec0d10..269e781 100644 --- a/src/Router/DocumentResolver.php +++ b/src/Router/DocumentResolver.php @@ -15,27 +15,20 @@ use function is_string; use function sprintf; -/** - * @psalm-suppress DeprecatedMethod - */ +/** @psalm-suppress DeprecatedMethod */ class DocumentResolver { - /** @var RouteParams */ - private $routeParams; - /** @var ApiClient */ - private $api; - - public function __construct(ApiClient $api, RouteParams $routeParams) - { - $this->api = $api; - $this->routeParams = $routeParams; + public function __construct( + private ApiClient $api, + private RouteParams $routeParams, + ) { } /** * @throws RoutingError if the uid is required by the route, but no document type is defined. * @throws RoutingError if the matched route will yield more than one document. */ - public function resolve(RouteResult $routeResult): ?Document + public function resolve(RouteResult $routeResult): Document|null { $document = $this->resolveWithBookmark($routeResult); @@ -50,10 +43,8 @@ public function resolve(RouteResult $routeResult): ?Document return $document; } - /** - * @deprecated - */ - private function resolveWithBookmark(RouteResult $routeResult): ?Document + /** @deprecated */ + private function resolveWithBookmark(RouteResult $routeResult): Document|null { $params = $routeResult->getMatchedParams(); $bookmark = $params[$this->routeParams->bookmark()] ?? null; @@ -65,7 +56,7 @@ private function resolveWithBookmark(RouteResult $routeResult): ?Document } /** @throws RoutingError */ - private function resolveWithParams(RouteResult $routeResult): ?Document + private function resolveWithParams(RouteResult $routeResult): Document|null { $params = $routeResult->getMatchedParams(); $type = $params[$this->routeParams->type()] ?? null; @@ -120,7 +111,7 @@ private function resolveWithParams(RouteResult $routeResult): ?Document return $resultSet->first(); } - private function resolveWithId(RouteResult $routeResult): ?Document + private function resolveWithId(RouteResult $routeResult): Document|null { $params = $routeResult->getMatchedParams(); $id = $params[$this->routeParams->id()] ?? null; diff --git a/src/Router/RouteMatcher.php b/src/Router/RouteMatcher.php index 15ec846..660a53d 100644 --- a/src/Router/RouteMatcher.php +++ b/src/Router/RouteMatcher.php @@ -16,20 +16,13 @@ use function is_string; use function uasort; -/** - * @psalm-suppress DeprecatedMethod - */ +/** @psalm-suppress DeprecatedMethod */ final class RouteMatcher { - /** @var RouteParams */ - private $params; - /** @var RouteCollector */ - private $collector; - - public function __construct(RouteParams $params, RouteCollector $collector) - { - $this->params = $params; - $this->collector = $collector; + public function __construct( + private RouteParams $params, + private RouteCollector $collector, + ) { } /** @@ -37,7 +30,7 @@ public function __construct(RouteParams $params, RouteCollector $collector) * * @param string[] $tags */ - public function bestMatch(string $id, string $type, ?string $uid, ?string $bookmark, array $tags): ?Route + public function bestMatch(string $id, string $type, string|null $uid, string|null $bookmark, array $tags): Route|null { // A matching bookmark is nearly the most specific type of route and the easiest to reason about if ($bookmark) { @@ -85,7 +78,7 @@ public function bestMatch(string $id, string $type, ?string $uid, ?string $bookm } /** @deprecated */ - public function getBookmarkedRoute(string $bookmark): ?Route + public function getBookmarkedRoute(string $bookmark): Route|null { foreach ($this->routes() as $route) { $options = $route->getOptions(); @@ -129,7 +122,7 @@ public function routesMatchingTag(string $tag): iterable return $routes; } - public function getTypedRoute(string $type): ?Route + public function getTypedRoute(string $type): Route|null { foreach ($this->routes() as $route) { if ($this->matchesType($route, $type)) { @@ -140,7 +133,7 @@ public function getTypedRoute(string $type): ?Route return null; } - public function getUidRoute(string $type, string $uid): ?Route + public function getUidRoute(string $type, string $uid): Route|null { foreach ($this->routesMatchingType($type) as $route) { if ($this->matchesUid($route, $uid)) { @@ -182,7 +175,7 @@ private function wantsTag(Route $route): array if (! is_array($tags)) { throw new ConfigurationError( - 'Tags specified in routes must be either a string or an array of strings' + 'Tags specified in routes must be either a string or an array of strings', ); } @@ -197,7 +190,7 @@ private function matchesUid(Route $route, string $uid): bool return $option === $uid; } - private function routeMatchingId(string $id): ?Route + private function routeMatchingId(string $id): Route|null { foreach ($this->routes() as $route) { $options = $route->getOptions(); diff --git a/src/Router/RouteParams.php b/src/Router/RouteParams.php index 0020cc2..110bd57 100644 --- a/src/Router/RouteParams.php +++ b/src/Router/RouteParams.php @@ -10,31 +10,19 @@ use function in_array; use function sprintf; -/** - * @psalm-suppress DeprecatedProperty - */ +/** @psalm-suppress DeprecatedProperty */ final class RouteParams { - /** @var string */ - private $id = 'document-id'; - /** @var string */ - private $uid = 'document-uid'; - /** @var string */ - private $type = 'document-type'; - /** - * @deprecated - * - * @var string - */ - private $bookmark = 'document-bookmark'; - /** @var string */ - private $lang = 'document-lang'; - /** @var string */ - private $tag = 'document-tag'; - /** @var string */ - private $reuseResultParams = 'reuse_result_params'; + private string $id = 'document-id'; + private string $uid = 'document-uid'; + private string $type = 'document-type'; + /** @deprecated */ + private string $bookmark = 'document-bookmark'; + private string $lang = 'document-lang'; + private string $tag = 'document-tag'; + private string $reuseResultParams = 'reuse_result_params'; /** @var string[] */ - private static $acceptable = ['key', 'id', 'uid', 'type', 'bookmark', 'lang', 'tag', 'reuseResultParams']; + private static array $acceptable = ['key', 'id', 'uid', 'type', 'bookmark', 'lang', 'tag', 'reuseResultParams']; private function __construct() { @@ -57,7 +45,7 @@ private function setParameter(string $name, string $value): void throw new InvalidArgument(sprintf( '"%s" is not a valid option key. Valid options are: %s', $name, - implode(', ', self::$acceptable) + implode(', ', self::$acceptable), )); } diff --git a/src/Router/ScoredRoute.php b/src/Router/ScoredRoute.php index 6a0d9cb..274a14f 100644 --- a/src/Router/ScoredRoute.php +++ b/src/Router/ScoredRoute.php @@ -8,16 +8,10 @@ class ScoredRoute { - /** @var Route */ - private $route; - - /** @var int */ - private $score; - - public function __construct(Route $route, int $score) - { - $this->route = $route; - $this->score = $score; + public function __construct( + private Route $route, + private int $score, + ) { } public function route(): Route diff --git a/test/Integration/IntegrationTestCase.php b/test/Integration/IntegrationTestCase.php index 7bf66a7..b0e5059 100644 --- a/test/Integration/IntegrationTestCase.php +++ b/test/Integration/IntegrationTestCase.php @@ -42,7 +42,7 @@ protected function getApplicationConfig(): array * * @param array|null $withCustomConfiguration */ - protected function getContainer(?array $withCustomConfiguration = null): ContainerInterface + protected function getContainer(array|null $withCustomConfiguration = null): ContainerInterface { $config = $withCustomConfiguration ?: $this->getApplicationConfig(); assert(isset($config['dependencies'])); diff --git a/test/Integration/RouteProviderTest.php b/test/Integration/RouteProviderTest.php index 7204516..a9591a5 100644 --- a/test/Integration/RouteProviderTest.php +++ b/test/Integration/RouteProviderTest.php @@ -59,7 +59,7 @@ public static function assertRouteNameNotFound(string $routeName, Application $a self::assertNotContains($routeName, $names, sprintf( 'The route name "%s" should not be present in the configured routes but it was found', - $routeName + $routeName, )); } @@ -71,7 +71,7 @@ public static function assertRouteNameFound(string $routeName, Application $appl self::assertContains($routeName, $names, sprintf( 'The route name "%s" was not present in the configured routes', - $routeName + $routeName, )); } } diff --git a/test/Unit/Container/LinkResolverFactoryTest.php b/test/Unit/Container/LinkResolverFactoryTest.php index f4f5a07..39044db 100644 --- a/test/Unit/Container/LinkResolverFactoryTest.php +++ b/test/Unit/Container/LinkResolverFactoryTest.php @@ -21,7 +21,7 @@ private function routeMatcher(): RouteMatcher { return new RouteMatcher( RouteParams::fromArray([]), - $this->createMock(RouteCollector::class) + $this->createMock(RouteCollector::class), ); } diff --git a/test/Unit/Event/WebhookEventTest.php b/test/Unit/Event/WebhookEventTest.php index 5866a6b..6afe831 100644 --- a/test/Unit/Event/WebhookEventTest.php +++ b/test/Unit/Event/WebhookEventTest.php @@ -27,11 +27,11 @@ public function testThatEventsCanBeSerialised(): void self::assertEquals( $event->received(), - $copy->received() + $copy->received(), ); self::assertSame( $event->payload()->foo, - $copy->payload()->foo + $copy->payload()->foo, ); } } diff --git a/test/Unit/Http/PrismicHttpClientFactoryTest.php b/test/Unit/Http/PrismicHttpClientFactoryTest.php index 3602046..fa2c9dd 100644 --- a/test/Unit/Http/PrismicHttpClientFactoryTest.php +++ b/test/Unit/Http/PrismicHttpClientFactoryTest.php @@ -12,8 +12,7 @@ class PrismicHttpClientFactoryTest extends TestCase { - /** @var MockObject|ClientInterface */ - private $container; + private MockObject|ClientInterface $container; protected function setUp(): void { diff --git a/test/Unit/Middleware/DocumentResolverTest.php b/test/Unit/Middleware/DocumentResolverTest.php index 02cbf8a..7519c31 100644 --- a/test/Unit/Middleware/DocumentResolverTest.php +++ b/test/Unit/Middleware/DocumentResolverTest.php @@ -21,16 +21,11 @@ class DocumentResolverTest extends TestCase { - /** @var MockObject|Resolver */ - private $resolver; - /** @var RouteResult|MockObject */ - private $routeResult; - /** @var RequestHandlerInterface */ - private $handler; - /** @var ServerRequestInterface */ - private $request; - /** @var MockObject|Document */ - private $document; + private MockObject|Resolver $resolver; + private RouteResult|MockObject $routeResult; + private RequestHandlerInterface $handler; + private ServerRequestInterface $request; + private MockObject|Document $document; protected function setUp(): void { @@ -39,8 +34,7 @@ protected function setUp(): void $this->resolver = $this->createMock(Resolver::class); $this->routeResult = $this->createMock(RouteResult::class); $this->handler = new class () implements RequestHandlerInterface { - /** @var ServerRequestInterface */ - public $lastRequest; + public ServerRequestInterface $lastRequest; public function handle(ServerRequestInterface $request): ResponseInterface { @@ -66,7 +60,7 @@ public function testAnExceptionIsThrownWhenThereIsNoRouteResultAvailable(): void public function testThatGivenADocumentCanBeResolvedTheDocumentIsInjectedToRequestAttributes(): ResponseInterface { $this->resolver->method('resolve')->with($this->routeResult)->willReturn( - $this->document + $this->document, ); $request = $this->request->withAttribute(RouteResult::class, $this->routeResult); self::assertNull($request->getAttribute(Document::class)); diff --git a/test/Unit/Middleware/ExpiredPreviewHandlerTest.php b/test/Unit/Middleware/ExpiredPreviewHandlerTest.php index 444c620..50b24d7 100644 --- a/test/Unit/Middleware/ExpiredPreviewHandlerTest.php +++ b/test/Unit/Middleware/ExpiredPreviewHandlerTest.php @@ -16,20 +16,16 @@ class ExpiredPreviewHandlerTest extends TestCase { - /** @var ExpiredPreviewHandler */ - private $subject; - /** @var ServerRequestInterface */ - private $request; - /** @var RequestHandlerInterface */ - private $handler; + private ExpiredPreviewHandler $subject; + private ServerRequestInterface $request; + private RequestHandlerInterface $handler; protected function setUp(): void { parent::setUp(); $this->request = Psr17FactoryDiscovery::findServerRequestFactory()->createServerRequest('GET', '/foo'); $this->handler = new class () implements RequestHandlerInterface { - /** @var ServerRequestInterface */ - public $lastRequest; + public ServerRequestInterface $lastRequest; public function handle(ServerRequestInterface $request): ResponseInterface { diff --git a/test/Unit/Middleware/InjectRequestCookiesTest.php b/test/Unit/Middleware/InjectRequestCookiesTest.php index e24ae5a..6f1b7db 100644 --- a/test/Unit/Middleware/InjectRequestCookiesTest.php +++ b/test/Unit/Middleware/InjectRequestCookiesTest.php @@ -16,12 +16,9 @@ class InjectRequestCookiesTest extends TestCase { - /** @var Api */ - private $api; - /** @var InjectRequestCookies */ - private $subject; - /** @var RequestHandlerInterface */ - private $handler; + private Api $api; + private InjectRequestCookies $subject; + private RequestHandlerInterface $handler; protected function setUp(): void { diff --git a/test/Unit/Middleware/PreviewCacheHeadersTest.php b/test/Unit/Middleware/PreviewCacheHeadersTest.php index b63e407..d677337 100644 --- a/test/Unit/Middleware/PreviewCacheHeadersTest.php +++ b/test/Unit/Middleware/PreviewCacheHeadersTest.php @@ -16,14 +16,10 @@ class PreviewCacheHeadersTest extends TestCase { - /** @var ServerRequestInterface */ - private $request; - /** @var RequestHandlerInterface */ - private $handler; - /** @var MockObject|ApiClient */ - private $api; - /** @var PreviewCacheHeaders */ - private $subject; + private ServerRequestInterface $request; + private RequestHandlerInterface $handler; + private MockObject|ApiClient $api; + private PreviewCacheHeaders $subject; protected function setUp(): void { diff --git a/test/Unit/Middleware/PreviewHandlerTest.php b/test/Unit/Middleware/PreviewHandlerTest.php index afad9c5..de0c158 100644 --- a/test/Unit/Middleware/PreviewHandlerTest.php +++ b/test/Unit/Middleware/PreviewHandlerTest.php @@ -20,24 +20,18 @@ class PreviewHandlerTest extends TestCase { - /** @var ServerRequestInterface */ - private $request; - /** @var RequestHandlerInterface */ - private $handler; - /** @var MockObject|ApiClient */ - private $api; - /** @var MockObject|LinkResolver */ - private $linkResolver; - /** @var PreviewHandler */ - private $subject; + private ServerRequestInterface $request; + private RequestHandlerInterface $handler; + private MockObject|ApiClient $api; + private MockObject|LinkResolver $linkResolver; + private PreviewHandler $subject; protected function setUp(): void { parent::setUp(); $this->request = Psr17FactoryDiscovery::findServerRequestFactory()->createServerRequest('GET', '/foo'); $this->handler = new class () implements RequestHandlerInterface { - /** @var ServerRequestInterface */ - public $lastRequest; + public ServerRequestInterface $lastRequest; public function handle(ServerRequestInterface $request): ResponseInterface { diff --git a/test/Unit/Middleware/PrismicTemplateTest.php b/test/Unit/Middleware/PrismicTemplateTest.php index 3609009..3821029 100644 --- a/test/Unit/Middleware/PrismicTemplateTest.php +++ b/test/Unit/Middleware/PrismicTemplateTest.php @@ -18,16 +18,13 @@ class PrismicTemplateTest extends TestCase { - /** @var TemplateRendererInterface|MockObject */ - private $templates; - /** @var PrismicTemplate */ - private $subject; - /** @var ServerRequestInterface */ - private $request; - /** @var MockObject|Document */ - private $document; - /** @var RequestHandlerInterface */ - private $handler; + /** @var TemplateRendererInterface&MockObject */ + private TemplateRendererInterface|MockObject $templates; + private PrismicTemplate $subject; + private ServerRequestInterface $request; + /** @var Document&MockObject */ + private MockObject|Document $document; + private RequestHandlerInterface $handler; protected function setUp(): void { @@ -37,8 +34,7 @@ protected function setUp(): void $this->request = Psr17FactoryDiscovery::findServerRequestFactory()->createServerRequest('GET', '/foo'); $this->document = $this->createMock(Document::class); $this->handler = new class () implements RequestHandlerInterface { - /** @var ServerRequestInterface */ - public $lastRequest; + public ServerRequestInterface|null $lastRequest = null; public function handle(ServerRequestInterface $request): ResponseInterface { @@ -85,7 +81,7 @@ public function testThatTheTemplateWillBeRenderedWhenRequestCriteriaAreMet(): vo ->with( self::equalTo(TemplateRendererInterface::TEMPLATE_ALL), self::equalTo('document'), - self::equalTo($this->document) + self::equalTo($this->document), ); $this->templates->expects(self::once()) diff --git a/test/Unit/Middleware/WebhookHandlerTest.php b/test/Unit/Middleware/WebhookHandlerTest.php index fe6ba2b..3680a4d 100644 --- a/test/Unit/Middleware/WebhookHandlerTest.php +++ b/test/Unit/Middleware/WebhookHandlerTest.php @@ -13,12 +13,9 @@ class WebhookHandlerTest extends TestCase { - /** @var MockObject|EventDispatcherInterface */ - private $events; - /** @var ServerRequestInterface */ - private $request; - /** @var WebhookHandler */ - private $subject; + private MockObject|EventDispatcherInterface $events; + private ServerRequestInterface $request; + private WebhookHandler $subject; protected function setUp(): void { diff --git a/test/Unit/Router/Container/RouteParamsFactoryTest.php b/test/Unit/Router/Container/RouteParamsFactoryTest.php index 842a7e6..663ae27 100644 --- a/test/Unit/Router/Container/RouteParamsFactoryTest.php +++ b/test/Unit/Router/Container/RouteParamsFactoryTest.php @@ -9,13 +9,10 @@ use PrimoTest\Unit\TestCase; use Psr\Container\ContainerInterface; -/** - * @psalm-suppress DeprecatedMethod - */ +/** @psalm-suppress DeprecatedMethod */ class RouteParamsFactoryTest extends TestCase { - /** @var RouteParamsFactory */ - private $factory; + private RouteParamsFactory $factory; /** @var MockObject&ContainerInterface */ private $container; diff --git a/test/Unit/Router/DocumentResolverTest.php b/test/Unit/Router/DocumentResolverTest.php index 10a48cc..7f98e4f 100644 --- a/test/Unit/Router/DocumentResolverTest.php +++ b/test/Unit/Router/DocumentResolverTest.php @@ -22,19 +22,14 @@ use Psr\Http\Server\MiddlewareInterface; use Psr\Http\Server\RequestHandlerInterface; -/** - * @psalm-suppress DeprecatedMethod - */ +/** @psalm-suppress DeprecatedMethod */ class DocumentResolverTest extends TestCase { /** @var MockObject&ApiClient */ private $api; - /** @var DocumentResolver */ - private $resolver; - /** @var MiddlewareInterface */ - private $middleware; - /** @var RouteParams */ - private $params; + private DocumentResolver $resolver; + private MiddlewareInterface $middleware; + private RouteParams $params; protected function setUp(): void { @@ -66,7 +61,7 @@ public function testThatResultFromApiWillBeReturnedWhenBookmarkMatches(): void $result = RouteResult::fromRoute( new Route('/foo', $this->middleware, ['GET']), - [$this->params->bookmark() => 'bookmark-name'] + [$this->params->bookmark() => 'bookmark-name'], ); self::assertSame($document, $this->resolver->resolve($result)); @@ -82,7 +77,7 @@ public function testThatResultFromApiWillBeReturnedWhenRouteMatchesDocumentId(): $result = RouteResult::fromRoute( new Route('/foo', $this->middleware, ['GET']), - [$this->params->id() => 'doc-id'] + [$this->params->id() => 'doc-id'], ); self::assertSame($document, $this->resolver->resolve($result)); @@ -131,7 +126,7 @@ public function testThatResultFromApiIsReturnedWhenRouteMatchesTypeAndUid(): voi [ $this->params->uid() => 'uid', $this->params->type() => 'type', - ] + ], ); self::assertSame($document, $this->resolver->resolve($result)); @@ -147,7 +142,7 @@ public function testThatLanguageIsProvidedToApiMethodWhenFoundInTheRouteParams() $this->params->uid() => 'uid', $this->params->type() => 'type', $this->params->lang() => 'en-gb', - ] + ], ); self::assertSame($document, $this->resolver->resolve($result)); @@ -157,7 +152,7 @@ public function testThatTypeMustBeKnownInOrderToResolveByUid(): void { $result = RouteResult::fromRoute( new Route('/foo', $this->middleware, ['GET'], 'myRoute'), - [$this->params->uid() => 'uid'] + [$this->params->uid() => 'uid'], ); $this->expectException(RoutingError::class); @@ -171,7 +166,7 @@ public function testThatItIsPossibleToQueryOnASingleType(): void $result = RouteResult::fromRoute( new Route('/foo', $this->middleware, ['GET'], 'myRoute'), - [$this->params->type() => 'type'] + [$this->params->type() => 'type'], ); self::assertSame($document, $this->resolver->resolve($result)); @@ -183,7 +178,7 @@ public function testThatItIsPossibleToQueryByTag(): void $result = RouteResult::fromRoute( new Route('/foo', $this->middleware, ['GET'], 'myRoute'), - [$this->params->tag() => 'my-tag'] + [$this->params->tag() => 'my-tag'], ); self::assertSame($document, $this->resolver->resolve($result)); @@ -218,7 +213,7 @@ public function testAnExceptionIsThrownWhenAResultSetContainsMultipleResults(): $this->expectExceptionMessage('The route named "myRoute" matched 2 documents when transformed into a query'); $result = RouteResult::fromRoute( new Route('/foo', $this->middleware, ['GET'], 'myRoute'), - [$this->params->tag() => 'my-tag'] + [$this->params->tag() => 'my-tag'], ); $this->resolver->resolve($result); } @@ -274,7 +269,7 @@ public function testThatWhenTheTypeAndIdentifierArePresentInRoutingParametersThe [ $this->params->id() => 'my-id', $this->params->type() => 'type', - ] + ], ); self::assertSame($document, $this->resolver->resolve($result)); diff --git a/test/Unit/Router/RouteMatcherTest.php b/test/Unit/Router/RouteMatcherTest.php index 6925782..c740f0d 100644 --- a/test/Unit/Router/RouteMatcherTest.php +++ b/test/Unit/Router/RouteMatcherTest.php @@ -17,17 +17,12 @@ use Psr\Http\Server\MiddlewareInterface; use Psr\Http\Server\RequestHandlerInterface; -/** - * @psalm-suppress DeprecatedMethod - */ +/** @psalm-suppress DeprecatedMethod */ class RouteMatcherTest extends TestCase { - /** @var RouteParams */ - private $params; - /** @var RouteCollector */ - private $collector; - /** @var MiddlewareInterface */ - private $middleware; + private RouteParams $params; + private RouteCollector $collector; + private MiddlewareInterface $middleware; protected function setUp(): void { @@ -216,7 +211,7 @@ public function testBestMatch(): void $this->assertBastMatch('two-tags', $matcher->bestMatch('id', 'type', 'no-match', null, ['a', 'b'])); } - private function assertBastMatch(string $name, ?Route $match): void + private function assertBastMatch(string $name, Route|null $match): void { self::assertNotNull($match, 'A match was not found'); self::assertSame($name, $match->getName()); diff --git a/test/Unit/Router/RouteParamsTest.php b/test/Unit/Router/RouteParamsTest.php index 4798e6b..3b51812 100644 --- a/test/Unit/Router/RouteParamsTest.php +++ b/test/Unit/Router/RouteParamsTest.php @@ -9,9 +9,7 @@ use PrimoTest\Unit\TestCase; use TypeError; -/** - * @psalm-suppress DeprecatedMethod - */ +/** @psalm-suppress DeprecatedMethod */ class RouteParamsTest extends TestCase { public function testOptionsArray(): RouteParams From d411e838696c17a47589f1bd01c17b530856c342 Mon Sep 17 00:00:00 2001 From: George Steel Date: Fri, 4 Nov 2022 16:29:58 +0000 Subject: [PATCH 2/2] Lock refresh --- composer.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.lock b/composer.lock index ee21b56..312bf51 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "10b12f46b1ba71d5fbeb53e8af8ece60", + "content-hash": "cc319a0cf926e1f1ac66c1e2e2dfb35b", "packages": [ { "name": "clue/stream-filter", @@ -7201,7 +7201,7 @@ "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": "~8.0 || ~8.1", + "php": "~8.0 || ~8.1 || ~8.2", "ext-json": "*" }, "platform-dev": [],