From 476d1b81aa099be0530a427df5ec905f5a9e93f2 Mon Sep 17 00:00:00 2001 From: Kevin Smith Date: Sun, 23 May 2021 00:01:02 -0500 Subject: [PATCH 1/5] Check coding standards against oldest supported version of PHP --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f31b7dd..d0a4c07 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,7 +13,7 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: '8.0' + php-version: '7.1' - name: Install Composer Dependencies uses: ramsey/composer-install@v1 - name: Run PHP-CS-Fixer From 350052adb40792f0a34e9061328db42a8ed7904f Mon Sep 17 00:00:00 2001 From: Kevin Smith Date: Sun, 23 May 2021 00:04:43 -0500 Subject: [PATCH 2/5] Remove inconsequential exclusion from coding standard --- phpcs.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/phpcs.xml b/phpcs.xml index 678876e..68a4bcf 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -21,6 +21,5 @@ - From 8a8997710fb70093e3bd1121fc1f1a768b92bbf2 Mon Sep 17 00:00:00 2001 From: Kevin Smith Date: Sun, 23 May 2021 00:06:04 -0500 Subject: [PATCH 3/5] Add missing return type hints and remove coding standard exclusion --- phpcs.xml | 1 - tests/RelayBuilderTest.php | 10 +++++----- tests/RelayTest.php | 18 +++++++++--------- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/phpcs.xml b/phpcs.xml index 68a4bcf..c6f471c 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -19,7 +19,6 @@ - diff --git a/tests/RelayBuilderTest.php b/tests/RelayBuilderTest.php index 2e4d27a..47e0f84 100644 --- a/tests/RelayBuilderTest.php +++ b/tests/RelayBuilderTest.php @@ -18,21 +18,21 @@ protected function setUp(): void $this->relayBuilder = new RelayBuilder(); } - public function testArray() + public function testArray(): void { $queue = [new FakeMiddleware()]; $relay = $this->relayBuilder->newInstance($queue); $this->assertInstanceOf('Relay\Relay', $relay); } - public function testArrayObject() + public function testArrayObject(): void { $queue = new ArrayObject([new FakeMiddleware()]); $relay = $this->relayBuilder->newInstance($queue); $this->assertInstanceOf('Relay\Relay', $relay); } - public function testTraversable() + public function testTraversable(): void { $queue = new class implements IteratorAggregate { public function getIterator(): Generator @@ -48,13 +48,13 @@ public function getIterator(): Generator /** * @psalm-suppress InvalidArgument */ - public function testInvalidArgument() + public function testInvalidArgument(): void { $this->expectException('TypeError'); $this->relayBuilder->newInstance('bad argument'); } - public function testEmptyQueue() + public function testEmptyQueue(): void { $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('$queue cannot be empty'); diff --git a/tests/RelayTest.php b/tests/RelayTest.php index 986c7c2..d4d591b 100644 --- a/tests/RelayTest.php +++ b/tests/RelayTest.php @@ -26,7 +26,7 @@ protected function setUp(): void }; } - protected function assertRelay(Relay $relay) + protected function assertRelay(Relay $relay): void { FakeMiddleware::$count = 0; @@ -41,7 +41,7 @@ protected function assertRelay(Relay $relay) $this->assertSame('<6<5<4', $actual); } - public function testArrayQueue() + public function testArrayQueue(): void { $queue = [ new FakeMiddleware(), @@ -53,7 +53,7 @@ public function testArrayQueue() $this->assertRelay(new Relay($queue)); } - public function testTraversableQueue() + public function testTraversableQueue(): void { $queue = new class implements IteratorAggregate { public function getIterator(): Generator @@ -73,13 +73,13 @@ public function getIterator(): Generator /** * @psalm-suppress InvalidArgument */ - public function testBadQueue() + public function testBadQueue(): void { $this->expectException(TypeError::class); new Relay('bad'); } - public function testEmptyQueue() + public function testEmptyQueue(): void { $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('$queue cannot be empty'); @@ -87,7 +87,7 @@ public function testEmptyQueue() new Relay([]); } - public function testQueueWithInvalidEntry() + public function testQueueWithInvalidEntry(): void { $this->expectException(RuntimeException::class); $this->expectExceptionMessage( @@ -98,7 +98,7 @@ public function testQueueWithInvalidEntry() $relay->handle(ServerRequestFactory::fromGlobals()); } - public function testResolverEntries() + public function testResolverEntries(): void { $queue = [ FakeMiddleware::class, @@ -112,7 +112,7 @@ public function testResolverEntries() $this->assertRelay(new Relay($queue, $resolver)); } - public function testRequestHandlerInQueue() + public function testRequestHandlerInQueue(): void { $queue = [ new FakeMiddleware(), @@ -124,7 +124,7 @@ public function testRequestHandlerInQueue() $this->assertRelay(new Relay([$requestHandler])); } - public function testCallableMiddleware() + public function testCallableMiddleware(): void { $queue = [ function ( From 69da37ca0f4c087f960f2cc4314188de45dc7ddb Mon Sep 17 00:00:00 2001 From: Kevin Smith Date: Sun, 23 May 2021 00:34:43 -0500 Subject: [PATCH 4/5] =?UTF-8?q?Use=20more=20focused=20exclusions=20for=20t?= =?UTF-8?q?he=20few=20missing=20parameter=20type=20hints=20that=20should?= =?UTF-8?q?=20be=20ignored=20in=20order=20to=20maintain=20the=20classes?= =?UTF-8?q?=E2=80=99=20public=20APIs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- phpcs.xml | 1 - src/RelayBuilder.php | 2 ++ src/RequestHandler.php | 2 ++ 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/phpcs.xml b/phpcs.xml index c6f471c..1d6575d 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -19,6 +19,5 @@ - diff --git a/src/RelayBuilder.php b/src/RelayBuilder.php index ba8fc0e..437c6c5 100644 --- a/src/RelayBuilder.php +++ b/src/RelayBuilder.php @@ -17,6 +17,8 @@ public function __construct(callable $resolver = null) /** * @param iterable $queue A queue of middleware entries. + * + * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint */ public function newInstance($queue): Relay { diff --git a/src/RequestHandler.php b/src/RequestHandler.php index c1535cc..996819f 100644 --- a/src/RequestHandler.php +++ b/src/RequestHandler.php @@ -25,6 +25,8 @@ abstract class RequestHandler implements RequestHandlerInterface /** * @param iterable $queue A queue of middleware entries. * @param callable $resolver Converts a given queue entry to a callable or MiddlewareInterface instance. + * + * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint */ public function __construct($queue, callable $resolver = null) { From c48fd0dd88591cd5deb2e09a2d8f6dbcd8385722 Mon Sep 17 00:00:00 2001 From: Kevin Smith Date: Sun, 23 May 2021 00:39:51 -0500 Subject: [PATCH 5/5] Update Doctrine Coding Standard to v9 --- composer.json | 2 +- src/RelayBuilder.php | 2 +- src/RequestHandler.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 9d3f070..96b2a9f 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ "psr/http-server-middleware": "^1.0" }, "require-dev": { - "doctrine/coding-standard": "^8.2", + "doctrine/coding-standard": "^9.0", "friendsofphp/php-cs-fixer": "^3.0", "laminas/laminas-diactoros": "~2.2", "phpstan/phpstan": "^0.12.14", diff --git a/src/RelayBuilder.php b/src/RelayBuilder.php index 437c6c5..7044854 100644 --- a/src/RelayBuilder.php +++ b/src/RelayBuilder.php @@ -10,7 +10,7 @@ class RelayBuilder /** * @param callable $resolver Converts a given queue entry to a callable or MiddlewareInterface instance. */ - public function __construct(callable $resolver = null) + public function __construct(?callable $resolver = null) { $this->resolver = $resolver; } diff --git a/src/RequestHandler.php b/src/RequestHandler.php index 996819f..2b2e520 100644 --- a/src/RequestHandler.php +++ b/src/RequestHandler.php @@ -28,7 +28,7 @@ abstract class RequestHandler implements RequestHandlerInterface * * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint */ - public function __construct($queue, callable $resolver = null) + public function __construct($queue, ?callable $resolver = null) { if (! is_iterable($queue)) { throw new TypeError('\$queue must be array or Traversable.');