Skip to content

Commit

Permalink
Merge pull request #57 from relayphp/tighten-up-coding-standard
Browse files Browse the repository at this point in the history
Tighten up Coding Standard
  • Loading branch information
kevinsmith authored May 23, 2021
2 parents 18cf372 + c48fd0d commit 924fdf9
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 0 additions & 3 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,5 @@
<exclude name="SlevomatCodingStandard.Functions.StaticClosure.ClosureNotStatic"/>
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingReturnTypeHint"/>
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint"/>
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingNativeTypeHint"/>
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint"/>
<exclude name="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint"/>
</rule>
</ruleset>
4 changes: 3 additions & 1 deletion src/RelayBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ 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;
}

/**
* @param iterable<mixed> $queue A queue of middleware entries.
*
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
*/
public function newInstance($queue): Relay
{
Expand Down
4 changes: 3 additions & 1 deletion src/RequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ abstract class RequestHandler implements RequestHandlerInterface
/**
* @param iterable<mixed> $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)
public function __construct($queue, ?callable $resolver = null)
{
if (! is_iterable($queue)) {
throw new TypeError('\$queue must be array or Traversable.');
Expand Down
10 changes: 5 additions & 5 deletions tests/RelayBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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');
Expand Down
18 changes: 9 additions & 9 deletions tests/RelayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ protected function setUp(): void
};
}

protected function assertRelay(Relay $relay)
protected function assertRelay(Relay $relay): void
{
FakeMiddleware::$count = 0;

Expand All @@ -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(),
Expand All @@ -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
Expand All @@ -73,21 +73,21 @@ 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');

new Relay([]);
}

public function testQueueWithInvalidEntry()
public function testQueueWithInvalidEntry(): void
{
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage(
Expand All @@ -98,7 +98,7 @@ public function testQueueWithInvalidEntry()
$relay->handle(ServerRequestFactory::fromGlobals());
}

public function testResolverEntries()
public function testResolverEntries(): void
{
$queue = [
FakeMiddleware::class,
Expand All @@ -112,7 +112,7 @@ public function testResolverEntries()
$this->assertRelay(new Relay($queue, $resolver));
}

public function testRequestHandlerInQueue()
public function testRequestHandlerInQueue(): void
{
$queue = [
new FakeMiddleware(),
Expand All @@ -124,7 +124,7 @@ public function testRequestHandlerInQueue()
$this->assertRelay(new Relay([$requestHandler]));
}

public function testCallableMiddleware()
public function testCallableMiddleware(): void
{
$queue = [
function (
Expand Down

0 comments on commit 924fdf9

Please sign in to comment.