Skip to content

Commit 7a47834

Browse files
authored
Merge pull request #36 from samsonasik/apply-php80
Apply PHP 8.0 Syntax and constructor promotion
2 parents bbc3a0b + 76ccec0 commit 7a47834

File tree

7 files changed

+20
-40
lines changed

7 files changed

+20
-40
lines changed

src/Emitter/EmitterStack.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,10 @@ public function unshift($emitter)
9191
/**
9292
* Validate that an emitter implements EmitterInterface.
9393
*
94-
* @param mixed $emitter
9594
* @throws Exception\InvalidEmitterException For non-emitter instances.
9695
* @psalm-assert EmitterInterface $emitter
9796
*/
98-
private function validateEmitter($emitter): void
97+
private function validateEmitter(mixed $emitter): void
9998
{
10099
if (! $emitter instanceof EmitterInterface) {
101100
throw Exception\InvalidEmitterException::forEmitter($emitter);

src/Emitter/SapiStreamEmitter.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@ class SapiStreamEmitter implements EmitterInterface
1818
{
1919
use SapiEmitterTrait;
2020

21-
/** @var int Maximum output buffering size for each iteration. */
22-
private int $maxBufferLength;
23-
24-
public function __construct(int $maxBufferLength = 8192)
25-
{
26-
$this->maxBufferLength = $maxBufferLength;
21+
public function __construct(
22+
/** @param int Maximum output buffering size for each iteration. */
23+
private int $maxBufferLength = 8192
24+
) {
2725
}
2826

2927
/**

src/Exception/InvalidEmitterException.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,21 @@
77
use InvalidArgumentException;
88
use Laminas\HttpHandlerRunner\Emitter;
99

10-
use function gettype;
11-
use function is_object;
10+
use function get_debug_type;
1211
use function sprintf;
1312

1413
class InvalidEmitterException extends InvalidArgumentException implements ExceptionInterface
1514
{
1615
/**
1716
* @param mixed $emitter Invalid emitter type
1817
*/
19-
public static function forEmitter($emitter): self
18+
public static function forEmitter(mixed $emitter): self
2019
{
2120
return new self(sprintf(
2221
'%s can only compose %s implementations; received %s',
2322
Emitter\EmitterStack::class,
2423
Emitter\EmitterInterface::class,
25-
is_object($emitter) ? $emitter::class : gettype($emitter)
24+
get_debug_type($emitter)
2625
));
2726
}
2827
}

src/RequestHandlerRunner.php

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,6 @@
2323
*/
2424
final class RequestHandlerRunner implements RequestHandlerRunnerInterface
2525
{
26-
private EmitterInterface $emitter;
27-
28-
/**
29-
* A request handler to run as the application.
30-
*/
31-
private RequestHandlerInterface $handler;
32-
3326
/**
3427
* A factory capable of generating an error response in the scenario that
3528
* the $serverRequestFactory raises an exception during generation of the
@@ -55,14 +48,14 @@ final class RequestHandlerRunner implements RequestHandlerRunnerInterface
5548
* @param callable(Throwable):ResponseInterface $serverRequestErrorResponseGenerator
5649
*/
5750
public function __construct(
58-
RequestHandlerInterface $handler,
59-
EmitterInterface $emitter,
51+
/**
52+
* A request handler to run as the application.
53+
*/
54+
private RequestHandlerInterface $handler,
55+
private EmitterInterface $emitter,
6056
callable $serverRequestFactory,
6157
callable $serverRequestErrorResponseGenerator
6258
) {
63-
$this->handler = $handler;
64-
$this->emitter = $emitter;
65-
6659
$this->serverRequestFactory = $serverRequestFactory;
6760
$this->serverRequestErrorResponseGenerator = $serverRequestErrorResponseGenerator;
6861
}

test/Emitter/EmitterStackTest.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,8 @@ public function nonEmitterValues(): iterable
4949

5050
/**
5151
* @dataProvider nonEmitterValues
52-
* @param mixed $value
5352
*/
54-
public function testCannotPushNonEmitterToStack($value): void
53+
public function testCannotPushNonEmitterToStack(mixed $value): void
5554
{
5655
$this->expectException(Exception\InvalidEmitterException::class);
5756
/** @psalm-suppress MixedArgument */
@@ -60,9 +59,8 @@ public function testCannotPushNonEmitterToStack($value): void
6059

6160
/**
6261
* @dataProvider nonEmitterValues
63-
* @param mixed $value
6462
*/
65-
public function testCannotUnshiftNonEmitterToStack($value): void
63+
public function testCannotUnshiftNonEmitterToStack(mixed $value): void
6664
{
6765
$this->expectException(Exception\InvalidEmitterException::class);
6866
/** @psalm-suppress MixedArgument */
@@ -71,9 +69,8 @@ public function testCannotUnshiftNonEmitterToStack($value): void
7169

7270
/**
7371
* @dataProvider nonEmitterValues
74-
* @param mixed $value
7572
*/
76-
public function testCannotSetNonEmitterToSpecificIndex($value): void
73+
public function testCannotSetNonEmitterToSpecificIndex(mixed $value): void
7774
{
7875
$this->expectException(Exception\InvalidEmitterException::class);
7976
/** @psalm-suppress MixedArgument */

test/Emitter/SapiStreamEmitterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ public function emitJsonResponseProvider(): array
555555
* @dataProvider emitJsonResponseProvider
556556
* @param mixed $contents Contents stored in stream
557557
*/
558-
public function testEmitJsonResponse($contents): void
558+
public function testEmitJsonResponse(mixed $contents): void
559559
{
560560
$response = (new JsonResponse($contents))
561561
->withStatus(200);

test/TestAsset/MockStreamHelper.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ class MockStreamHelper
1515
/** @var string|callable(int,?int=null):string */
1616
private $contents;
1717

18-
private int $position;
19-
20-
private int $size;
21-
2218
private int $startPosition;
2319

2420
/** @var null|callable */
@@ -30,14 +26,12 @@ class MockStreamHelper
3026
*/
3127
public function __construct(
3228
$contents,
33-
int $size,
34-
int $startPosition,
29+
private int $size,
30+
private int $position,
3531
?callable $trackPeakBufferLength = null
3632
) {
3733
$this->contents = $contents;
38-
$this->size = $size;
39-
$this->position = $startPosition;
40-
$this->startPosition = $startPosition;
34+
$this->startPosition = $position;
4135
$this->trackPeakBufferLength = $trackPeakBufferLength;
4236
}
4337

0 commit comments

Comments
 (0)