Skip to content

Commit

Permalink
Require php8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
MortalFlesh committed Apr 22, 2022
1 parent fad2278 commit a8fbf26
Show file tree
Hide file tree
Showing 28 changed files with 181 additions and 260 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/tests.yaml
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -3,6 +3,7 @@
<!-- There should always be "Unreleased" section at the beginning. -->

## Unreleased
- [**BC**] Require php 8.1

## 1.3.0 - 2022-04-05
- Add handled response type to profiler item
Expand Down
27 changes: 14 additions & 13 deletions composer.json
Expand Up @@ -4,24 +4,25 @@
"license": "MIT",
"type": "library",
"require": {
"php": "^7.4",
"php": "^8.1",
"ext-json": "*",
"ext-mbstring": "*",
"lmc/cqrs-types": "^2.3",
"psr/cache": "^1.0",
"psr/http-message": "^1.0",
"ramsey/uuid": "^4.1",
"symfony/stopwatch": "^4.4 || ^5.0"
"lmc/cqrs-types": "^3.0",
"psr/cache": "^3.0",
"psr/http-message": "^1.0.1",
"ramsey/collection": "^1.2.2",
"ramsey/uuid": "^4.2.3",
"symfony/stopwatch": "^4.4 || ^5.0 || ^6.0"
},
"require-dev": {
"ergebnis/composer-normalize": "^2.5",
"lmc/coding-standard": "^3.0",
"lmc/coding-standard": "^3.3",
"php-parallel-lint/php-parallel-lint": "^1.2",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan": "^0.12.83",
"phpstan/phpstan-phpunit": "^0.12.18",
"phpunit/phpunit": "^9.5",
"symfony/cache": "^5.2"
"phpstan/phpstan": "^1.4",
"phpstan/phpstan-phpunit": "^1.0",
"phpunit/phpunit": "^9.5.20",
"symfony/cache": "^5.2 || ^6.0"
},
"autoload": {
"psr-4": {
Expand All @@ -36,8 +37,8 @@
"config": {
"allow-plugins": {
"phpstan/extension-installer": true,
"dealerdirect/phpcodesniffer-composer-installer": true,
"ergebnis/composer-normalize": true
"ergebnis/composer-normalize": true,
"dealerdirect/phpcodesniffer-composer-installer": true
},
"sort-packages": true
},
Expand Down
10 changes: 6 additions & 4 deletions ecs.php
Expand Up @@ -3,7 +3,7 @@
declare(strict_types=1);

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

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

$containerConfigurator->import(__DIR__ . '/vendor/lmc/coding-standard/ecs.php');
Expand All @@ -26,6 +29,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: 10 additions & 1 deletion phpstan.neon
@@ -1,8 +1,17 @@
parameters:
checkMissingIterableValueType: false
level: 7
level: 8
paths:
- src
- tests/

ignoreErrors:
-
message: "#^Cannot call method getItem\\(\\) on Psr\\\\Cache\\\\CacheItemPoolInterface\\|null\\.$#"
count: 1
path: src/QueryFetcher.php

-
message: "#^Cannot call method save\\(\\) on Psr\\\\Cache\\\\CacheItemPoolInterface\\|null\\.$#"
count: 1
path: src/QueryFetcher.php
6 changes: 1 addition & 5 deletions src/Command/ProfiledDataCommand.php
Expand Up @@ -16,17 +16,13 @@ class ProfiledDataCommand implements CommandInterface, ProfileableInterface
* @var callable
*/
private $createData;
private string $profilerId;
private ?array $profilerData;

/**
* @phpstan-param callable(): Data $createData
*/
public function __construct(callable $createData, string $profilerId, ?array $profilerData = null)
public function __construct(callable $createData, private string $profilerId, private ?array $profilerData = null)
{
$this->createData = $createData;
$this->profilerId = $profilerId;
$this->profilerData = $profilerData;
}

final public function getRequestType(): string
Expand Down
22 changes: 10 additions & 12 deletions src/CommandSender.php
Expand Up @@ -24,13 +24,13 @@
* @phpstan-template DecodedResponse
*
* @phpstan-type Handler SendCommandHandlerInterface<Request, Response>
* @phpstan-type Context SendContext<Request, Handler, DecodedResponse>
* @phpstan-type Context SendContext<Request, Response>
*
* @phpstan-implements CommandSenderInterface<Request, DecodedResponse>
*/
class CommandSender implements CommandSenderInterface
{
/** @phpstan-use CommonCQRSTrait<Context, Handler> */
/** @phpstan-use CommonCQRSTrait<Request, Response, Context, Handler> */
use CommonCQRSTrait;

/**
Expand Down Expand Up @@ -68,7 +68,7 @@ class CommandSender implements CommandSenderInterface
public function __construct(
?ProfilerBag $profilerBag,
iterable $customHandlers = [],
iterable $customDecoders = []
iterable $customDecoders = [],
) {
$this->profilerBag = $profilerBag;

Expand Down Expand Up @@ -146,12 +146,11 @@ public function send(CommandInterface $command, OnSuccessInterface $onSuccess, O
* @phpstan-param ResponseDecoderInterface<T, U> $decoder
* @phpstan-param T $currentResponse
* @phpstan-return U
* @param mixed $currentResponse
*/
private function getDecodedResponse(
SendContext $context,
ResponseDecoderInterface $decoder,
$currentResponse
mixed $currentResponse,
) {
return $decoder->decode($currentResponse);
}
Expand All @@ -160,9 +159,8 @@ private function getDecodedResponse(
* @phpstan-param CommandInterface<Request> $command
* @phpstan-return DecodedResponse
* @throws \Throwable
* @return mixed
*/
public function sendAndReturn(CommandInterface $command)
public function sendAndReturn(CommandInterface $command): mixed
{
$response = null;

Expand All @@ -171,7 +169,7 @@ public function sendAndReturn(CommandInterface $command)
new OnSuccessCallback(function ($decodedResponse) use (&$response): void {
$response = $decodedResponse;
}),
OnErrorCallback::throwOnError()
OnErrorCallback::throwOnError(),
);

return $response;
Expand All @@ -181,7 +179,7 @@ private function iterateHandlers(): array
{
return array_map(
fn (PrioritizedItem $PrioritizedItem) => $PrioritizedItem->getItem(),
$this->handlers
$this->handlers,
);
}

Expand All @@ -198,8 +196,8 @@ private function startProfileCommand(ProfileableInterface $command, SendContext
$command->getProfilerId(),
$command->getProfilerData(),
ProfilerItem::TYPE_COMMAND,
get_class($command)
)
get_class($command),
),
);

$context->startStopwatch();
Expand All @@ -219,7 +217,7 @@ private function profileCommandFinished(SendContext $context): void
$profilerItem->setHandledBy(sprintf(
'%s<%s>',
Utils::getType($currentHandler),
$context->getHandledResponseType()
$context->getHandledResponseType(),
));
$profilerItem->setDecodedBy($context->getUsedDecoders());

Expand Down
71 changes: 23 additions & 48 deletions src/Core/AbstractContext.php
Expand Up @@ -4,7 +4,9 @@

use Lmc\Cqrs\Types\CommandInterface;
use Lmc\Cqrs\Types\Decoder\ResponseDecoderInterface;
use Lmc\Cqrs\Types\QueryHandlerInterface;
use Lmc\Cqrs\Types\QueryInterface;
use Lmc\Cqrs\Types\SendCommandHandlerInterface;
use Lmc\Cqrs\Types\Utils;
use Lmc\Cqrs\Types\ValueObject\ProfilerItem;
use Ramsey\Uuid\Uuid;
Expand All @@ -14,22 +16,18 @@
/**
* @internal
*
* @phpstan-template Initiator
* @phpstan-template Handler
* @phpstan-template Request
* @phpstan-template Response
*/
abstract class AbstractContext
{
private UuidInterface $key;
/**
* @phpstan-var Initiator
* @var QueryInterface|CommandInterface
*/
private $initiator;
/** @phpstan-var QueryInterface<Request>|CommandInterface<Request> */
private QueryInterface|CommandInterface $initiator;

private bool $isHandled = false;
/** @phpstan-var Handler|null */
private $usedHandler;
/** @phpstan-var QueryHandlerInterface<Request, Response>|SendCommandHandlerInterface<Request, Response>|null */
private QueryHandlerInterface|SendCommandHandlerInterface|null $usedHandler;
private ?string $handledResponseType = null;

/** @var string[] */
Expand All @@ -38,27 +36,18 @@ abstract class AbstractContext
private ?Stopwatch $stopwatch = null;

private ?\Throwable $error = null;
/**
* @phpstan-var ?Response
* @var ?mixed
*/
private $response;
/** @phpstan-var ?Response */
private mixed $response = null;

/**
* @phpstan-param Initiator $initiator
* @param QueryInterface|CommandInterface $initiator
*/
public function __construct($initiator)
/** @phpstan-param QueryInterface<Request>|CommandInterface<Request> $initiator */
public function __construct(QueryInterface|CommandInterface $initiator)
{
$this->initiator = $initiator;
$this->key = Uuid::uuid4();
}

/**
* @phpstan-return Initiator
* @return QueryInterface|CommandInterface
*/
public function getInitiator()
/** @phpstan-return QueryInterface<Request>|CommandInterface<Request> */
public function getInitiator(): QueryInterface|CommandInterface
{
return $this->initiator;
}
Expand Down Expand Up @@ -92,20 +81,14 @@ public function isHandled(): bool
return $this->isHandled;
}

/**
* @phpstan-param Handler|null $usedHandler
* @param mixed $usedHandler
*/
public function setUsedHandler($usedHandler): void
/** @phpstan-param QueryHandlerInterface<Request, Response>|SendCommandHandlerInterface<Request, Response>|null $usedHandler */
public function setUsedHandler(QueryHandlerInterface|SendCommandHandlerInterface|null $usedHandler): void
{
$this->usedHandler = $usedHandler;
}

/**
* @phpstan-return Handler|null
* @return mixed
*/
public function getUsedHandler()
/** @phpstan-return QueryHandlerInterface<Request, Response>|SendCommandHandlerInterface<Request, Response>|null */
public function getUsedHandler(): QueryHandlerInterface|SendCommandHandlerInterface|null
{
return $this->usedHandler;
}
Expand All @@ -120,20 +103,14 @@ public function getHandledResponseType(): ?string
return $this->handledResponseType;
}

/**
* @phpstan-param ?Response $response
* @param ?mixed $response
*/
public function setResponse($response): void
/** @phpstan-param ?Response $response */
public function setResponse(mixed $response): void
{
$this->response = $response;
}

/**
* @phpstan-return ?Response
* @return ?mixed
*/
public function getResponse()
/** @phpstan-return ?Response */
public function getResponse(): mixed
{
return $this->response;
}
Expand All @@ -155,16 +132,14 @@ public function getError(): ?\Throwable
* @phpstan-param ResponseDecoderInterface<T, U> $decoder
* @phpstan-param T $currentResponse
* @phpstan-param U $decodedResponse
* @param mixed $currentResponse
* @param mixed $decodedResponse
*/
public function addUsedDecoder(ResponseDecoderInterface $decoder, $currentResponse, $decodedResponse): void
public function addUsedDecoder(ResponseDecoderInterface $decoder, mixed $currentResponse, mixed $decodedResponse): void
{
$this->usedDecoders[] = sprintf(
'%s<%s, %s>',
get_class($decoder),
Utils::getType($currentResponse),
Utils::getType($decodedResponse)
Utils::getType($decodedResponse),
);
}

Expand Down

0 comments on commit a8fbf26

Please sign in to comment.