diff --git a/.github/workflows/rector.yml b/.github/workflows/rector.yml new file mode 100644 index 00000000..bd79331d --- /dev/null +++ b/.github/workflows/rector.yml @@ -0,0 +1,23 @@ +on: + pull_request: + paths-ignore: + - 'docs/**' + - 'README.md' + - 'CHANGELOG.md' + - '.gitignore' + - '.gitattributes' + - 'infection.json.dist' + - 'psalm.xml' + +name: rector + +jobs: + rector: + uses: yiisoft/actions/.github/workflows/rector.yml@master + secrets: + token: ${{ secrets.YIISOFT_GITHUB_TOKEN }} + with: + os: >- + ['ubuntu-latest'] + php: >- + ['8.2'] diff --git a/composer.json b/composer.json index c742c7e7..be146626 100644 --- a/composer.json +++ b/composer.json @@ -38,6 +38,7 @@ "require-dev": { "maglnet/composer-require-checker": "^4.2", "phpunit/phpunit": "^9.5", + "rector/rector": "^0.18.10", "roave/infection-static-analysis-plugin": "^1.16", "spatie/phpunit-watcher": "^1.23", "yiisoft/yii-debug": "dev-master", diff --git a/rector.php b/rector.php new file mode 100644 index 00000000..c80d86e9 --- /dev/null +++ b/rector.php @@ -0,0 +1,29 @@ +paths([ + __DIR__ . '/src', + __DIR__ . '/tests', + ]); + + // register a single rule + $rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class); + + // define sets of rules + $rectorConfig->sets([ + LevelSetList::UP_TO_PHP_80, + ]); + + $rectorConfig->skip([ + ClosureToArrowFunctionRector::class, + JsonThrowOnErrorRector::class, + ]); +}; diff --git a/src/Adapter/AdapterInterface.php b/src/Adapter/AdapterInterface.php index 0fca04de..bde6ebcb 100644 --- a/src/Adapter/AdapterInterface.php +++ b/src/Adapter/AdapterInterface.php @@ -30,8 +30,6 @@ public function status(string $id): JobStatus; /** * Pushing a message to the queue. Adapter sets message ID if available. - * - * @param MessageInterface $message */ public function push(MessageInterface $message): void; diff --git a/src/Cli/SignalLoop.php b/src/Cli/SignalLoop.php index ce075c78..6995c577 100644 --- a/src/Cli/SignalLoop.php +++ b/src/Cli/SignalLoop.php @@ -14,8 +14,6 @@ class SignalLoop implements LoopInterface protected const SIGNALS_SUSPEND = [SIGTSTP]; /** @psalm-suppress UndefinedConstant */ protected const SIGNALS_RESUME = [SIGCONT]; - - protected int $memorySoftLimit; protected bool $pause = false; protected bool $exit = false; @@ -23,10 +21,8 @@ class SignalLoop implements LoopInterface * @param int $memorySoftLimit Soft RAM limit in bytes. The loop won't let you continue to execute the program if * soft limit is reached. Zero means no limit. */ - public function __construct(int $memorySoftLimit = 0) + public function __construct(protected int $memorySoftLimit = 0) { - $this->memorySoftLimit = $memorySoftLimit; - foreach (self::SIGNALS_EXIT as $signal) { pcntl_signal($signal, fn () => $this->exit = true); } diff --git a/src/Cli/SimpleLoop.php b/src/Cli/SimpleLoop.php index c7fcb016..6e3ce0ad 100644 --- a/src/Cli/SimpleLoop.php +++ b/src/Cli/SimpleLoop.php @@ -8,16 +8,12 @@ class SimpleLoop implements LoopInterface { use SoftLimitTrait; - protected int $memorySoftLimit; - /** * @param int $memorySoftLimit Soft RAM limit in bytes. The loop won't let you continue to execute the program if * soft limit is reached. Zero means no limit. */ - public function __construct( - int $memorySoftLimit = 0 - ) { - $this->memorySoftLimit = $memorySoftLimit; + public function __construct(protected int $memorySoftLimit = 0) + { } public function canContinue(): bool diff --git a/src/Command/ListenCommand.php b/src/Command/ListenCommand.php index bc71544f..79ff2e62 100644 --- a/src/Command/ListenCommand.php +++ b/src/Command/ListenCommand.php @@ -17,12 +17,9 @@ final class ListenCommand extends Command protected static $defaultName = 'queue:listen'; protected static $defaultDescription = 'Listens the queue and executes messages as they come. Needs to be stopped manually.'; - private QueueFactoryInterface $queueFactory; - - public function __construct(QueueFactoryInterface $queueFactory) + public function __construct(private QueueFactoryInterface $queueFactory) { parent::__construct(); - $this->queueFactory = $queueFactory; } public function configure(): void diff --git a/src/Command/RunCommand.php b/src/Command/RunCommand.php index c1c4638f..624700ea 100644 --- a/src/Command/RunCommand.php +++ b/src/Command/RunCommand.php @@ -17,12 +17,9 @@ final class RunCommand extends Command protected static $defaultName = 'queue:run'; protected static $defaultDescription = 'Runs all the existing messages in the queue. Exits once messages are over.'; - private QueueFactoryInterface $queueFactory; - - public function __construct(QueueFactoryInterface $queueFactory) + public function __construct(private QueueFactoryInterface $queueFactory) { parent::__construct(); - $this->queueFactory = $queueFactory; } public function configure(): void diff --git a/src/Exception/AdapterConfiguration/ChannelIncorrectlyConfigured.php b/src/Exception/AdapterConfiguration/ChannelIncorrectlyConfigured.php index 286f8aee..53a8e09b 100644 --- a/src/Exception/AdapterConfiguration/ChannelIncorrectlyConfigured.php +++ b/src/Exception/AdapterConfiguration/ChannelIncorrectlyConfigured.php @@ -17,9 +17,7 @@ class ChannelIncorrectlyConfigured extends InvalidArgumentException implements F /** * ChannelIncorrectlyConfigured constructor. * - * @param string $channel * @param mixed|object $definition - * @param int $code * @param Throwable|null $previous */ public function __construct(string $channel, $definition, int $code = 0, ?Throwable $previous = null) diff --git a/src/Exception/InvalidStatusException.php b/src/Exception/InvalidStatusException.php index f0606c1c..a4ade6c8 100644 --- a/src/Exception/InvalidStatusException.php +++ b/src/Exception/InvalidStatusException.php @@ -40,8 +40,6 @@ public function getSolution(): ?string /** * Get the wrong status value - * - * @return int */ public function getStatus(): int { diff --git a/src/Exception/JobFailureException.php b/src/Exception/JobFailureException.php index ff114646..ea88ab98 100644 --- a/src/Exception/JobFailureException.php +++ b/src/Exception/JobFailureException.php @@ -10,14 +10,10 @@ class JobFailureException extends RuntimeException { - private MessageInterface $queueMessage; - - public function __construct(MessageInterface $message, Throwable $previous) + public function __construct(private MessageInterface $queueMessage, Throwable $previous) { - $this->queueMessage = $message; - $error = $previous->getMessage(); - $messageId = $message->getId() ?? 'null'; + $messageId = $queueMessage->getId() ?? 'null'; $messageText = "Processing of message #$messageId is stopped because of an exception:\n$error."; parent::__construct($messageText, 0, $previous); diff --git a/src/Message/Message.php b/src/Message/Message.php index 8add1a00..5e1fd2a7 100644 --- a/src/Message/Message.php +++ b/src/Message/Message.php @@ -7,7 +7,6 @@ final class Message implements MessageInterface { /** - * @param string $handlerName * @param mixed $data Message data, encodable by a queue adapter * @param array $metadata Message metadata, encodable by a queue adapter * @param string|null $id Message id diff --git a/src/Middleware/CallableFactory.php b/src/Middleware/CallableFactory.php index 4249d60b..0e535a38 100644 --- a/src/Middleware/CallableFactory.php +++ b/src/Middleware/CallableFactory.php @@ -19,11 +19,8 @@ */ final class CallableFactory { - private ContainerInterface $container; - - public function __construct(ContainerInterface $container) + public function __construct(private ContainerInterface $container) { - $this->container = $container; } /** @@ -64,13 +61,8 @@ public function create(mixed $definition): callable } /** - * @param string $className - * @param string $methodName - * * @throws ContainerExceptionInterface Error while retrieving the entry from container. * @throws NotFoundExceptionInterface - * - * @return callable|null */ private function fromDefinition(string $className, string $methodName): ?callable { diff --git a/src/Middleware/Consume/ConsumeRequest.php b/src/Middleware/Consume/ConsumeRequest.php index b5b913de..452c3b50 100644 --- a/src/Middleware/Consume/ConsumeRequest.php +++ b/src/Middleware/Consume/ConsumeRequest.php @@ -13,9 +13,6 @@ public function __construct(private MessageInterface $message, private QueueInte { } - /** - * @return MessageInterface - */ public function getMessage(): MessageInterface { return $this->message; diff --git a/src/Middleware/Consume/MiddlewareFactoryConsume.php b/src/Middleware/Consume/MiddlewareFactoryConsume.php index bd37b2f2..d88cc2da 100644 --- a/src/Middleware/Consume/MiddlewareFactoryConsume.php +++ b/src/Middleware/Consume/MiddlewareFactoryConsume.php @@ -87,13 +87,11 @@ private function getFromContainer(string $middlewareDefinition): MiddlewareConsu private function wrapCallable(callable $callback): MiddlewareConsumeInterface { return new class ($callback, $this->container) implements MiddlewareConsumeInterface { - private ContainerInterface $container; private $callback; - public function __construct(callable $callback, ContainerInterface $container) + public function __construct(callable $callback, private ContainerInterface $container) { $this->callback = $callback; - $this->container = $container; } public function processConsume(ConsumeRequest $request, MessageHandlerConsumeInterface $handler): ConsumeRequest diff --git a/src/Middleware/FailureHandling/FailureMiddlewareDispatcher.php b/src/Middleware/FailureHandling/FailureMiddlewareDispatcher.php index ad496d8d..e60fe6e9 100644 --- a/src/Middleware/FailureHandling/FailureMiddlewareDispatcher.php +++ b/src/Middleware/FailureHandling/FailureMiddlewareDispatcher.php @@ -18,7 +18,6 @@ final class FailureMiddlewareDispatcher private array $stack = []; /** - * @param MiddlewareFactoryFailureInterface $middlewareFactory * @param array[][]|callable[][]|MiddlewareFailureInterface[][]|string[][] $middlewareDefinitions */ public function __construct( diff --git a/src/Middleware/FailureHandling/Implementation/ExponentialDelayMiddleware.php b/src/Middleware/FailureHandling/Implementation/ExponentialDelayMiddleware.php index e3e6a087..23d454b5 100644 --- a/src/Middleware/FailureHandling/Implementation/ExponentialDelayMiddleware.php +++ b/src/Middleware/FailureHandling/Implementation/ExponentialDelayMiddleware.php @@ -28,7 +28,6 @@ final class ExponentialDelayMiddleware implements MiddlewareFailureInterface * @param float $delayInitial The first delay period * @param float $delayMaximum The maximum delay period * @param float $exponent Message handling delay will be increased by this multiplication each time it fails - * @param DelayMiddlewareInterface $delayMiddleware * @param QueueInterface|null $queue */ public function __construct( diff --git a/src/Middleware/FailureHandling/MiddlewareFactoryFailure.php b/src/Middleware/FailureHandling/MiddlewareFactoryFailure.php index e4736721..b8957d9b 100644 --- a/src/Middleware/FailureHandling/MiddlewareFactoryFailure.php +++ b/src/Middleware/FailureHandling/MiddlewareFactoryFailure.php @@ -90,13 +90,11 @@ private function getFromContainer(string $middlewareDefinition): MiddlewareFailu private function wrapCallable(callable $callback): MiddlewareFailureInterface { return new class ($callback, $this->container) implements MiddlewareFailureInterface { - private ContainerInterface $container; private $callback; - public function __construct(callable $callback, ContainerInterface $container) + public function __construct(callable $callback, private ContainerInterface $container) { $this->callback = $callback; - $this->container = $container; } public function processFailure(FailureHandlingRequest $request, MessageFailureHandlerInterface $handler): FailureHandlingRequest diff --git a/src/Middleware/InvalidMiddlewareDefinitionException.php b/src/Middleware/InvalidMiddlewareDefinitionException.php index 882c3724..1f25353d 100644 --- a/src/Middleware/InvalidMiddlewareDefinitionException.php +++ b/src/Middleware/InvalidMiddlewareDefinitionException.php @@ -8,7 +8,6 @@ use Throwable; -use function get_class; use function is_array; use function is_object; use function is_string; @@ -31,14 +30,12 @@ public function __construct($middlewareDefinition, int $code = 0, ?Throwable $pr } /** - * @param mixed $middlewareDefinition - * * @return string|null */ private function convertDefinitionToString(mixed $middlewareDefinition): ?string { if (is_object($middlewareDefinition)) { - return 'an instance of "' . get_class($middlewareDefinition) . '"'; + return 'an instance of "' . $middlewareDefinition::class . '"'; } if (is_string($middlewareDefinition)) { diff --git a/src/Middleware/Push/MiddlewareFactoryPush.php b/src/Middleware/Push/MiddlewareFactoryPush.php index f31a231a..4f8c6e0a 100644 --- a/src/Middleware/Push/MiddlewareFactoryPush.php +++ b/src/Middleware/Push/MiddlewareFactoryPush.php @@ -87,13 +87,11 @@ private function getFromContainer(string $middlewareDefinition): MiddlewarePushI private function wrapCallable(callable $callback): MiddlewarePushInterface { return new class ($callback, $this->container) implements MiddlewarePushInterface { - private ContainerInterface $container; private $callback; - public function __construct(callable $callback, ContainerInterface $container) + public function __construct(callable $callback, private ContainerInterface $container) { $this->callback = $callback; - $this->container = $container; } public function processPush(PushRequest $request, MessageHandlerPushInterface $handler): PushRequest diff --git a/src/Middleware/Push/PushRequest.php b/src/Middleware/Push/PushRequest.php index 14e9da78..6612ece8 100644 --- a/src/Middleware/Push/PushRequest.php +++ b/src/Middleware/Push/PushRequest.php @@ -13,9 +13,6 @@ public function __construct(private MessageInterface $message, private ?AdapterI { } - /** - * @return MessageInterface - */ public function getMessage(): MessageInterface { return $this->message; diff --git a/src/QueueFactory.php b/src/QueueFactory.php index e92ea7ae..31a4c361 100644 --- a/src/QueueFactory.php +++ b/src/QueueFactory.php @@ -29,9 +29,6 @@ final class QueueFactory implements QueueFactoryInterface * "Definition" here is a {@see Factory} definition * @param QueueInterface $queue A default queue implementation. `$queue->withAdapter()` will be returned * with the `get` method - * @param ContainerInterface $container - * @param CallableFactory $callableFactory - * @param Injector $injector * @param bool $enableRuntimeChannelDefinition A flag whether to enable a such behavior when there is no * explicit channel adapter definition: `return $this->queue->withAdapter($this->adapter->withChannel($channel)` * When this flag is set to false, only explicit definitions from the $definition parameter are used. @@ -71,10 +68,7 @@ public function get(string $channel = self::DEFAULT_CHANNEL_NAME): QueueInterfac } /** - * @param string $channel - * * @throws ChannelIncorrectlyConfigured - * * @return QueueInterface */ private function create(string $channel): QueueInterface diff --git a/src/Worker/Worker.php b/src/Worker/Worker.php index 9b142ba3..18103a87 100644 --- a/src/Worker/Worker.php +++ b/src/Worker/Worker.php @@ -41,12 +41,7 @@ public function __construct( } /** - * @param MessageInterface $message - * @param QueueInterface $queue - * * @throws Throwable - * - * @return MessageInterface */ public function process(MessageInterface $message, QueueInterface $queue): MessageInterface { @@ -94,8 +89,6 @@ private function getHandler(string $name): ?callable * * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface - * - * @return callable|null */ private function prepare(callable|object|array|string|null $definition): callable|null { diff --git a/tests/Unit/JobStatusTest.php b/tests/Unit/JobStatusTest.php index 330d5993..20c03c00 100644 --- a/tests/Unit/JobStatusTest.php +++ b/tests/Unit/JobStatusTest.php @@ -43,10 +43,6 @@ public function getStatusPairs(): array /** * @dataProvider getStatusPairs - * - * @param string $statusName - * @param string $positiveMethod - * @param array $negatives */ public function testInstanceValue(string $statusName, string $positiveMethod, array $negatives): void { diff --git a/tests/Unit/Middleware/Consume/InvalidMiddlewareDefinitionExceptionTest.php b/tests/Unit/Middleware/Consume/InvalidMiddlewareDefinitionExceptionTest.php index ad8389dc..b173b389 100644 --- a/tests/Unit/Middleware/Consume/InvalidMiddlewareDefinitionExceptionTest.php +++ b/tests/Unit/Middleware/Consume/InvalidMiddlewareDefinitionExceptionTest.php @@ -35,9 +35,6 @@ public function dataBase(): array /** * @dataProvider dataBase - * - * @param mixed $definition - * @param string $expected */ public function testBase(mixed $definition, string $expected): void { @@ -55,8 +52,6 @@ public function dataUnknownDefinition(): array /** * @dataProvider dataUnknownDefinition - * - * @param mixed $definition */ public function testUnknownDefinition(mixed $definition): void { diff --git a/tests/Unit/Middleware/Consume/MiddlewareDispatcherTest.php b/tests/Unit/Middleware/Consume/MiddlewareDispatcherTest.php index 7ce71d23..c67c2c09 100644 --- a/tests/Unit/Middleware/Consume/MiddlewareDispatcherTest.php +++ b/tests/Unit/Middleware/Consume/MiddlewareDispatcherTest.php @@ -162,7 +162,7 @@ public function handleConsume(ConsumeRequest $request): ConsumeRequest private function createDispatcher( ContainerInterface $container = null, ): ConsumeMiddlewareDispatcher { - $container = $container ?? $this->createContainer([AdapterInterface::class => new FakeAdapter()]); + $container ??= $this->createContainer([AdapterInterface::class => new FakeAdapter()]); $callableFactory = new CallableFactory($container); return new ConsumeMiddlewareDispatcher( diff --git a/tests/Unit/Middleware/Consume/MiddlewareFactoryTest.php b/tests/Unit/Middleware/Consume/MiddlewareFactoryTest.php index 0985736f..e1f790f4 100644 --- a/tests/Unit/Middleware/Consume/MiddlewareFactoryTest.php +++ b/tests/Unit/Middleware/Consume/MiddlewareFactoryTest.php @@ -57,12 +57,10 @@ public function testCreateFromClosureResponse(): void { $container = $this->getContainer([TestCallableMiddleware::class => new TestCallableMiddleware()]); $middleware = $this->getMiddlewareFactory($container)->createConsumeMiddleware( - function (): ConsumeRequest { - return new ConsumeRequest( - new Message('test', 'test data'), - $this->createMock(QueueInterface::class), - ); - } + fn (): ConsumeRequest => new ConsumeRequest( + new Message('test', 'test data'), + $this->createMock(QueueInterface::class), + ) ); self::assertSame( 'test data', @@ -77,9 +75,7 @@ public function testCreateFromClosureMiddleware(): void { $container = $this->getContainer([TestCallableMiddleware::class => new TestCallableMiddleware()]); $middleware = $this->getMiddlewareFactory($container)->createConsumeMiddleware( - static function (): MiddlewareConsumeInterface { - return new TestMiddleware(); - } + static fn (): MiddlewareConsumeInterface => new TestMiddleware() ); self::assertSame( 'New middleware test data', @@ -125,9 +121,7 @@ public function testInvalidMiddlewareWithWrongCallable(): void { $container = $this->getContainer([TestCallableMiddleware::class => new TestCallableMiddleware()]); $middleware = $this->getMiddlewareFactory($container)->createConsumeMiddleware( - static function () { - return 42; - } + static fn () => 42 ); $this->expectException(InvalidMiddlewareDefinitionException::class); @@ -176,7 +170,7 @@ public function testInvalidMiddlewareWithWrongController(): void private function getMiddlewareFactory(ContainerInterface $container = null): MiddlewareFactoryConsumeInterface { - $container = $container ?? $this->getContainer([AdapterInterface::class => new FakeAdapter()]); + $container ??= $this->getContainer([AdapterInterface::class => new FakeAdapter()]); return new MiddlewareFactoryConsume($container, new CallableFactory($container)); } diff --git a/tests/Unit/Middleware/FailureHandling/InvalidMiddlewareDefinitionExceptionTest.php b/tests/Unit/Middleware/FailureHandling/InvalidMiddlewareDefinitionExceptionTest.php index 57c5482f..beb4f25d 100644 --- a/tests/Unit/Middleware/FailureHandling/InvalidMiddlewareDefinitionExceptionTest.php +++ b/tests/Unit/Middleware/FailureHandling/InvalidMiddlewareDefinitionExceptionTest.php @@ -35,9 +35,6 @@ public function dataBase(): array /** * @dataProvider dataBase - * - * @param mixed $definition - * @param string $expected */ public function testBase(mixed $definition, string $expected): void { @@ -55,8 +52,6 @@ public function dataUnknownDefinition(): array /** * @dataProvider dataUnknownDefinition - * - * @param mixed $definition */ public function testUnknownDefinition(mixed $definition): void { diff --git a/tests/Unit/Middleware/FailureHandling/MiddlewareDispatcherTest.php b/tests/Unit/Middleware/FailureHandling/MiddlewareDispatcherTest.php index 53f5c016..9d536a4a 100644 --- a/tests/Unit/Middleware/FailureHandling/MiddlewareDispatcherTest.php +++ b/tests/Unit/Middleware/FailureHandling/MiddlewareDispatcherTest.php @@ -159,7 +159,7 @@ public function handleFailure(FailureHandlingRequest $request): FailureHandlingR private function createDispatcher( ContainerInterface $container = null, ): FailureMiddlewareDispatcher { - $container = $container ?? $this->createContainer([AdapterInterface::class => new FakeAdapter()]); + $container ??= $this->createContainer([AdapterInterface::class => new FakeAdapter()]); $callableFactory = new CallableFactory($container); return new FailureMiddlewareDispatcher(new MiddlewareFactoryFailure($container, $callableFactory), []); diff --git a/tests/Unit/Middleware/FailureHandling/MiddlewareFactoryTest.php b/tests/Unit/Middleware/FailureHandling/MiddlewareFactoryTest.php index 8d04bbc5..86136664 100644 --- a/tests/Unit/Middleware/FailureHandling/MiddlewareFactoryTest.php +++ b/tests/Unit/Middleware/FailureHandling/MiddlewareFactoryTest.php @@ -154,7 +154,7 @@ public function testInvalidMiddlewareWithWrongController(): void private function getMiddlewareFactory(ContainerInterface $container = null): MiddlewareFactoryFailureInterface { - $container = $container ?? $this->getContainer([AdapterInterface::class => new FakeAdapter()]); + $container ??= $this->getContainer([AdapterInterface::class => new FakeAdapter()]); return new MiddlewareFactoryFailure($container, new CallableFactory($container)); } diff --git a/tests/Unit/Middleware/Push/InvalidMiddlewareDefinitionExceptionTest.php b/tests/Unit/Middleware/Push/InvalidMiddlewareDefinitionExceptionTest.php index 7a228186..7b7db2e1 100644 --- a/tests/Unit/Middleware/Push/InvalidMiddlewareDefinitionExceptionTest.php +++ b/tests/Unit/Middleware/Push/InvalidMiddlewareDefinitionExceptionTest.php @@ -35,9 +35,6 @@ public function dataBase(): array /** * @dataProvider dataBase - * - * @param mixed $definition - * @param string $expected */ public function testBase(mixed $definition, string $expected): void { @@ -55,8 +52,6 @@ public function dataUnknownDefinition(): array /** * @dataProvider dataUnknownDefinition - * - * @param mixed $definition */ public function testUnknownDefinition(mixed $definition): void { diff --git a/tests/Unit/Middleware/Push/MiddlewareDispatcherTest.php b/tests/Unit/Middleware/Push/MiddlewareDispatcherTest.php index 02bb0f1f..159c9365 100644 --- a/tests/Unit/Middleware/Push/MiddlewareDispatcherTest.php +++ b/tests/Unit/Middleware/Push/MiddlewareDispatcherTest.php @@ -26,11 +26,9 @@ public function testCallableMiddlewareCalled(): void $dispatcher = $this->createDispatcher()->withMiddlewares( [ - static function (PushRequest $request, AdapterInterface $adapter): PushRequest { - return $request - ->withMessage(new Message('test', 'New closure test data')) - ->withAdapter($adapter->withChannel('closure-channel')); - }, + static fn (PushRequest $request, AdapterInterface $adapter): PushRequest => $request + ->withMessage(new Message('test', 'New closure test data')) + ->withAdapter($adapter->withChannel('closure-channel')), ] ); @@ -104,12 +102,8 @@ public function testMiddlewareStackInterrupted(): void { $request = $this->getPushRequest(); - $middleware1 = static function (PushRequest $request, MessageHandlerPushInterface $handler): PushRequest { - return $request->withMessage(new Message($request->getMessage()->getHandlerName(), 'first')); - }; - $middleware2 = static function (PushRequest $request, MessageHandlerPushInterface $handler): PushRequest { - return $request->withMessage(new Message($request->getMessage()->getHandlerName(), 'second')); - }; + $middleware1 = static fn (PushRequest $request, MessageHandlerPushInterface $handler): PushRequest => $request->withMessage(new Message($request->getMessage()->getHandlerName(), 'first')); + $middleware2 = static fn (PushRequest $request, MessageHandlerPushInterface $handler): PushRequest => $request->withMessage(new Message($request->getMessage()->getHandlerName(), 'second')); $dispatcher = $this->createDispatcher()->withMiddlewares([$middleware1, $middleware2]); @@ -176,7 +170,7 @@ public function handlePush(PushRequest $request): PushRequest private function createDispatcher( ContainerInterface $container = null, ): PushMiddlewareDispatcher { - $container = $container ?? $this->createContainer([AdapterInterface::class => new FakeAdapter()]); + $container ??= $this->createContainer([AdapterInterface::class => new FakeAdapter()]); $callableFactory = new CallableFactory($container); return new PushMiddlewareDispatcher( diff --git a/tests/Unit/Middleware/Push/MiddlewareFactoryTest.php b/tests/Unit/Middleware/Push/MiddlewareFactoryTest.php index fe37d99f..b68437fb 100644 --- a/tests/Unit/Middleware/Push/MiddlewareFactoryTest.php +++ b/tests/Unit/Middleware/Push/MiddlewareFactoryTest.php @@ -145,7 +145,7 @@ public function testInvalidMiddlewareWithWrongController(): void private function getMiddlewareFactory(ContainerInterface $container = null): MiddlewareFactoryPushInterface { - $container = $container ?? $this->getContainer([AdapterInterface::class => new FakeAdapter()]); + $container ??= $this->getContainer([AdapterInterface::class => new FakeAdapter()]); return new MiddlewareFactoryPush($container, new CallableFactory($container)); }