diff --git a/README.md b/README.md index 4914175e..8745eb2b 100644 --- a/README.md +++ b/README.md @@ -43,14 +43,15 @@ change to start working with the queue: ## Differences to yii2-queue If you have experience with `yiisoft/yii2-queue`, you will find out that this package is similar. -Though, there are some key differences which are described in the "[migrating from yii2-queue](docs/guide/migrating-from-yii2-queue.md)" article. +Though, there are some key differences that are described in the "[migrating from yii2-queue](docs/guide/migrating-from-yii2-queue.md)" +article. ## General usage Each queue task consists of two parts: 1. A message is a class implementing `MessageInterface`. For simple cases you can use the default implementation, - `Yiisoft\Queue\Message\Message`. For more complex cases you should implement the interface by your own. + `Yiisoft\Queue\Message\Message`. For more complex cases, you should implement the interface by your own. 2. A message handler is a callable called by a `Yiisoft\Queue\Worker\Worker`. The handler handles each queue message. For example, if you need to download and save a file, your message creation may look like the following: @@ -103,7 +104,7 @@ $worker = new \Yiisoft\Queue\Worker\Worker( ); ``` -There is the way to run all the messages that are already in the queue, and then exit: +There is a way to run all the messages that are already in the queue, and then exit: ```php $queue->run(); // this will execute all the existing messages @@ -147,7 +148,7 @@ To use a custom handler name before message push, you can pass it as the first a new Message('handler-name', $data); ``` -To use a custom handler name on message consume, you should configure handler mapping for the `Worker` class: +To use a custom handler name on message consumption, you should configure handler mapping for the `Worker` class: ```php $worker = new \Yiisoft\Queue\Worker\Worker( ['handler-name' => FooHandler::class], @@ -175,7 +176,7 @@ Out of the box, there are four implementations of the `QueueProviderInterface`: ### `AdapterFactoryQueueProvider` -Provider based on definition of channel-specific adapters. Definitions are passed in +Provider based on the definition of channel-specific adapters. Definitions are passed in the `$definitions` constructor parameter of the factory, where keys are channel names and values are definitions for the [`Yiisoft\Factory\Factory`](https://github.com/yiisoft/factory). Below are some examples: @@ -192,7 +193,7 @@ use Yiisoft\Queue\Adapter\SynchronousAdapter; ] ``` -For more information about a definition formats available see the [factory](https://github.com/yiisoft/factory) documentation. +For more information about the definition formats available, see the [factory](https://github.com/yiisoft/factory) documentation. ### `PrototypeQueueProvider` @@ -226,14 +227,14 @@ yii queue:listen See the documentation for more details about adapter specific console commands and their options. -The component also has the ability to track the status of a job which was pushed into queue. +The component can also track the status of a job which was pushed into queue. -For more details see [the guide](docs/guide/en/README.md). +For more details, see [the guide](docs/guide/en/README.md). ## Middleware pipelines Any message pushed to a queue or consumed from it passes through two different middleware pipelines: one pipeline -on message push and another - on message consume. The process is the same as for the HTTP request, but it is executed +on message push and another - on a message consume. The process is the same as for the HTTP request, but it is executed twice for a queue message. That means you can add extra functionality on message pushing and consuming with configuration of the two classes: `PushMiddlewareDispatcher` and `ConsumeMiddlewareDispatcher` respectively. @@ -262,13 +263,13 @@ graph LR ConsumeMiddleware1[$middleware1] -.-> EndConsume((End)) ``` -### Push pipeline +### Push a pipeline When you push a message, you can use middlewares to modify both message and queue adapter. With message modification you can add extra data, obfuscate data, collect metrics, etc. -With queue adapter modification you can redirect message to another queue, delay message consuming, and so on. +With queue adapter modification you can redirect the message to another queue, delay message consuming, and so on. -To use this feature you have to create a middleware class, which implements `MiddlewarePushInterface`, and +To use this feature, you have to create a middleware class, which implements `MiddlewarePushInterface`, and return a modified `PushRequest` object from the `processPush` method: ```php @@ -297,16 +298,16 @@ along with them. ### Consume pipeline -You can set a middleware pipeline for a message when it will be consumed from a queue server. This is useful to collect metrics, modify message data, etc. In pair with a Push middleware you can deduplicate messages in the queue, calculate time from push to consume, handle errors (push to a queue again, redirect failed message to another queue, send a notification, etc.). Unless Push pipeline, you have only one place to define the middleware stack: in the `ConsumeMiddlewareDispatcher`, either in the constructor, or in the `withMiddlewares()` method. If you use [yiisoft/config](yiisoft/config), you can add middleware to the `middlewares-consume` key of the `yiisoft/queue` array in the `params`. +You can set a middleware pipeline for a message when it will be consumed from a queue server. This is useful to collect metrics, modify message data, etc. In a pair with a Push middleware you can deduplicate messages in the queue, calculate time from push to consume, handle errors (push to a queue again, redirect failed message to another queue, send a notification, etc.). Except push pipeline, you have only one place to define the middleware stack: in the `ConsumeMiddlewareDispatcher`, either in the constructor, or in the `withMiddlewares()` method. If you use [yiisoft/config](yiisoft/config), you can add middleware to the `middlewares-consume` key of the `yiisoft/queue` array in the `params`. ### Error handling pipeline -Often when some job is failing, we want to retry its execution a couple more times or redirect it to another queue channel. This can be done in `yiisoft/queue` with Failure middleware pipeline. They are triggered each time message processing via the Consume middleware pipeline is interrupted with any `Throwable`. The key differences from the previous two pipelines: +Often when some job is failing, we want to retry its execution a couple more times or redirect it to another queue channel. This can be done in `yiisoft/queue` with a Failure middleware pipeline. They are triggered each time message processing via the Consume middleware pipeline is interrupted with any `Throwable`. The key differences from the previous two pipelines: - You should set up the middleware pipeline separately for each queue channel. That means, the format should be `['channel-name' => [FooMiddleware::class]]` instead of `[FooMiddleware::class]`, like for the other two pipelines. There is also a default key, which will be used for those channels without their own one: `FailureMiddlewareDispatcher::DEFAULT_PIPELINE`. - The last middleware will throw the exception, which will come with the `FailureHandlingRequest` object. If you don't want the exception to be thrown, your middlewares should `return` a request without calling `$handler->handleFailure()`. -You can declare error handling middleware pipeline in the `FailureMiddlewareDispatcher`, either in the constructor, or in the `withMiddlewares()` method. If you use [yiisoft/config](yiisoft/config), you can add middleware to the `middlewares-fail` key of the `yiisoft/queue` array in the `params`. +You can declare error handling a middleware pipeline in the `FailureMiddlewareDispatcher`, either in the constructor, or in the `withMiddlewares()` method. If you use [yiisoft/config](yiisoft/config), you can add middleware to the `middlewares-fail` key of the `yiisoft/queue` array in the `params`. See [error handling docs](docs/guide/error-handling.md) for details. diff --git a/docs/guide/en/error-handling.md b/docs/guide/en/error-handling.md index 14db9054..2a17c11a 100644 --- a/docs/guide/en/error-handling.md +++ b/docs/guide/en/error-handling.md @@ -4,7 +4,7 @@ Often when some message handling is failing, we want to retry its execution a co ## Configuration -Here below is configuration via `yiisoft/config`. If you don't use it - you should add middleware definition list (in the `middlewares-fail` key here) to the `FailureMiddlewareDispatcher` by your own. +Here below is configuration via `yiisoft/config`. If you don't use it, you should add a middleware definition list (in the `middlewares-fail` key here) to the `FailureMiddlewareDispatcher` by your own. Configuration should be passed to the `yiisoft/queue.fail-strategy-pipelines` key of the `params` config to work with the `yiisoft/config`. You can define different failure handling pipelines for each queue channel. Let's see and describe an example: @@ -39,10 +39,10 @@ Configuration should be passed to the `yiisoft/queue.fail-strategy-pipelines` ke ] ``` -Keys here except `FailureMiddlewareDispatcher::DEFAULT_PIPELINE` are queue channel names, and values are lists of `FailureMiddlewareInterface` definitions. `FailureMiddlewareDispatcher::DEFAULT_PIPELINE` defines a default pipeline to apply to channels without explicitly defined failure strategy pipeline. Each middleware definition must be one of: +Keys here except `FailureMiddlewareDispatcher::DEFAULT_PIPELINE` are queue channel names, and values are lists of `FailureMiddlewareInterface` definitions. `FailureMiddlewareDispatcher::DEFAULT_PIPELINE` defines a default pipeline to apply to channels without an explicitly defined failure strategy pipeline. Each middleware definition must be one of: - A ready-to-use `MiddlewareFailureInterface` object like `new FooMiddleware()`. - A valid definition for the [yiisoft/definitions](https://github.com/yiisoft/definitions). It must describe an object, implementing the `MiddlewareFailureInterface`. -- A callable: `fn() => // do stuff`, `$object->foo(...)`, etc. It will be executed through the `yiisoft/injector`, so all the dependencies of your callable will be resolved. You can also define a "callable-looking" array, where object will be instantiated with a DI container: `[FooMiddleware::class, 'handle']`. +- A callable: `fn() => // do stuff`, `$object->foo(...)`, etc. It will be executed through the `yiisoft/injector`, so all the dependencies of your callable will be resolved. You can also define a "callable-looking" array, where an object will be instantiated with a DI container: `[FooMiddleware::class, 'handle']`. - A string for your DI container to resolve the middleware, e.g. `FooMiddleware::class`. In the example above failures will be handled this way (look the concrete middleware description below): diff --git a/docs/guide/en/migrating-from-yii2-queue.md b/docs/guide/en/migrating-from-yii2-queue.md index 6a74e329..fa6bfad7 100644 --- a/docs/guide/en/migrating-from-yii2-queue.md +++ b/docs/guide/en/migrating-from-yii2-queue.md @@ -1,11 +1,11 @@ # Migrating from yii2-queue -This package is similar to [yiisoft/yii2-queue] but with improved design and code style. The new package less coupled +This package is similar to [yiisoft/yii2-queue] but with improved design and code style. The new package is less coupled and more structured than the old one allowing better maintenance. ## Adapters -- Individual adapters are now separate packages. This means each adapter must be `require`d with composer in order to +- Individual adapters are now separate packages. This means each adapter must be `require`d with composer to be available in your application. - Adapter may be any class which implements `AdapterInterface`. This means you can replace one adapter with another without changing any code in your app. For example, you can use `db` adapter in development while using `amqp` in production, @@ -15,11 +15,11 @@ and more structured than the old one allowing better maintenance. ## Jobs (Messages and Handlers) There was a concept in [yiisoft/yii2-queue] called `Job`: you had to push it to the queue, and it was executed after -being consumed. In the new package it is divided into two different concepts: a message and a handler. +being consumed. In the new package, it is divided into two different concepts: a message and a handler. -- A `Message` is a class implementing `MessageInterface`. It contains 2 types of data: - - Name. Worker uses it to find the right handler for a message. - - Data. Any serializable data which should be used by the message handler. +- A `Message` is a class implementing `MessageInterface`. It contains two types of data: + - Name. The worker uses it to find the right handler for a message. + - Data. Any serializable data that should be used by the message handler. All the message data is fully serializable (that means message `data` must be serializable too). It allows you to freely choose where and how to send and process jobs. Both can be implemented in a single application, or diff --git a/docs/guide/en/usage.md b/docs/guide/en/usage.md index 8ab99215..9a663a88 100644 --- a/docs/guide/en/usage.md +++ b/docs/guide/en/usage.md @@ -26,7 +26,7 @@ See also the documentation for concrete adapters ([synchronous adapter](adapter- ## Usage Each job sent to the queue should be defined as a separate class. -For example, if you need to download and save a file the class may look like the following: +For example, if you need to download and save a file, the class may look like the following: ```php $data = [ @@ -54,7 +54,7 @@ To push a job into the queue that should run after 5 minutes: ## Queue handling The exact way how a job is executed depends on the adapter used. Most adapters can be run using -console commands, which the component registers in your application. For more details check the respective +console commands, which the component registers in your application. For more details, check the respective adapter documentation. @@ -79,7 +79,7 @@ $status->isDone($id); ## Limitations -When using queues it is important to remember that tasks are put into and obtained from the queue in separate +When using queues, it is important to remember that tasks are put into and obtained from the queue in separate processes. Therefore, avoid external dependencies when executing a task if you're not sure if they are available in the environment where the worker does its job. diff --git a/docs/guide/en/worker.md b/docs/guide/en/worker.md index ca9c951a..7ac12ea1 100644 --- a/docs/guide/en/worker.md +++ b/docs/guide/en/worker.md @@ -1,7 +1,7 @@ # Configuration -To use a worker, you should resolve its dependencies (e.g. through DI container) and define handlers for each message -which will be consumed by this worker; +To use a worker, you should resolve its dependencies (e.g., through DI container) and define handlers for each message +that will be consumed by this worker; Handlers are callables indexed by payload names. When a message is consumed from the queue, a callable associated with its payload name is called. @@ -10,7 +10,7 @@ its payload name is called. Handler can be any callable with a couple of additions: -- If handler is provided as an array of two strings, it will be treated as a DI container service id and its method. +- If a handler is provided as an array of two strings, it will be treated as a DI container service id and its method. E.g. `[ClassName::class, 'handle']` will be resolved to: ```php $container @@ -69,7 +69,7 @@ stdout_logfile=/var/www/my_project/log/yii-queue-worker.log In this case Supervisor should start 4 `queue:listen` workers. The worker output will be written to the specified log file. -For more info about Supervisor's configuration and usage see its [documentation](http://supervisord.org). +For more info about Supervisor's configuration and usage, see its [documentation](http://supervisord.org). ### Systemd @@ -96,7 +96,7 @@ Restart=on-failure WantedBy=multi-user.target ``` -You need to reload systemd in order to re-read its configuration: +You need to reload systemd to re-read its configuration: ```shell systemctl daemon-reload @@ -133,4 +133,4 @@ Config example: * * * * * /usr/bin/php /var/www/my_project/yii queue:run ``` -In this case cron will run the command every minute. +In this case, cron will run the command every minute. diff --git a/src/Adapter/SynchronousAdapter.php b/src/Adapter/SynchronousAdapter.php index f815264a..26789295 100644 --- a/src/Adapter/SynchronousAdapter.php +++ b/src/Adapter/SynchronousAdapter.php @@ -20,8 +20,8 @@ final class SynchronousAdapter implements AdapterInterface private string $channel; public function __construct( - private WorkerInterface $worker, - private QueueInterface $queue, + private readonly WorkerInterface $worker, + private readonly QueueInterface $queue, string|BackedEnum $channel = QueueInterface::DEFAULT_CHANNEL, ) { $this->channel = ChannelNormalizer::normalize($channel); diff --git a/src/Cli/SignalLoop.php b/src/Cli/SignalLoop.php index 1f1be127..2043a597 100644 --- a/src/Cli/SignalLoop.php +++ b/src/Cli/SignalLoop.php @@ -28,7 +28,7 @@ final 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. + * soft limit is reached. Zero means no limit. */ public function __construct(protected int $memorySoftLimit = 0) { @@ -61,7 +61,7 @@ protected function dispatchSignals(): bool { pcntl_signal_dispatch(); - // Wait for resume signal until loop is suspended + // Wait for resume signal until the loop is suspended while ($this->pause && !$this->exit) { usleep(10000); pcntl_signal_dispatch(); diff --git a/src/Debug/QueueCollector.php b/src/Debug/QueueCollector.php index 3d83e593..acf88cfb 100644 --- a/src/Debug/QueueCollector.php +++ b/src/Debug/QueueCollector.php @@ -83,9 +83,9 @@ public function getSummary(): array return []; } - $countPushes = array_sum(array_map(fn ($messages) => is_countable($messages) ? count($messages) : 0, $this->pushes)); + $countPushes = array_sum(array_map(static fn ($messages) => is_countable($messages) ? count($messages) : 0, $this->pushes)); $countStatuses = count($this->statuses); - $countProcessingMessages = array_sum(array_map(fn ($messages) => is_countable($messages) ? count($messages) : 0, $this->processingMessages)); + $countProcessingMessages = array_sum(array_map(static fn ($messages) => is_countable($messages) ? count($messages) : 0, $this->processingMessages)); return [ 'countPushes' => $countPushes, diff --git a/src/Debug/QueueDecorator.php b/src/Debug/QueueDecorator.php index 8da8fb17..adc8e6b1 100644 --- a/src/Debug/QueueDecorator.php +++ b/src/Debug/QueueDecorator.php @@ -13,8 +13,8 @@ final class QueueDecorator implements QueueInterface { public function __construct( - private QueueInterface $queue, - private QueueCollector $collector, + private readonly QueueInterface $queue, + private readonly QueueCollector $collector, ) { } diff --git a/src/Debug/QueueWorkerInterfaceProxy.php b/src/Debug/QueueWorkerInterfaceProxy.php index 11f82201..574ba2cd 100644 --- a/src/Debug/QueueWorkerInterfaceProxy.php +++ b/src/Debug/QueueWorkerInterfaceProxy.php @@ -11,8 +11,8 @@ final class QueueWorkerInterfaceProxy implements WorkerInterface { public function __construct( - private WorkerInterface $worker, - private QueueCollector $collector, + private readonly WorkerInterface $worker, + private readonly QueueCollector $collector, ) { } diff --git a/src/Exception/JobFailureException.php b/src/Exception/JobFailureException.php index 59482d72..cb167759 100644 --- a/src/Exception/JobFailureException.php +++ b/src/Exception/JobFailureException.php @@ -11,8 +11,10 @@ final class JobFailureException extends RuntimeException { - public function __construct(private MessageInterface $queueMessage, Throwable $previous) - { + public function __construct( + private readonly MessageInterface $queueMessage, + Throwable $previous + ) { $error = $previous->getMessage(); $messageId = $queueMessage->getMetadata()[IdEnvelope::MESSAGE_ID_KEY] ?? 'null'; $messageText = "Processing of message #$messageId is stopped because of an exception:\n$error."; diff --git a/src/Message/EnvelopeTrait.php b/src/Message/EnvelopeTrait.php index 68ae0d88..f5dc1257 100644 --- a/src/Message/EnvelopeTrait.php +++ b/src/Message/EnvelopeTrait.php @@ -11,7 +11,7 @@ trait EnvelopeTrait /** * A mirror of {@see MessageInterface::fromData()} */ - abstract public static function fromMessage(MessageInterface $message): self; + abstract public static function fromMessage(MessageInterface $message): MessageInterface; public static function fromData(string $handlerName, mixed $data, array $metadata = []): MessageInterface { diff --git a/src/Message/IdEnvelope.php b/src/Message/IdEnvelope.php index bbf0d67f..bdfd48a6 100644 --- a/src/Message/IdEnvelope.php +++ b/src/Message/IdEnvelope.php @@ -5,7 +5,7 @@ namespace Yiisoft\Queue\Message; /** - * ID envelope allows to identify a message. + * ID envelope allows identifying a message. */ final class IdEnvelope implements EnvelopeInterface { @@ -14,9 +14,10 @@ final class IdEnvelope implements EnvelopeInterface public const MESSAGE_ID_KEY = 'yii-message-id'; public function __construct( - private MessageInterface $message, - private string|int|null $id = null, + MessageInterface $message, + private readonly string|int|null $id = null, ) { + $this->message = $message; } public static function fromMessage(MessageInterface $message): self @@ -24,11 +25,6 @@ public static function fromMessage(MessageInterface $message): self return new self($message, $message->getMetadata()[self::MESSAGE_ID_KEY] ?? null); } - public function setId(string|int|null $id): void - { - $this->id = $id; - } - public function getId(): string|int|null { return $this->id ?? $this->message->getMetadata()[self::MESSAGE_ID_KEY] ?? null; diff --git a/src/Message/Message.php b/src/Message/Message.php index ab85d069..bcc35211 100644 --- a/src/Message/Message.php +++ b/src/Message/Message.php @@ -9,11 +9,10 @@ final class Message implements MessageInterface /** * @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 */ public function __construct( - private string $handlerName, - private mixed $data, + private readonly string $handlerName, + private readonly mixed $data, private array $metadata = [], ) { } diff --git a/src/Middleware/CallableFactory.php b/src/Middleware/CallableFactory.php index f0d538e4..09c41aa3 100644 --- a/src/Middleware/CallableFactory.php +++ b/src/Middleware/CallableFactory.php @@ -19,12 +19,13 @@ */ final class CallableFactory { - public function __construct(private ContainerInterface $container) - { + public function __construct( + private readonly ContainerInterface $container + ) { } /** - * Create real callable listener from definition. + * Create a real callable listener from definition. * * @param mixed $definition Definition to create listener from. * diff --git a/src/Middleware/Consume/ConsumeFinalHandler.php b/src/Middleware/Consume/ConsumeFinalHandler.php index e3d281ef..fd514310 100644 --- a/src/Middleware/Consume/ConsumeFinalHandler.php +++ b/src/Middleware/Consume/ConsumeFinalHandler.php @@ -11,8 +11,9 @@ */ final class ConsumeFinalHandler implements MessageHandlerConsumeInterface { - public function __construct(private Closure $handler) - { + public function __construct( + private readonly Closure $handler + ) { } public function handleConsume(ConsumeRequest $request): ConsumeRequest diff --git a/src/Middleware/Consume/ConsumeMiddlewareDispatcher.php b/src/Middleware/Consume/ConsumeMiddlewareDispatcher.php index 7cef6572..feef5529 100644 --- a/src/Middleware/Consume/ConsumeMiddlewareDispatcher.php +++ b/src/Middleware/Consume/ConsumeMiddlewareDispatcher.php @@ -21,7 +21,7 @@ final class ConsumeMiddlewareDispatcher private array $middlewareDefinitions; public function __construct( - private MiddlewareFactoryConsumeInterface $middlewareFactory, + private readonly MiddlewareFactoryConsumeInterface $middlewareFactory, array|callable|string|MiddlewareConsumeInterface ...$middlewareDefinitions, ) { $this->middlewareDefinitions = array_reverse($middlewareDefinitions); @@ -31,7 +31,7 @@ public function __construct( * Dispatch request through middleware to get response. * * @param ConsumeRequest $request Request to pass to middleware. - * @param MessageHandlerConsumeInterface $finishHandler Handler to use in case no middleware produced response. + * @param MessageHandlerConsumeInterface $finishHandler Handler to use in case no middleware produced a response. */ public function dispatch( ConsumeRequest $request, @@ -47,7 +47,7 @@ public function dispatch( /** * Returns new instance with middleware handlers replaced with the ones provided. - * Last specified handler will be executed first. + * The last specified handler will be executed first. * * @param array[]|callable[]|MiddlewareConsumeInterface[]|string[] $middlewareDefinitions Each array element is: * @@ -56,7 +56,7 @@ public function dispatch( * ResponseInterface` signature. * - A "callable-like" array in format `[FooMiddleware::class, 'index']`. `FooMiddleware` instance will * be created and `index()` method will be executed. - * - A function returning a middleware. The middleware returned will be executed. + * - A function returning middleware. The middleware returned will be executed. * * For callables typed parameters are automatically injected using dependency injection container. * diff --git a/src/Middleware/Consume/MiddlewareConsumeStack.php b/src/Middleware/Consume/MiddlewareConsumeStack.php index 935594c6..73ce91a6 100644 --- a/src/Middleware/Consume/MiddlewareConsumeStack.php +++ b/src/Middleware/Consume/MiddlewareConsumeStack.php @@ -22,8 +22,8 @@ final class MiddlewareConsumeStack implements MessageHandlerConsumeInterface * events. */ public function __construct( - private array $middlewares, - private MessageHandlerConsumeInterface $finishHandler, + private readonly array $middlewares, + private readonly MessageHandlerConsumeInterface $finishHandler, ) { } @@ -57,8 +57,8 @@ private function wrap(Closure $middlewareFactory, MessageHandlerConsumeInterface private ?MiddlewareConsumeInterface $middleware = null; public function __construct( - private Closure $middlewareFactory, - private MessageHandlerConsumeInterface $handler, + private readonly Closure $middlewareFactory, + private readonly MessageHandlerConsumeInterface $handler, ) { } diff --git a/src/Middleware/Consume/MiddlewareFactoryConsume.php b/src/Middleware/Consume/MiddlewareFactoryConsume.php index e5561b37..7b916be4 100644 --- a/src/Middleware/Consume/MiddlewareFactoryConsume.php +++ b/src/Middleware/Consume/MiddlewareFactoryConsume.php @@ -25,14 +25,14 @@ final class MiddlewareFactoryConsume implements MiddlewareFactoryConsumeInterfac * @param ContainerInterface $container Container to use for resolving definitions. */ public function __construct( - private ContainerInterface $container, - private CallableFactory $callableFactory, + private readonly ContainerInterface $container, + private readonly CallableFactory $callableFactory, ) { } /** - * @param array|callable|MiddlewareConsumeInterface|string $middlewareDefinition Middleware definition in one of the - * following formats: + * @param array|callable|MiddlewareConsumeInterface|string $middlewareDefinition Middleware definition in one of + * the following formats: * * - A middleware object. * - A name of a middleware class. The middleware instance will be obtained from container and executed. @@ -89,8 +89,10 @@ private function wrapCallable(callable $callback): MiddlewareConsumeInterface return new class ($callback, $this->container) implements MiddlewareConsumeInterface { private $callback; - public function __construct(callable $callback, private ContainerInterface $container) - { + public function __construct( + callable $callback, + private readonly ContainerInterface $container + ) { $this->callback = $callback; } diff --git a/src/Middleware/FailureHandling/FailureEnvelope.php b/src/Middleware/FailureHandling/FailureEnvelope.php index 0f6a62e9..9190d82d 100644 --- a/src/Middleware/FailureHandling/FailureEnvelope.php +++ b/src/Middleware/FailureHandling/FailureEnvelope.php @@ -15,9 +15,10 @@ final class FailureEnvelope implements EnvelopeInterface public const FAILURE_META_KEY = 'failure-meta'; public function __construct( - private MessageInterface $message, - private array $meta = [], + MessageInterface $message, + private readonly array $meta = [], ) { + $this->message = $message; } public static function fromMessage(MessageInterface $message): self diff --git a/src/Middleware/FailureHandling/FailureMiddlewareDispatcher.php b/src/Middleware/FailureHandling/FailureMiddlewareDispatcher.php index 841e53c8..17c631b2 100644 --- a/src/Middleware/FailureHandling/FailureMiddlewareDispatcher.php +++ b/src/Middleware/FailureHandling/FailureMiddlewareDispatcher.php @@ -21,7 +21,7 @@ final class FailureMiddlewareDispatcher * @param array[][]|callable[][]|MiddlewareFailureInterface[][]|string[][] $middlewareDefinitions */ public function __construct( - private MiddlewareFactoryFailureInterface $middlewareFactory, + private readonly MiddlewareFactoryFailureInterface $middlewareFactory, private array $middlewareDefinitions, ) { $this->init(); @@ -31,7 +31,7 @@ public function __construct( * Dispatch request through middleware to get response. * * @param FailureHandlingRequest $request Request to pass to middleware. - * @param MessageFailureHandlerInterface $finishHandler Handler to use in case no middleware produced response. + * @param MessageFailureHandlerInterface $finishHandler Handler to use in case no middleware produced a response. */ public function dispatch( FailureHandlingRequest $request, @@ -53,7 +53,7 @@ public function dispatch( /** * Returns new instance with middleware handlers replaced with the ones provided. - * Last specified handler will be executed first. + * The last specified handler will be executed first. * * @param array[][]|callable[][]|MiddlewareFailureInterface[][]|string[][] $middlewareDefinitions Each array element is: * diff --git a/src/Middleware/FailureHandling/Implementation/ExponentialDelayMiddleware.php b/src/Middleware/FailureHandling/Implementation/ExponentialDelayMiddleware.php index 643ab31c..0cd0eacf 100644 --- a/src/Middleware/FailureHandling/Implementation/ExponentialDelayMiddleware.php +++ b/src/Middleware/FailureHandling/Implementation/ExponentialDelayMiddleware.php @@ -28,16 +28,17 @@ 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 A middleware for message delaying. * @param QueueInterface|null $queue */ public function __construct( - private string $id, - private int $maxAttempts, - private float $delayInitial, - private float $delayMaximum, - private float $exponent, - private DelayMiddlewareInterface $delayMiddleware, - private ?QueueInterface $queue = null, + private readonly string $id, + private readonly int $maxAttempts, + private readonly float $delayInitial, + private readonly float $delayMaximum, + private readonly float $exponent, + private readonly DelayMiddlewareInterface $delayMiddleware, + private readonly ?QueueInterface $queue = null, ) { if ($maxAttempts <= 0) { throw new InvalidArgumentException("maxAttempts parameter must be a positive integer, $this->maxAttempts given."); diff --git a/src/Middleware/FailureHandling/Implementation/SendAgainMiddleware.php b/src/Middleware/FailureHandling/Implementation/SendAgainMiddleware.php index a7ae792a..589bc07a 100644 --- a/src/Middleware/FailureHandling/Implementation/SendAgainMiddleware.php +++ b/src/Middleware/FailureHandling/Implementation/SendAgainMiddleware.php @@ -26,9 +26,9 @@ final class SendAgainMiddleware implements MiddlewareFailureInterface * They will be resent to an original queue otherwise. */ public function __construct( - private string $id, - private int $maxAttempts, - private ?QueueInterface $targetQueue = null, + private readonly string $id, + private readonly int $maxAttempts, + private readonly ?QueueInterface $targetQueue = null, ) { if ($maxAttempts < 1) { throw new InvalidArgumentException("maxAttempts parameter must be a positive integer, $this->maxAttempts given."); diff --git a/src/Middleware/FailureHandling/MiddlewareFactoryFailure.php b/src/Middleware/FailureHandling/MiddlewareFactoryFailure.php index 084f20d3..fcee6695 100644 --- a/src/Middleware/FailureHandling/MiddlewareFactoryFailure.php +++ b/src/Middleware/FailureHandling/MiddlewareFactoryFailure.php @@ -27,14 +27,14 @@ final class MiddlewareFactoryFailure implements MiddlewareFactoryFailureInterfac * @param ContainerInterface $container Container to use for resolving definitions. */ public function __construct( - private ContainerInterface $container, - private CallableFactory $callableFactory, + private readonly ContainerInterface $container, + private readonly CallableFactory $callableFactory, ) { } /** - * @param array|callable|MiddlewareFailureInterface|string $middlewareDefinition Middleware definition in one of the - * following formats: + * @param array|callable|MiddlewareFailureInterface|string $middlewareDefinition Middleware definition in one of + * the following formats: * * - A middleware object. * - A name of a middleware class. The middleware instance will be obtained from container and executed. @@ -92,8 +92,10 @@ private function wrapCallable(callable $callback): MiddlewareFailureInterface return new class ($callback, $this->container) implements MiddlewareFailureInterface { private $callback; - public function __construct(callable $callback, private ContainerInterface $container) - { + public function __construct( + callable $callback, + private readonly ContainerInterface $container + ) { $this->callback = $callback; } diff --git a/src/Middleware/FailureHandling/MiddlewareFailureStack.php b/src/Middleware/FailureHandling/MiddlewareFailureStack.php index f57c8b44..b02a984b 100644 --- a/src/Middleware/FailureHandling/MiddlewareFailureStack.php +++ b/src/Middleware/FailureHandling/MiddlewareFailureStack.php @@ -22,8 +22,8 @@ final class MiddlewareFailureStack implements MessageFailureHandlerInterface * events. */ public function __construct( - private array $middlewares, - private MessageFailureHandlerInterface $finishHandler, + private readonly array $middlewares, + private readonly MessageFailureHandlerInterface $finishHandler, ) { } @@ -57,8 +57,8 @@ private function wrap(Closure $middlewareFactory, MessageFailureHandlerInterface private ?MiddlewareFailureInterface $middleware = null; public function __construct( - private Closure $middlewareFactory, - private MessageFailureHandlerInterface $handler, + private readonly Closure $middlewareFactory, + private readonly MessageFailureHandlerInterface $handler, ) { } diff --git a/src/Middleware/InvalidMiddlewareDefinitionException.php b/src/Middleware/InvalidMiddlewareDefinitionException.php index 9ca6ef27..cbf4707e 100644 --- a/src/Middleware/InvalidMiddlewareDefinitionException.php +++ b/src/Middleware/InvalidMiddlewareDefinitionException.php @@ -29,6 +29,7 @@ public function __construct($middlewareDefinition, int $code = 0, ?Throwable $pr } /** + * @param mixed $middlewareDefinition Middleware definition. * @return string|null */ private function convertDefinitionToString(mixed $middlewareDefinition): ?string diff --git a/src/Middleware/Push/MiddlewareFactoryPush.php b/src/Middleware/Push/MiddlewareFactoryPush.php index 8e235b36..e3444c6f 100644 --- a/src/Middleware/Push/MiddlewareFactoryPush.php +++ b/src/Middleware/Push/MiddlewareFactoryPush.php @@ -25,14 +25,14 @@ final class MiddlewareFactoryPush implements MiddlewareFactoryPushInterface * @param ContainerInterface $container Container to use for resolving definitions. */ public function __construct( - private ContainerInterface $container, - private CallableFactory $callableFactory, + private readonly ContainerInterface $container, + private readonly CallableFactory $callableFactory, ) { } /** - * @param array|callable|MiddlewarePushInterface|string $middlewareDefinition Middleware definition in one of the - * following formats: + * @param array|callable|MiddlewarePushInterface|string $middlewareDefinition Middleware definition in one of + * the following formats: * * - A middleware object. * - A name of a middleware class. The middleware instance will be obtained from container and executed. @@ -89,8 +89,10 @@ private function wrapCallable(callable $callback): MiddlewarePushInterface return new class ($callback, $this->container) implements MiddlewarePushInterface { private $callback; - public function __construct(callable $callback, private ContainerInterface $container) - { + public function __construct( + callable $callback, + private readonly ContainerInterface $container + ) { $this->callback = $callback; } diff --git a/src/Middleware/Push/MiddlewarePushStack.php b/src/Middleware/Push/MiddlewarePushStack.php index 5682cfc9..cf531316 100644 --- a/src/Middleware/Push/MiddlewarePushStack.php +++ b/src/Middleware/Push/MiddlewarePushStack.php @@ -22,8 +22,8 @@ final class MiddlewarePushStack implements MessageHandlerPushInterface * events. */ public function __construct( - private array $middlewares, - private MessageHandlerPushInterface $finishHandler, + private readonly array $middlewares, + private readonly MessageHandlerPushInterface $finishHandler, ) { } @@ -57,8 +57,8 @@ private function wrap(Closure $middlewareFactory, MessageHandlerPushInterface $h private ?MiddlewarePushInterface $middleware = null; public function __construct( - private Closure $middlewareFactory, - private MessageHandlerPushInterface $handler, + private readonly Closure $middlewareFactory, + private readonly MessageHandlerPushInterface $handler, ) { } diff --git a/src/Middleware/Push/PushMiddlewareDispatcher.php b/src/Middleware/Push/PushMiddlewareDispatcher.php index 489dabab..a3889156 100644 --- a/src/Middleware/Push/PushMiddlewareDispatcher.php +++ b/src/Middleware/Push/PushMiddlewareDispatcher.php @@ -20,7 +20,7 @@ final class PushMiddlewareDispatcher private array $middlewareDefinitions; public function __construct( - private MiddlewareFactoryPushInterface $middlewareFactory, + private readonly MiddlewareFactoryPushInterface $middlewareFactory, array|callable|string|MiddlewarePushInterface ...$middlewareDefinitions, ) { $this->middlewareDefinitions = array_reverse($middlewareDefinitions); @@ -30,7 +30,7 @@ public function __construct( * Dispatch request through middleware to get response. * * @param PushRequest $request Request to pass to middleware. - * @param MessageHandlerPushInterface $finishHandler Handler to use in case no middleware produced response. + * @param MessageHandlerPushInterface $finishHandler Handler to use in case no middleware produced a response. */ public function dispatch( PushRequest $request, @@ -45,7 +45,7 @@ public function dispatch( /** * Returns new instance with middleware handlers replaced with the ones provided. - * Last specified handler will be executed first. + * The last specified handler will be executed first. * * @param array[]|callable[]|MiddlewarePushInterface[]|string[] $middlewareDefinitions Each array element is: * diff --git a/src/Provider/AdapterFactoryQueueProvider.php b/src/Provider/AdapterFactoryQueueProvider.php index 36c2a193..aac1b205 100644 --- a/src/Provider/AdapterFactoryQueueProvider.php +++ b/src/Provider/AdapterFactoryQueueProvider.php @@ -16,7 +16,7 @@ use function sprintf; /** - * This queue provider create new queue objects based on adapter definitions. + * This queue provider creates new queue objects based on adapter definitions. * * @see https://github.com/yiisoft/definitions/ * @see https://github.com/yiisoft/factory/ diff --git a/src/Provider/ChannelNotFoundException.php b/src/Provider/ChannelNotFoundException.php index ef9b3ace..ccd43bd3 100644 --- a/src/Provider/ChannelNotFoundException.php +++ b/src/Provider/ChannelNotFoundException.php @@ -12,7 +12,7 @@ use function sprintf; /** - * Thrown when channel is not found. + * Thrown when the channel is not found. */ final class ChannelNotFoundException extends LogicException implements QueueProviderException { diff --git a/src/Queue.php b/src/Queue.php index abd731e4..faf890df 100644 --- a/src/Queue.php +++ b/src/Queue.php @@ -26,10 +26,10 @@ final class Queue implements QueueInterface private AdapterPushHandler $adapterPushHandler; public function __construct( - private WorkerInterface $worker, - private LoopInterface $loop, - private LoggerInterface $logger, - private PushMiddlewareDispatcher $pushMiddlewareDispatcher, + private readonly WorkerInterface $worker, + private readonly LoopInterface $loop, + private readonly LoggerInterface $logger, + private readonly PushMiddlewareDispatcher $pushMiddlewareDispatcher, private ?AdapterInterface $adapter = null, MiddlewarePushInterface|callable|array|string ...$middlewareDefinitions ) { @@ -158,12 +158,12 @@ private function createPushHandler(MiddlewarePushInterface|callable|array|string array_merge($this->middlewareDefinitions, $middlewares) ) implements MessageHandlerPushInterface { public function __construct( - private AdapterPushHandler $adapterPushHandler, - private PushMiddlewareDispatcher $dispatcher, + private readonly AdapterPushHandler $adapterPushHandler, + private readonly PushMiddlewareDispatcher $dispatcher, /** * @var array|array[]|callable[]|MiddlewarePushInterface[]|string[] */ - private array $middlewares, + private readonly array $middlewares, ) { } diff --git a/src/QueueInterface.php b/src/QueueInterface.php index 17237548..3c8b9a3a 100644 --- a/src/QueueInterface.php +++ b/src/QueueInterface.php @@ -25,7 +25,7 @@ public function push(MessageInterface $message, MiddlewarePushInterface|callable /** * Execute all existing jobs and exit * - * @return int How many messages were processed + * @return int Number of messages processed. */ public function run(int $max = 0): int; diff --git a/src/Worker/Worker.php b/src/Worker/Worker.php index b369bb06..33c2dff6 100644 --- a/src/Worker/Worker.php +++ b/src/Worker/Worker.php @@ -33,12 +33,12 @@ final class Worker implements WorkerInterface private array $handlersCached = []; public function __construct( - private array $handlers, - private LoggerInterface $logger, - private Injector $injector, - private ContainerInterface $container, - private ConsumeMiddlewareDispatcher $consumeMiddlewareDispatcher, - private FailureMiddlewareDispatcher $failureMiddlewareDispatcher, + private readonly array $handlers, + private readonly LoggerInterface $logger, + private readonly Injector $injector, + private readonly ContainerInterface $container, + private readonly ConsumeMiddlewareDispatcher $consumeMiddlewareDispatcher, + private readonly FailureMiddlewareDispatcher $failureMiddlewareDispatcher, ) { } @@ -103,6 +103,7 @@ 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/stubs/StubQueue.php b/stubs/StubQueue.php index 69efc0d7..dc19ed62 100644 --- a/stubs/StubQueue.php +++ b/stubs/StubQueue.php @@ -60,6 +60,6 @@ public function getChannel(): string throw new LogicException('Adapter is not set.'); } - return $this->adapter?->getChannel(); + return $this->adapter->getChannel(); } } diff --git a/tests/App/DummyQueue.php b/tests/App/DummyQueue.php index d8a9828e..149845e7 100644 --- a/tests/App/DummyQueue.php +++ b/tests/App/DummyQueue.php @@ -13,8 +13,9 @@ final class DummyQueue implements QueueInterface { - public function __construct(private string $channel) - { + public function __construct( + private readonly string $channel + ) { } public function push( diff --git a/tests/App/FakeHandler.php b/tests/App/FakeHandler.php index b2d2e49c..a0760859 100644 --- a/tests/App/FakeHandler.php +++ b/tests/App/FakeHandler.php @@ -16,7 +16,7 @@ public function __construct() self::$processedMessages = []; } - public function __invoke(MessageInterface $message) + public function __invoke(MessageInterface $message): void { self::$processedMessages[] = $message; } diff --git a/tests/Benchmark/MetadataBench.php b/tests/Benchmark/MetadataBench.php index 459cd53b..12a25d6b 100644 --- a/tests/Benchmark/MetadataBench.php +++ b/tests/Benchmark/MetadataBench.php @@ -15,7 +15,7 @@ final class MetadataBench { /** - * Create metadata as array and read its value from array + * Create metadata as an array and read its value from an array. */ #[Tag('metadata_read')] public function benchArrayRead(): void @@ -25,7 +25,7 @@ public function benchArrayRead(): void } /** - * Create metadata as object and read its value immediately + * Create metadata as an object and read its value immediately. */ #[Tag('metadata_read')] public function benchEnvelopeRead(): void @@ -35,7 +35,7 @@ public function benchEnvelopeRead(): void } /** - * Create metadata as array and read its value from an envelope object + * Create metadata as an array and read its value from an envelope object. */ #[Tag('metadata_read')] public function benchEnvelopeReadRestored(): void @@ -92,7 +92,7 @@ public function benchEnvelopeStackCreation(array $params): void } /** - * Create metadata array with the given elements count + * Create a metadata array with the given elements count * * @psalm-param array{0: int} $params */ diff --git a/tests/Benchmark/Support/VoidAdapter.php b/tests/Benchmark/Support/VoidAdapter.php index cb295eed..863ed587 100644 --- a/tests/Benchmark/Support/VoidAdapter.php +++ b/tests/Benchmark/Support/VoidAdapter.php @@ -20,7 +20,7 @@ final class VoidAdapter implements AdapterInterface */ public string $message; - public function __construct(private MessageSerializerInterface $serializer) + public function __construct(private readonly MessageSerializerInterface $serializer) { } diff --git a/tests/Integration/Support/TestMiddleware.php b/tests/Integration/Support/TestMiddleware.php index 54ea46bb..78b8a907 100644 --- a/tests/Integration/Support/TestMiddleware.php +++ b/tests/Integration/Support/TestMiddleware.php @@ -14,7 +14,7 @@ final class TestMiddleware implements MiddlewarePushInterface, MiddlewareConsumeInterface { - public function __construct(private string $stage) + public function __construct(private readonly string $stage) { } diff --git a/tests/Unit/Adapter/SynchronousAdapterTest.php b/tests/Unit/Adapter/SynchronousAdapterTest.php index d9ca6b37..7d2758ce 100644 --- a/tests/Unit/Adapter/SynchronousAdapterTest.php +++ b/tests/Unit/Adapter/SynchronousAdapterTest.php @@ -4,6 +4,7 @@ namespace Yiisoft\Queue\Tests\Unit\Adapter; +use InvalidArgumentException; use PHPUnit\Framework\Attributes\DataProvider; use Yiisoft\Queue\Adapter\SynchronousAdapter; use Yiisoft\Queue\JobStatus; @@ -86,7 +87,7 @@ public function testWithAnotherChannel(): void public function testStatusIdLessZero(): void { $adapter = $this->getAdapter(); - $this->expectException(\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('This adapter IDs start with 0.'); $adapter->status('-1'); } @@ -94,7 +95,7 @@ public function testStatusIdLessZero(): void public function testStatusNotMessage(): void { $adapter = $this->getAdapter(); - $this->expectException(\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('There is no message with the given ID.'); $adapter->status('1'); } diff --git a/tests/Unit/Command/SoftLimitTraitTest.php b/tests/Unit/Command/SoftLimitTraitTest.php index fe034a5a..187c38d5 100644 --- a/tests/Unit/Command/SoftLimitTraitTest.php +++ b/tests/Unit/Command/SoftLimitTraitTest.php @@ -33,7 +33,7 @@ public function testMemoryLimitNotReachedWhenUsageIsLower(): void memoryLimitReached as public; } - public function __construct(private int $limit) + public function __construct(private readonly int $limit) { } @@ -54,7 +54,7 @@ public function testMemoryLimitReachedWhenUsageIsHigher(): void memoryLimitReached as public; } - public function __construct(private int $limit) + public function __construct(private readonly int $limit) { } @@ -75,7 +75,7 @@ public function testMemoryLimitExceededWhenUsageIncreases(): void memoryLimitReached as public; } - public function __construct(private int $limit) + public function __construct(private readonly int $limit) { } @@ -91,7 +91,7 @@ protected function getMemoryLimit(): int // Create a large string to increase memory usage $largeString = str_repeat('x', 5 * 1024 * 1024 + 1); // 5MB and 1 byte string - // Now memory limit should be exceeded + // Now the memory limit should be exceeded $this->assertTrue($instance->memoryLimitReached()); // Clean up to free memory diff --git a/tests/Unit/EnvelopeTest.php b/tests/Unit/EnvelopeTest.php index d7e4650e..ad86abd5 100644 --- a/tests/Unit/EnvelopeTest.php +++ b/tests/Unit/EnvelopeTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Unit; +namespace Yiisoft\Queue\Tests\Unit; use PHPUnit\Framework\TestCase; use Yiisoft\Queue\Message\EnvelopeInterface; diff --git a/tests/Unit/Message/JsonMessageSerializerTest.php b/tests/Unit/Message/JsonMessageSerializerTest.php index 93889d3b..8101c24c 100644 --- a/tests/Unit/Message/JsonMessageSerializerTest.php +++ b/tests/Unit/Message/JsonMessageSerializerTest.php @@ -11,7 +11,6 @@ use Yiisoft\Queue\Message\IdEnvelope; use Yiisoft\Queue\Message\JsonMessageSerializer; use Yiisoft\Queue\Message\Message; -use Yiisoft\Queue\Message\MessageInterface; use Yiisoft\Queue\Tests\Unit\Support\TestMessage; /** @@ -115,7 +114,6 @@ public function testUnserializeFromData(): void $message = $serializer->unserialize(json_encode($payload)); - $this->assertInstanceOf(MessageInterface::class, $message); $this->assertEquals($payload['data'], $message->getData()); $this->assertEquals([EnvelopeInterface::ENVELOPE_STACK_KEY => []], $message->getMetadata()); } @@ -127,7 +125,6 @@ public function testUnserializeWithMetadata(): void $message = $serializer->unserialize(json_encode($payload)); - $this->assertInstanceOf(MessageInterface::class, $message); $this->assertEquals($payload['data'], $message->getData()); $this->assertEquals(['int' => 1, 'str' => 'string', 'bool' => true, EnvelopeInterface::ENVELOPE_STACK_KEY => []], $message->getMetadata()); } @@ -147,7 +144,6 @@ public function testUnserializeEnvelopeStack(): void $message = $serializer->unserialize(json_encode($payload)); - $this->assertInstanceOf(MessageInterface::class, $message); $this->assertEquals($payload['data'], $message->getData()); $this->assertEquals([IdEnvelope::class], $message->getMetadata()[EnvelopeInterface::ENVELOPE_STACK_KEY]); diff --git a/tests/Unit/Middleware/Consume/Support/TestMiddleware.php b/tests/Unit/Middleware/Consume/Support/TestMiddleware.php index 1e4508f0..4a0baacd 100644 --- a/tests/Unit/Middleware/Consume/Support/TestMiddleware.php +++ b/tests/Unit/Middleware/Consume/Support/TestMiddleware.php @@ -11,7 +11,7 @@ final class TestMiddleware implements MiddlewareConsumeInterface { - public function __construct(private string $message = 'New middleware test data') + public function __construct(private readonly string $message = 'New middleware test data') { } diff --git a/tests/Unit/Middleware/FailureHandling/Implementation/SendAgainMiddlewareTest.php b/tests/Unit/Middleware/FailureHandling/Implementation/SendAgainMiddlewareTest.php index 665c6bea..f0c838ed 100644 --- a/tests/Unit/Middleware/FailureHandling/Implementation/SendAgainMiddlewareTest.php +++ b/tests/Unit/Middleware/FailureHandling/Implementation/SendAgainMiddlewareTest.php @@ -85,7 +85,7 @@ public static function queueSendingStrategyProvider(): array self::KEY_EXPONENTIAL_ATTEMPTS => 1, ], [ - self::KEY_EXPONENTIAL_DELAY => 1 * self::EXPONENTIAL_STRATEGY_EXPONENT, + self::KEY_EXPONENTIAL_DELAY => self::EXPONENTIAL_STRATEGY_EXPONENT, self::KEY_EXPONENTIAL_ATTEMPTS => 2, ], ], diff --git a/tests/Unit/Middleware/FailureHandling/Support/TestMiddleware.php b/tests/Unit/Middleware/FailureHandling/Support/TestMiddleware.php index e929e357..f22a2755 100644 --- a/tests/Unit/Middleware/FailureHandling/Support/TestMiddleware.php +++ b/tests/Unit/Middleware/FailureHandling/Support/TestMiddleware.php @@ -11,7 +11,7 @@ final class TestMiddleware implements MiddlewareFailureInterface { - public function __construct(private string $message = 'New middleware test data') + public function __construct(private readonly string $message = 'New middleware test data') { } diff --git a/tests/Unit/Middleware/Push/Support/TestMiddleware.php b/tests/Unit/Middleware/Push/Support/TestMiddleware.php index a15c24f0..5baf1d3b 100644 --- a/tests/Unit/Middleware/Push/Support/TestMiddleware.php +++ b/tests/Unit/Middleware/Push/Support/TestMiddleware.php @@ -11,7 +11,7 @@ final class TestMiddleware implements MiddlewarePushInterface { - public function __construct(private string $message = 'New middleware test data') + public function __construct(private readonly string $message = 'New middleware test data') { } diff --git a/tests/Unit/Provider/AdapterFactoryQueueProviderTest.php b/tests/Unit/Provider/AdapterFactoryQueueProviderTest.php index 4a52ac6f..68dedcae 100644 --- a/tests/Unit/Provider/AdapterFactoryQueueProviderTest.php +++ b/tests/Unit/Provider/AdapterFactoryQueueProviderTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Provider; +namespace Yiisoft\Queue\Tests\Unit\Provider; use PHPUnit\Framework\TestCase; use Yiisoft\Queue\Adapter\AdapterInterface; diff --git a/tests/Unit/Provider/ChannelNotFoundExceptionTest.php b/tests/Unit/Provider/ChannelNotFoundExceptionTest.php index 6e967133..c7bf0bed 100644 --- a/tests/Unit/Provider/ChannelNotFoundExceptionTest.php +++ b/tests/Unit/Provider/ChannelNotFoundExceptionTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Provider; +namespace Yiisoft\Queue\Tests\Unit\Provider; use PHPUnit\Framework\Attributes\DataProvider; use Yiisoft\Queue\Provider\ChannelNotFoundException; diff --git a/tests/Unit/WorkerTest.php b/tests/Unit/WorkerTest.php index 74bbf539..6d84b10b 100644 --- a/tests/Unit/WorkerTest.php +++ b/tests/Unit/WorkerTest.php @@ -6,6 +6,7 @@ use Psr\Container\ContainerInterface; use Psr\Log\LoggerInterface; +use RuntimeException; use Yiisoft\Injector\Injector; use Yiisoft\Test\Support\Container\SimpleContainer; use Yiisoft\Test\Support\Log\SimpleLogger; @@ -211,7 +212,7 @@ public function testHandlerNotFoundInContainer(): void $queue = $this->createMock(QueueInterface::class); $worker = $this->createWorkerByParams($handlers, $logger, $container); - $this->expectException(\RuntimeException::class); + $this->expectException(RuntimeException::class); $this->expectExceptionMessage('Queue handler with name "nonexistent" does not exist'); $worker->process($message, $queue); } @@ -232,7 +233,7 @@ public function handle(): void $queue = $this->createMock(QueueInterface::class); $worker = $this->createWorkerByParams($handlers, $logger, $container); - $this->expectException(\RuntimeException::class); + $this->expectException(RuntimeException::class); $this->expectExceptionMessage('Queue handler with name "invalid" does not exist'); $worker->process($message, $queue); }