Skip to content

Commit

Permalink
Merge pull request #36 from samsonasik/apply-php80
Browse files Browse the repository at this point in the history
Apply PHP 8.0 Syntax and constructor promotion
  • Loading branch information
Ocramius authored Jan 5, 2023
2 parents bbc3a0b + 76ccec0 commit 7a47834
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 40 deletions.
3 changes: 1 addition & 2 deletions src/Emitter/EmitterStack.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,10 @@ public function unshift($emitter)
/**
* Validate that an emitter implements EmitterInterface.
*
* @param mixed $emitter
* @throws Exception\InvalidEmitterException For non-emitter instances.
* @psalm-assert EmitterInterface $emitter
*/
private function validateEmitter($emitter): void
private function validateEmitter(mixed $emitter): void
{
if (! $emitter instanceof EmitterInterface) {
throw Exception\InvalidEmitterException::forEmitter($emitter);
Expand Down
10 changes: 4 additions & 6 deletions src/Emitter/SapiStreamEmitter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@ class SapiStreamEmitter implements EmitterInterface
{
use SapiEmitterTrait;

/** @var int Maximum output buffering size for each iteration. */
private int $maxBufferLength;

public function __construct(int $maxBufferLength = 8192)
{
$this->maxBufferLength = $maxBufferLength;
public function __construct(
/** @param int Maximum output buffering size for each iteration. */
private int $maxBufferLength = 8192
) {
}

/**
Expand Down
7 changes: 3 additions & 4 deletions src/Exception/InvalidEmitterException.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,21 @@
use InvalidArgumentException;
use Laminas\HttpHandlerRunner\Emitter;

use function gettype;
use function is_object;
use function get_debug_type;
use function sprintf;

class InvalidEmitterException extends InvalidArgumentException implements ExceptionInterface
{
/**
* @param mixed $emitter Invalid emitter type
*/
public static function forEmitter($emitter): self
public static function forEmitter(mixed $emitter): self
{
return new self(sprintf(
'%s can only compose %s implementations; received %s',
Emitter\EmitterStack::class,
Emitter\EmitterInterface::class,
is_object($emitter) ? $emitter::class : gettype($emitter)
get_debug_type($emitter)
));
}
}
17 changes: 5 additions & 12 deletions src/RequestHandlerRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,6 @@
*/
final class RequestHandlerRunner implements RequestHandlerRunnerInterface
{
private EmitterInterface $emitter;

/**
* A request handler to run as the application.
*/
private RequestHandlerInterface $handler;

/**
* A factory capable of generating an error response in the scenario that
* the $serverRequestFactory raises an exception during generation of the
Expand All @@ -55,14 +48,14 @@ final class RequestHandlerRunner implements RequestHandlerRunnerInterface
* @param callable(Throwable):ResponseInterface $serverRequestErrorResponseGenerator
*/
public function __construct(
RequestHandlerInterface $handler,
EmitterInterface $emitter,
/**
* A request handler to run as the application.
*/
private RequestHandlerInterface $handler,
private EmitterInterface $emitter,
callable $serverRequestFactory,
callable $serverRequestErrorResponseGenerator
) {
$this->handler = $handler;
$this->emitter = $emitter;

$this->serverRequestFactory = $serverRequestFactory;
$this->serverRequestErrorResponseGenerator = $serverRequestErrorResponseGenerator;
}
Expand Down
9 changes: 3 additions & 6 deletions test/Emitter/EmitterStackTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@ public function nonEmitterValues(): iterable

/**
* @dataProvider nonEmitterValues
* @param mixed $value
*/
public function testCannotPushNonEmitterToStack($value): void
public function testCannotPushNonEmitterToStack(mixed $value): void
{
$this->expectException(Exception\InvalidEmitterException::class);
/** @psalm-suppress MixedArgument */
Expand All @@ -60,9 +59,8 @@ public function testCannotPushNonEmitterToStack($value): void

/**
* @dataProvider nonEmitterValues
* @param mixed $value
*/
public function testCannotUnshiftNonEmitterToStack($value): void
public function testCannotUnshiftNonEmitterToStack(mixed $value): void
{
$this->expectException(Exception\InvalidEmitterException::class);
/** @psalm-suppress MixedArgument */
Expand All @@ -71,9 +69,8 @@ public function testCannotUnshiftNonEmitterToStack($value): void

/**
* @dataProvider nonEmitterValues
* @param mixed $value
*/
public function testCannotSetNonEmitterToSpecificIndex($value): void
public function testCannotSetNonEmitterToSpecificIndex(mixed $value): void
{
$this->expectException(Exception\InvalidEmitterException::class);
/** @psalm-suppress MixedArgument */
Expand Down
2 changes: 1 addition & 1 deletion test/Emitter/SapiStreamEmitterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ public function emitJsonResponseProvider(): array
* @dataProvider emitJsonResponseProvider
* @param mixed $contents Contents stored in stream
*/
public function testEmitJsonResponse($contents): void
public function testEmitJsonResponse(mixed $contents): void
{
$response = (new JsonResponse($contents))
->withStatus(200);
Expand Down
12 changes: 3 additions & 9 deletions test/TestAsset/MockStreamHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ class MockStreamHelper
/** @var string|callable(int,?int=null):string */
private $contents;

private int $position;

private int $size;

private int $startPosition;

/** @var null|callable */
Expand All @@ -30,14 +26,12 @@ class MockStreamHelper
*/
public function __construct(
$contents,
int $size,
int $startPosition,
private int $size,
private int $position,
?callable $trackPeakBufferLength = null
) {
$this->contents = $contents;
$this->size = $size;
$this->position = $startPosition;
$this->startPosition = $startPosition;
$this->startPosition = $position;
$this->trackPeakBufferLength = $trackPeakBufferLength;
}

Expand Down

0 comments on commit 7a47834

Please sign in to comment.