From 6f8d368707c373ed9266ec92df0c18921a4fb7f3 Mon Sep 17 00:00:00 2001 From: Petr Chromec Date: Fri, 22 Apr 2022 14:05:21 +0200 Subject: [PATCH] Use codestyle supporting php 8.1 --- CHANGELOG.md | 3 +- composer.json | 4 +- ecs.php | 10 +--- phpstan.neon | 2 +- src/Command/AbstractHttpCommand.php | 3 +- src/Decoder/StreamResponseDecoder.php | 3 +- src/Exception/HttpBadRequestException.php | 2 +- src/Exception/HttpServerErrorException.php | 2 +- src/Query/AbstractHttpGetQuery.php | 2 +- src/Query/AbstractHttpQuery.php | 3 +- tests/Formatter/HttpProfilerFormatterTest.php | 58 +++++++++---------- tests/Handler/HttpQueryHandlerTest.php | 6 +- tests/Handler/HttpSendCommandHandlerTest.php | 8 +-- 13 files changed, 49 insertions(+), 57 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 74ec3dd..60964c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,8 @@ ## Unreleased -- [**BC**] Require php 8.1 +- Require php 8.1 + - [**BC**] Use new language features and change method signatures ## 2.0.0 - 2021-08-10 - [**BC**] Add an `$initiator` to `ResponseDecoders` `supports` method diff --git a/composer.json b/composer.json index 0864ced..392f174 100644 --- a/composer.json +++ b/composer.json @@ -8,7 +8,7 @@ "ext-json": "*", "ext-mbstring": "*", "fig/http-message-util": "^1.1", - "lmc/cqrs-types": "dev-feature/require-php-81@dev", + "lmc/cqrs-types": "^3.0", "psr/http-client": "^1.0", "psr/http-factory": "^1.0", "psr/http-message": "^1.0" @@ -16,7 +16,7 @@ "require-dev": { "ergebnis/composer-normalize": "^2.5", "guzzlehttp/psr7": "^2.1", - "lmc/coding-standard": "^3.2", + "lmc/coding-standard": "^3.3", "nyholm/psr7": "^1.4", "php-parallel-lint/php-parallel-lint": "^1.2", "phpstan/extension-installer": "^1.1", diff --git a/ecs.php b/ecs.php index 2c37308..8e4f714 100644 --- a/ecs.php +++ b/ecs.php @@ -3,8 +3,6 @@ declare(strict_types=1); use Lmc\CodingStandard\Sniffs\Naming\ClassNameSuffixByParentSniff; -use PhpCsFixer\Fixer\Operator\BinaryOperatorSpacesFixer; -use PhpCsFixer\Fixer\Phpdoc\NoSuperfluousPhpdocTagsFixer; use PhpCsFixer\Fixer\PhpUnit\PhpUnitTestAnnotationFixer; use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; use Symplify\EasyCodingStandard\ValueObject\Option; @@ -16,8 +14,7 @@ Option::SKIP, [ 'SlevomatCodingStandard\Sniffs\Exceptions\ReferenceThrowableOnlySniff.ReferencedGeneralException' => ['tests/Exception/*.php'], - BinaryOperatorSpacesFixer::class => null, - ] + ], ); $containerConfigurator->import(__DIR__ . '/vendor/lmc/coding-standard/ecs.php'); @@ -30,8 +27,5 @@ $services->set(ClassNameSuffixByParentSniff::class) ->property('extraParentTypesToSuffixes', ['*ApplicatorInterface' => 'Applicator']); - $services->set(NoSuperfluousPhpdocTagsFixer::class) - ->call('configure', [['allow_mixed' => true]]); - - $containerConfigurator->import(__DIR__ . '/vendor/lmc/coding-standard/ecs-7.4.php'); + $containerConfigurator->import(__DIR__ . '/vendor/lmc/coding-standard/ecs-8.1.php'); }; diff --git a/phpstan.neon b/phpstan.neon index 226823f..3ff2c54 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,7 +1,7 @@ parameters: checkMissingIterableValueType: false treatPhpDocTypesAsCertain: false - level: 7 + level: 8 paths: - src - tests/ diff --git a/src/Command/AbstractHttpCommand.php b/src/Command/AbstractHttpCommand.php index 6e7a3a1..887a14c 100644 --- a/src/Command/AbstractHttpCommand.php +++ b/src/Command/AbstractHttpCommand.php @@ -36,8 +36,7 @@ public function modifyRequest(RequestInterface $request): RequestInterface /** @see RequestMethodInterface */ abstract public function getHttpMethod(): string; - /** @return UriInterface|string */ - abstract public function getUri(); + abstract public function getUri(): UriInterface|string; public function getProfilerId(): string { diff --git a/src/Decoder/StreamResponseDecoder.php b/src/Decoder/StreamResponseDecoder.php index 13f91b4..2e5ff79 100644 --- a/src/Decoder/StreamResponseDecoder.php +++ b/src/Decoder/StreamResponseDecoder.php @@ -25,8 +25,7 @@ public function decode(mixed $response): mixed : $response; } - /** @return StreamInterface|string */ - private function decodeStream(StreamInterface $stream) + private function decodeStream(StreamInterface $stream): StreamInterface|string { try { if (!empty($contents = $stream->getContents())) { diff --git a/src/Exception/HttpBadRequestException.php b/src/Exception/HttpBadRequestException.php index 7c62be1..3fd875b 100644 --- a/src/Exception/HttpBadRequestException.php +++ b/src/Exception/HttpBadRequestException.php @@ -19,7 +19,7 @@ public function __construct( private RequestInterface $request, private ResponseInterface $response, int $code = 0, - ?\Throwable $previous = null + ?\Throwable $previous = null, ) { parent::__construct(self::createMessage($response->getReasonPhrase()), $code, $previous); } diff --git a/src/Exception/HttpServerErrorException.php b/src/Exception/HttpServerErrorException.php index be563f5..9682dae 100644 --- a/src/Exception/HttpServerErrorException.php +++ b/src/Exception/HttpServerErrorException.php @@ -19,7 +19,7 @@ public function __construct( private RequestInterface $request, private ResponseInterface $response, int $code = 0, - ?\Throwable $previous = null + ?\Throwable $previous = null, ) { parent::__construct(self::createMessage($response->getReasonPhrase()), $code, $previous); } diff --git a/src/Query/AbstractHttpGetQuery.php b/src/Query/AbstractHttpGetQuery.php index 0f69d28..afe1111 100644 --- a/src/Query/AbstractHttpGetQuery.php +++ b/src/Query/AbstractHttpGetQuery.php @@ -24,7 +24,7 @@ public function getCacheKey(): CacheKey return new CacheKey(sprintf( '%s:%s', static::class, - $this->getUri() + $this->getUri(), )); } } diff --git a/src/Query/AbstractHttpQuery.php b/src/Query/AbstractHttpQuery.php index 120b288..31b2b09 100644 --- a/src/Query/AbstractHttpQuery.php +++ b/src/Query/AbstractHttpQuery.php @@ -35,8 +35,7 @@ public function modifyRequest(RequestInterface $request): RequestInterface /** @see RequestMethodInterface */ abstract public function getHttpMethod(): string; - /** @return UriInterface|string */ - abstract public function getUri(); + abstract public function getUri(): UriInterface|string; public function getProfilerId(): string { diff --git a/tests/Formatter/HttpProfilerFormatterTest.php b/tests/Formatter/HttpProfilerFormatterTest.php index dcdce00..e1c0892 100644 --- a/tests/Formatter/HttpProfilerFormatterTest.php +++ b/tests/Formatter/HttpProfilerFormatterTest.php @@ -51,14 +51,14 @@ public function provideNyholmItems(): iterable 'test', '', $request = (new \Nyholm\Psr7\Request('get', 'url')) - ->withBody(\Nyholm\Psr7\Stream::create('body')) + ->withBody(\Nyholm\Psr7\Stream::create('body')), ), new ProfilerItem( 'id', null, 'test', '', - new FormattedValue($request, 'body') + new FormattedValue($request, 'body'), ), ]; @@ -69,14 +69,14 @@ public function provideNyholmItems(): iterable 'test', '', $request = (new \Nyholm\Psr7\Request('get', 'url')) - ->withBody(\Nyholm\Psr7\Stream::create()) + ->withBody(\Nyholm\Psr7\Stream::create()), ), new ProfilerItem( 'id', null, 'test', '', - new FormattedValue($request, '') + new FormattedValue($request, ''), ), ]; @@ -86,14 +86,14 @@ public function provideNyholmItems(): iterable null, 'test', '', - $response = (new \Nyholm\Psr7\Response(200, [], 'body')) + $response = (new \Nyholm\Psr7\Response(200, [], 'body')), ), new ProfilerItem( 'id', null, 'test', '', - new FormattedValue($response, 'body') + new FormattedValue($response, 'body'), ), ]; @@ -103,14 +103,14 @@ public function provideNyholmItems(): iterable null, 'test', '', - $response = (new \Nyholm\Psr7\Response(200, [], \Nyholm\Psr7\Stream::create('body'))) + $response = (new \Nyholm\Psr7\Response(200, [], \Nyholm\Psr7\Stream::create('body'))), ), new ProfilerItem( 'id', null, 'test', '', - new FormattedValue($response, 'body') + new FormattedValue($response, 'body'), ), ]; @@ -120,14 +120,14 @@ public function provideNyholmItems(): iterable null, 'test', '', - $stream = (\Nyholm\Psr7\Stream::create('body')) + $stream = (\Nyholm\Psr7\Stream::create('body')), ), new ProfilerItem( 'id', null, 'test', '', - new FormattedValue($stream, 'body') + new FormattedValue($stream, 'body'), ), ]; } @@ -141,14 +141,14 @@ public function provideNyholmAdditioanlItems(): iterable 'additional' => $request = (new \Nyholm\Psr7\Request('get', 'url')) ->withBody(\Nyholm\Psr7\Stream::create('body')), ], - 'test' + 'test', ), new ProfilerItem( 'id', [ 'additional' => new FormattedValue($request, 'body'), ], - 'test' + 'test', ), ]; @@ -193,17 +193,17 @@ public function provideNyholmAdditioanlItems(): iterable 'additional' => $response = (new \Nyholm\Psr7\Response( 200, [], - \Nyholm\Psr7\Stream::create('body') + \Nyholm\Psr7\Stream::create('body'), )), ], - 'test' + 'test', ), new ProfilerItem( 'id', [ 'additional' => new FormattedValue($response, 'body'), ], - 'test' + 'test', ), ]; @@ -234,14 +234,14 @@ public function provideGuzzleItems(): iterable 'test', '', $request = (new \GuzzleHttp\Psr7\Request('post', 'url')) - ->withBody(Utils::streamFor('body')) + ->withBody(Utils::streamFor('body')), ), new ProfilerItem( 'id', null, 'test', '', - new FormattedValue($request, 'body') + new FormattedValue($request, 'body'), ), ]; @@ -252,14 +252,14 @@ public function provideGuzzleItems(): iterable 'test', '', $request = (new \GuzzleHttp\Psr7\Request('post', 'url')) - ->withBody(Utils::streamFor(null)) + ->withBody(Utils::streamFor(null)), ), new ProfilerItem( 'id', null, 'test', '', - new FormattedValue($request, '') + new FormattedValue($request, ''), ), ]; @@ -269,14 +269,14 @@ public function provideGuzzleItems(): iterable null, 'test', '', - $response = (new \GuzzleHttp\Psr7\Response(200, [], 'body')) + $response = (new \GuzzleHttp\Psr7\Response(200, [], 'body')), ), new ProfilerItem( 'id', null, 'test', '', - new FormattedValue($response, 'body') + new FormattedValue($response, 'body'), ), ]; @@ -286,14 +286,14 @@ public function provideGuzzleItems(): iterable null, 'test', '', - $response = (new \GuzzleHttp\Psr7\Response(200, [], Utils::streamFor('body'))) + $response = (new \GuzzleHttp\Psr7\Response(200, [], Utils::streamFor('body'))), ), new ProfilerItem( 'id', null, 'test', '', - new FormattedValue($response, 'body') + new FormattedValue($response, 'body'), ), ]; @@ -303,14 +303,14 @@ public function provideGuzzleItems(): iterable null, 'test', '', - $stream = (Utils::streamFor('body')) + $stream = (Utils::streamFor('body')), ), new ProfilerItem( 'id', null, 'test', '', - new FormattedValue($stream, 'body') + new FormattedValue($stream, 'body'), ), ]; } @@ -331,7 +331,7 @@ public function provideGuzzleAdditionalItems(): iterable [ 'additional' => new FormattedValue($request, 'body'), ], - 'test' + 'test', ), ]; @@ -348,7 +348,7 @@ public function provideGuzzleAdditionalItems(): iterable [ 'additional' => new FormattedValue($request, ''), ], - 'test' + 'test', ), ]; @@ -392,14 +392,14 @@ public function provideGuzzleAdditionalItems(): iterable null, 'test', '', - $stream = (Utils::streamFor('body')) + $stream = (Utils::streamFor('body')), ), new ProfilerItem( 'id', null, 'test', '', - new FormattedValue($stream, 'body') + new FormattedValue($stream, 'body'), ), ]; } diff --git a/tests/Handler/HttpQueryHandlerTest.php b/tests/Handler/HttpQueryHandlerTest.php index 9c6262d..fd35594 100644 --- a/tests/Handler/HttpQueryHandlerTest.php +++ b/tests/Handler/HttpQueryHandlerTest.php @@ -41,7 +41,7 @@ public function shouldFetchHttpQuery(): void new OnSuccessCallback( fn (ResponseInterface $response) => $this->assertSame($data, $response->getBody()->getContents()) ), - new OnErrorCallback(fn (\Throwable $error) => $this->fail($error->getMessage())) + new OnErrorCallback(fn (\Throwable $error) => $this->fail($error->getMessage())), ); } @@ -72,7 +72,7 @@ public function shouldFetchHttpQueryAsErrorWithBadRequest(): void $this->assertSame($request, $error->getRequest()); $this->assertSame($response, $error->getResponse()); } - }) + }), ); } @@ -103,7 +103,7 @@ public function shouldFetchHttpQueryAsErrorWithServerError(): void $this->assertSame($request, $error->getRequest()); $this->assertSame($response, $error->getResponse()); } - }) + }), ); } } diff --git a/tests/Handler/HttpSendCommandHandlerTest.php b/tests/Handler/HttpSendCommandHandlerTest.php index 428c99a..18af340 100644 --- a/tests/Handler/HttpSendCommandHandlerTest.php +++ b/tests/Handler/HttpSendCommandHandlerTest.php @@ -45,7 +45,7 @@ public function shouldSendPostCommand(): void new OnSuccessCallback( fn (ResponseInterface $response) => $this->assertSame($responseData, $response->getBody()->getContents()) ), - new OnErrorCallback(fn (\Throwable $error) => $this->fail($error->getMessage())) + new OnErrorCallback(fn (\Throwable $error) => $this->fail($error->getMessage())), ); } @@ -70,7 +70,7 @@ public function shouldSendPutCommand(): void new OnSuccessCallback( fn (ResponseInterface $response) => $this->assertSame($responseData, $response->getBody()->getContents()) ), - new OnErrorCallback(fn (\Throwable $error) => $this->fail($error->getMessage())) + new OnErrorCallback(fn (\Throwable $error) => $this->fail($error->getMessage())), ); } @@ -101,7 +101,7 @@ public function shouldSendPutCommandAsErrorWithBadRequest(): void $this->assertSame($request, $error->getRequest()); $this->assertSame($response, $error->getResponse()); } - }) + }), ); } @@ -132,7 +132,7 @@ public function shouldSendPutCommandAsErrorWithServerError(): void $this->assertSame($request, $error->getRequest()); $this->assertSame($response, $error->getResponse()); } - }) + }), ); } }