Skip to content

Commit

Permalink
Merge pull request #4 from lmc-eu/feature/require-php-81
Browse files Browse the repository at this point in the history
Require php8.1
  • Loading branch information
MortalFlesh authored Apr 27, 2022
2 parents dad89d4 + 6f8d368 commit 9e3a114
Show file tree
Hide file tree
Showing 23 changed files with 107 additions and 127 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ jobs:

strategy:
matrix:
php-version: ['7.4']
php-version: ['8.1']
dependencies: ['']
include:
- { php-version: '7.4', dependencies: '--prefer-lowest --prefer-stable' }
- { php-version: '8.1', dependencies: '--prefer-lowest --prefer-stable' }

name: Unit tests - PHP ${{ matrix.dependencies }}

Expand Down Expand Up @@ -65,7 +65,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
php-version: '8.1'
extensions: json, mbstring

- name: Install dependencies
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<!-- There should always be "Unreleased" section at the beginning. -->

## Unreleased
- 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
Expand Down
25 changes: 15 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,32 +1,29 @@
{
"name": "lmc/cqrs-http",
"type": "library",
"description": "A library containing base implementations to help with Http Queries and Commands",
"license": "MIT",
"type": "library",
"require": {
"php": "^7.4",
"php": "^8.1",
"ext-json": "*",
"ext-mbstring": "*",
"fig/http-message-util": "^1.1",
"lmc/cqrs-types": "^2.0",
"lmc/cqrs-types": "^3.0",
"psr/http-client": "^1.0",
"psr/http-factory": "^1.0",
"psr/http-message": "^1.0"
},
"require-dev": {
"ergebnis/composer-normalize": "^2.5",
"guzzlehttp/psr7": "^1.8",
"lmc/coding-standard": "^3.0",
"guzzlehttp/psr7": "^2.1",
"lmc/coding-standard": "^3.3",
"nyholm/psr7": "^1.4",
"php-parallel-lint/php-parallel-lint": "^1.2",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan": "^0.12.96",
"phpstan/phpstan-phpunit": "^0.12.18",
"phpstan/phpstan": "^1.4",
"phpstan/phpstan-phpunit": "^1.0",
"phpunit/phpunit": "^9.5"
},
"config": {
"sort-packages": true
},
"autoload": {
"psr-4": {
"Lmc\\Cqrs\\Http\\": "src/"
Expand All @@ -37,6 +34,14 @@
"Lmc\\Cqrs\\Http\\": "tests/"
}
},
"config": {
"allow-plugins": {
"phpstan/extension-installer": true,
"ergebnis/composer-normalize": true,
"dealerdirect/phpcodesniffer-composer-installer": true
},
"sort-packages": true
},
"scripts": {
"all": [
"@lint",
Expand Down
8 changes: 4 additions & 4 deletions ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
declare(strict_types=1);

use Lmc\CodingStandard\Sniffs\Naming\ClassNameSuffixByParentSniff;
use PhpCsFixer\Fixer\Phpdoc\NoSuperfluousPhpdocTagsFixer;
use PhpCsFixer\Fixer\PhpUnit\PhpUnitTestAnnotationFixer;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\EasyCodingStandard\ValueObject\Option;
Expand All @@ -13,7 +12,9 @@

$parameters->set(
Option::SKIP,
['SlevomatCodingStandard\Sniffs\Exceptions\ReferenceThrowableOnlySniff.ReferencedGeneralException' => ['tests/Exception/*.php']]
[
'SlevomatCodingStandard\Sniffs\Exceptions\ReferenceThrowableOnlySniff.ReferencedGeneralException' => ['tests/Exception/*.php'],
],
);

$containerConfigurator->import(__DIR__ . '/vendor/lmc/coding-standard/ecs.php');
Expand All @@ -26,6 +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-8.1.php');
};
11 changes: 7 additions & 4 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
parameters:
checkMissingIterableValueType: false
level: 7
treatPhpDocTypesAsCertain: false
level: 8
paths:
- src
- tests/

reportUnmatchedIgnoredErrors: false
reportUnmatchedIgnoredErrors: true

ignoreErrors:
- '#Cannot access offset .size. on array.*#'
- '#Method Lmc\\Cqrs\\Base\\Query\\AbstractHttpQuery::assertHeaderFieldValue\(\) has parameter \$value with no typehint specified.#'
-
message: "#^Else branch is unreachable because ternary operator condition is always true\\.$#"
count: 1
path: src/Command/AbstractHttpPostCommand.php
8 changes: 2 additions & 6 deletions src/Command/AbstractHttpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@
*/
abstract class AbstractHttpCommand implements CommandInterface, ProfileableInterface
{
protected RequestFactoryInterface $requestFactory;

public function __construct(RequestFactoryInterface $requestFactory)
public function __construct(private RequestFactoryInterface $requestFactory)
{
$this->requestFactory = $requestFactory;
}

final public function getRequestType(): string
Expand All @@ -39,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
{
Expand Down
4 changes: 3 additions & 1 deletion src/Command/AbstractHttpPostCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ final public function getHttpMethod(): string

public function createRequest(): RequestInterface
{
return parent::createRequest()->withBody($this->createBody());
return ($request = parent::createRequest()->withBody($this->createBody())) instanceof RequestInterface
? $request
: throw new \LogicException('Implementation of the RequestInterface->withBody(...) does not return a RequestInterface.');
}

abstract public function createBody(): StreamInterface;
Expand Down
5 changes: 2 additions & 3 deletions src/Decoder/HttpMessageResponseDecoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,15 @@
*/
class HttpMessageResponseDecoder implements ResponseDecoderInterface
{
public function supports($response, $initiator): bool
public function supports(mixed $response, mixed $initiator): bool
{
return $response instanceof MessageInterface;
}

/**
* @param mixed $response
* @return StreamInterface|MessageInterface
*/
public function decode($response)
public function decode(mixed $response): mixed
{
return $response instanceof MessageInterface
? $response->getBody()
Expand Down
8 changes: 3 additions & 5 deletions src/Decoder/StreamResponseDecoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,22 @@
*/
class StreamResponseDecoder implements ResponseDecoderInterface
{
public function supports($response, $initiator): bool
public function supports(mixed $response, mixed $initiator): bool
{
return $response instanceof StreamInterface;
}

/**
* @param mixed $response
* @return StreamInterface|string
*/
public function decode($response)
public function decode(mixed $response): mixed
{
return $response instanceof StreamInterface
? $this->decodeStream($response)
: $response;
}

/** @return StreamInterface|string */
private function decodeStream(StreamInterface $stream)
private function decodeStream(StreamInterface $stream): StreamInterface|string
{
try {
if (!empty($contents = $stream->getContents())) {
Expand Down
18 changes: 10 additions & 8 deletions src/Exception/HttpBadRequestException.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,20 @@

class HttpBadRequestException extends \RuntimeException implements CqrsExceptionInterface
{
private RequestInterface $request;
private ResponseInterface $response;
private static function createMessage(?string $reasonPhrase): string
{
return empty($reasonPhrase)
? 'HTTP Bad Request'
: $reasonPhrase;
}

public function __construct(
RequestInterface $request,
ResponseInterface $response,
private RequestInterface $request,
private ResponseInterface $response,
int $code = 0,
?\Throwable $previous = null
?\Throwable $previous = null,
) {
parent::__construct($response->getReasonPhrase() ?? 'HTTP Bad Request', $code, $previous);
$this->request = $request;
$this->response = $response;
parent::__construct(self::createMessage($response->getReasonPhrase()), $code, $previous);
}

public function getRequest(): RequestInterface
Expand Down
18 changes: 10 additions & 8 deletions src/Exception/HttpServerErrorException.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,20 @@

class HttpServerErrorException extends \RuntimeException implements CqrsExceptionInterface
{
private RequestInterface $request;
private ResponseInterface $response;
private static function createMessage(?string $reasonPhrase): string
{
return empty($reasonPhrase)
? 'HTTP Server Error'
: $reasonPhrase;
}

public function __construct(
RequestInterface $request,
ResponseInterface $response,
private RequestInterface $request,
private ResponseInterface $response,
int $code = 0,
?\Throwable $previous = null
?\Throwable $previous = null,
) {
parent::__construct($response->getReasonPhrase() ?? 'HTTP Server Error', $code, $previous);
$this->request = $request;
$this->response = $response;
parent::__construct(self::createMessage($response->getReasonPhrase()), $code, $previous);
}

public function getRequest(): RequestInterface
Expand Down
5 changes: 1 addition & 4 deletions src/Handler/HttpQueryHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@
*/
class HttpQueryHandler extends AbstractQueryHandler
{
private ClientInterface $client;

public function __construct(ClientInterface $client)
public function __construct(private ClientInterface $client)
{
$this->client = $client;
}

/** @phpstan-param QueryInterface<mixed> $query */
Expand Down
5 changes: 1 addition & 4 deletions src/Handler/HttpSendCommandHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@
*/
class HttpSendCommandHandler extends AbstractSendCommandHandler
{
private ClientInterface $client;

public function __construct(ClientInterface $client)
public function __construct(private ClientInterface $client)
{
$this->client = $client;
}

/** @phpstan-param CommandInterface<mixed> $command */
Expand Down
2 changes: 1 addition & 1 deletion src/Query/AbstractHttpGetQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function getCacheKey(): CacheKey
return new CacheKey(sprintf(
'%s:%s',
static::class,
$this->getUri()
$this->getUri(),
));
}
}
8 changes: 2 additions & 6 deletions src/Query/AbstractHttpQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@
*/
abstract class AbstractHttpQuery implements QueryInterface, ProfileableInterface
{
protected RequestFactoryInterface $requestFactory;

public function __construct(RequestFactoryInterface $requestFactory)
public function __construct(private RequestFactoryInterface $requestFactory)
{
$this->requestFactory = $requestFactory;
}

final public function getRequestType(): string
Expand All @@ -38,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
{
Expand Down
6 changes: 1 addition & 5 deletions tests/Decoder/HttpMessageResponseDecoderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,10 @@ protected function setUp(): void
}

/**
* @param mixed $message
* @param mixed $expected
*
* @dataProvider provideMessage
*
* @test
*/
public function shouldDecodeNyholmMessage($message, bool $isSupported, $expected): void
public function shouldDecodeNyholmMessage(mixed $message, bool $isSupported, mixed $expected): void
{
$decoded = $this->decoder->decode($message);

Expand Down
6 changes: 1 addition & 5 deletions tests/Decoder/StreamResponseDecoderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,10 @@ protected function setUp(): void
}

/**
* @param mixed $message
* @param mixed $expected
*
* @dataProvider provideMessage
*
* @test
*/
public function shouldDecodeNyholmMessage($message, bool $isSupported, $expected): void
public function shouldDecodeNyholmMessage(mixed $message, bool $isSupported, mixed $expected): void
{
$decoded = $this->decoder->decode($message);

Expand Down
5 changes: 1 addition & 4 deletions tests/Fixture/DummyHttpGetQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@

class DummyHttpGetQuery extends AbstractHttpGetQuery
{
private string $uri;

public function __construct(string $uri, RequestFactoryInterface $requestFactory)
public function __construct(private string $uri, RequestFactoryInterface $requestFactory)
{
$this->uri = $uri;
parent::__construct($requestFactory);
}

Expand Down
7 changes: 1 addition & 6 deletions tests/Fixture/DummyHttpPostCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,8 @@

class DummyHttpPostCommand extends AbstractHttpPostCommand
{
private string $uri;
private StreamInterface $body;

public function __construct(string $uri, StreamInterface $body, RequestFactoryInterface $requestFactory)
public function __construct(private string $uri, private StreamInterface $body, RequestFactoryInterface $requestFactory)
{
$this->uri = $uri;
$this->body = $body;
parent::__construct($requestFactory);
}

Expand Down
Loading

0 comments on commit 9e3a114

Please sign in to comment.