Skip to content

Commit

Permalink
Merge pull request #32 from samsonasik/apply-php74
Browse files Browse the repository at this point in the history
Apply PHP 7.4 syntax and typed property
  • Loading branch information
Ocramius committed Sep 17, 2022
2 parents 5e7d886 + acbc9f3 commit eb670c5
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 36 deletions.
2 changes: 1 addition & 1 deletion src/Emitter/SapiStreamEmitter.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class SapiStreamEmitter implements EmitterInterface
use SapiEmitterTrait;

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

public function __construct(int $maxBufferLength = 8192)
{
Expand Down
10 changes: 4 additions & 6 deletions src/RequestHandlerRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Laminas\HttpHandlerRunner;

use Laminas\HttpHandlerRunner\Emitter\EmitterInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
Expand All @@ -22,15 +23,12 @@
*/
final class RequestHandlerRunner implements RequestHandlerRunnerInterface
{
/** @var Emitter\EmitterInterface */
private $emitter;
private EmitterInterface $emitter;

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

/**
* A factory capable of generating an error response in the scenario that
Expand Down Expand Up @@ -58,7 +56,7 @@ final class RequestHandlerRunner implements RequestHandlerRunnerInterface
*/
public function __construct(
RequestHandlerInterface $handler,
Emitter\EmitterInterface $emitter,
EmitterInterface $emitter,
callable $serverRequestFactory,
callable $serverRequestErrorResponseGenerator
) {
Expand Down
3 changes: 1 addition & 2 deletions test/ConfigProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@

class ConfigProviderTest extends TestCase
{
/** @var ConfigProvider */
private $provider;
private ConfigProvider $provider;

public function setUp(): void
{
Expand Down
3 changes: 1 addition & 2 deletions test/Emitter/EmitterStackTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@

class EmitterStackTest extends TestCase
{
/** @var EmitterStack */
private $emitter;
private EmitterStack $emitter;

public function setUp(): void
{
Expand Down
16 changes: 6 additions & 10 deletions test/Emitter/SapiStreamEmitterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ public function setUp(): void

public function testEmitCallbackStreamResponse(): void
{
$stream = new CallbackStream(function () {
return 'it works';
});
$stream = new CallbackStream(static fn(): string => 'it works');
$response = (new Response())
->withStatus(200)
->withBody($stream);
Expand Down Expand Up @@ -124,7 +122,7 @@ public function testEmitStreamResponse(bool $seekable, bool $readable, string $c
$contents,
strlen($contents),
$startPosition,
function (int $bufferLength) use (&$peakBufferLength): void {
static function (int $bufferLength) use (&$peakBufferLength): void {
self::assertIsInt($peakBufferLength);
if ($bufferLength > $peakBufferLength) {
$peakBufferLength = $bufferLength;
Expand Down Expand Up @@ -420,7 +418,7 @@ public function testEmitMemoryUsage(
$peakMemoryUsage = (int) max($peakMemoryUsage, memory_get_usage());
};

$contentsCallback = function (int $position, ?int $length = null) use (&$sizeBytes): string {
$contentsCallback = static function (int $position, ?int $length = null) use (&$sizeBytes): string {
self::assertIsInt($sizeBytes);
if (! $length) {
$length = $sizeBytes - $position;
Expand All @@ -429,7 +427,7 @@ public function testEmitMemoryUsage(
return str_repeat('0', $length);
};

$trackPeakBufferLength = function (int $bufferLength) use (&$peakBufferLength): void {
$trackPeakBufferLength = static function (int $bufferLength) use (&$peakBufferLength): void {
if ($bufferLength > $peakBufferLength) {
$peakBufferLength = $bufferLength;
}
Expand Down Expand Up @@ -476,7 +474,7 @@ public function testEmitMemoryUsage(
}

ob_start(
function () use (&$closureTrackMemoryUsage) {
static function () use (&$closureTrackMemoryUsage): string {
self::assertIsCallable($closureTrackMemoryUsage);
$closureTrackMemoryUsage();
return '';
Expand Down Expand Up @@ -610,9 +608,7 @@ public function testContentRange(string $header, string $body, string $expected)

public function testContentRangeUnseekableBody(): void
{
$body = new CallbackStream(function () {
return 'Hello world';
});
$body = new CallbackStream(static fn(): string => 'Hello world');
$response = (new Response())
->withBody($body)
->withHeader('Content-Range', 'bytes 3-6/*');
Expand Down
15 changes: 9 additions & 6 deletions test/RequestHandlerRunnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,18 @@ class RequestHandlerRunnerTest extends TestCase
public function testUsesErrorResponseGeneratorToGenerateResponseWhenRequestFactoryRaisesException(): void
{
$exception = new Exception();
$serverRequestFactory = function () use ($exception): ServerRequestInterface {
$serverRequestFactory = static function () use ($exception): ServerRequestInterface {
throw $exception;
};

$response = $this->createMock(ResponseInterface::class);

$errorResponseGenerator = function (Throwable $passedThrowable) use ($exception, $response): ResponseInterface {
$errorResponseGenerator = static function (
Throwable $passedThrowable
) use (
$exception,
$response
): ResponseInterface {
Assert::assertSame($exception, $passedThrowable);
return $response;
};
Expand All @@ -50,11 +55,9 @@ public function testRunPassesRequestGeneratedByRequestFactoryToHandleWhenNoReque
{
$request = $this->createMock(ServerRequestInterface::class);

$serverRequestFactory = function () use ($request): ServerRequestInterface {
return $request;
};
$serverRequestFactory = static fn(): ServerRequestInterface => $request;

$errorResponseGenerator = function (): ResponseInterface {
$errorResponseGenerator = static function (): ResponseInterface {
self::fail('Should never hit error response generator');
};

Expand Down
2 changes: 1 addition & 1 deletion test/TestAsset/HeaderStack.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class HeaderStack
* @var string[][]
* @psalm-var list<HeaderType>
*/
private static $data = [];
private static array $data = [];

/**
* Reset state
Expand Down
3 changes: 1 addition & 2 deletions test/TestAsset/HeadersSent.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@

final class HeadersSent
{
/** @var bool */
private static $headerSent = false;
private static bool $headerSent = false;
/** @var null|string */
public static $filename;
/** @var null|int */
Expand Down
9 changes: 3 additions & 6 deletions test/TestAsset/MockStreamHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,11 @@ class MockStreamHelper
/** @var string|callable(int,?int=null):string */
private $contents;

/** @var int */
private $position;
private int $position;

/** @var int */
private $size;
private int $size;

/** @var int */
private $startPosition;
private int $startPosition;

/** @var null|callable */
private $trackPeakBufferLength;
Expand Down

0 comments on commit eb670c5

Please sign in to comment.