From 4326ba7ca299de0891c8067893408e72089f7a36 Mon Sep 17 00:00:00 2001 From: Jasper Smet Date: Thu, 23 Oct 2025 11:46:20 +0200 Subject: [PATCH 1/4] Cleanup up - Use constructor promotion where possible - Use readonly properties where possible - Add Rectoring - Update some - Use spread operator wher possible - Use strict comparisons where possible - Use null coalescing operator where possible --- composer.json | 3 ++ rector.php | 26 ++++++++++ src/Command/JobCommand.php | 1 - src/Command/PurgeFailedCommand.php | 19 +++---- src/Command/RequeueCommand.php | 29 +++++------ src/Command/WorkerCommand.php | 30 ++++------- src/Consumption/LimitAttemptsExtension.php | 18 ++----- .../LimitConsumedMessagesExtension.php | 17 ++----- .../RemoveUniqueJobIdFromCacheExtension.php | 15 ++---- src/Job/JobInterface.php | 1 - src/Job/MailerJob.php | 5 +- src/Job/Message.php | 45 +++++++---------- src/Job/SendMailJob.php | 6 +-- src/Listener/FailedJobsListener.php | 9 ++-- src/Mailer/QueueTrait.php | 1 - src/Mailer/Transport/QueueTransport.php | 7 ++- src/Model/Entity/FailedJob.php | 1 - src/Model/Table/FailedJobsTable.php | 2 - src/Plugin.php | 6 +-- src/Queue/Processor.php | 30 ++++------- src/QueueManager.php | 50 +++++++++---------- templates/bake/job.twig | 1 - tests/Fixture/FailedJobsFixture.php | 2 - .../Command/PurgeFailedCommandTest.php | 2 +- tests/TestCase/Command/RequeueCommandTest.php | 2 +- tests/TestCase/Command/WorkerCommandTest.php | 2 - tests/TestCase/Job/MailerJobTest.php | 9 ++-- tests/TestCase/Job/MessageTest.php | 9 ++-- tests/TestCase/Job/SendMailJobTest.php | 3 +- tests/TestCase/Queue/ProcessorTest.php | 5 +- tests/TestCase/QueueTestTrait.php | 10 ++-- tests/TestCase/Task/JobTaskTest.php | 2 - tests/bootstrap.php | 4 +- tests/comparisons/JobTask.php | 1 - tests/comparisons/JobTaskWithMaxAttempts.php | 1 - tests/comparisons/JobTaskWithUnique.php | 1 - .../src/Queue/TestCustomProcessor.php | 14 ++---- tests/test_app/src/TestProcessor.php | 6 --- tests/test_app/src/WelcomeMailerListener.php | 3 -- 39 files changed, 159 insertions(+), 239 deletions(-) create mode 100644 rector.php diff --git a/composer.json b/composer.json index c9d1609..5a5934f 100644 --- a/composer.json +++ b/composer.json @@ -66,6 +66,9 @@ "phpstan": "tools/phpstan analyse", "stan-baseline": "tools/phpstan --generate-baseline", "stan-setup": "phive install", + "rector-setup": "cp composer.json composer.backup && composer require --dev rector/rector:\"^2.2\" && mv composer.backup composer.json", + "rector-check": "vendor/bin/rector process --dry-run", + "rector-fix": "vendor/bin/rector process", "test": "phpunit", "test-coverage": "phpunit --coverage-clover=clover.xml" } diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..ab1947c --- /dev/null +++ b/rector.php @@ -0,0 +1,26 @@ +withPhpVersion(PhpVersion::PHP_82) + ->withPaths([ + __DIR__ . '/src', + __DIR__ . '/tests', + ]) + ->withSkip([ + DisallowedEmptyRuleFixerRector::class, + SimplifyIfElseToTernaryRector::class, + MakeInheritedMethodVisibilitySameAsParentRector::class, + ]) + ->withParallel() + ->withPreparedSets( + deadCode: true, + codeQuality: true, + codingStyle: true, + ); diff --git a/src/Command/JobCommand.php b/src/Command/JobCommand.php index 7148df9..eca7c50 100644 --- a/src/Command/JobCommand.php +++ b/src/Command/JobCommand.php @@ -69,7 +69,6 @@ public function templateData(Arguments $arguments): array * Gets the option parser instance and configures it. * * @param \Cake\Console\ConsoleOptionParser $parser The parser to update. - * @return \Cake\Console\ConsoleOptionParser */ public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser { diff --git a/src/Command/PurgeFailedCommand.php b/src/Command/PurgeFailedCommand.php index f2c0d3a..8f7c05a 100644 --- a/src/Command/PurgeFailedCommand.php +++ b/src/Command/PurgeFailedCommand.php @@ -28,8 +28,6 @@ class PurgeFailedCommand extends Command /** * Get the command name. - * - * @return string */ public static function defaultName(): string { @@ -38,8 +36,6 @@ public static function defaultName(): string /** * Gets the option parser instance and configures it. - * - * @return \Cake\Console\ConsoleOptionParser */ public function getOptionParser(): ConsoleOptionParser { @@ -72,9 +68,8 @@ public function getOptionParser(): ConsoleOptionParser /** * @param \Cake\Console\Arguments $args Arguments * @param \Cake\Console\ConsoleIo $io ConsoleIo - * @return void */ - public function execute(Arguments $args, ConsoleIo $io): void + public function execute(Arguments $args, ConsoleIo $io): int { /** @var \Cake\Queue\Model\Table\FailedJobsTable $failedJobsTable */ $failedJobsTable = $this->getTableLocator()->get('Cake/Queue.FailedJobs'); @@ -108,21 +103,23 @@ public function execute(Arguments $args, ConsoleIo $io): void if (!$deletingCount) { $io->out('0 jobs found.'); - return; + return self::CODE_SUCCESS; } if (!$args->getOption('force')) { - $confirmed = $io->askChoice("Delete {$deletingCount} jobs?", ['y', 'n'], 'n'); + $confirmed = $io->askChoice(sprintf('Delete %s jobs?', $deletingCount), ['y', 'n'], 'n'); if ($confirmed !== 'y') { - return; + return self::CODE_SUCCESS; } } - $io->out("Deleting {$deletingCount} jobs."); + $io->out(sprintf('Deleting %s jobs.', $deletingCount)); $failedJobsTable->deleteManyOrFail($jobsToDelete); - $io->success("{$deletingCount} jobs deleted."); + $io->success($deletingCount . ' jobs deleted.'); + + return self::CODE_SUCCESS; } } diff --git a/src/Command/RequeueCommand.php b/src/Command/RequeueCommand.php index b9efd02..653a982 100644 --- a/src/Command/RequeueCommand.php +++ b/src/Command/RequeueCommand.php @@ -30,8 +30,6 @@ class RequeueCommand extends Command /** * Get the command name. - * - * @return string */ public static function defaultName(): string { @@ -40,8 +38,6 @@ public static function defaultName(): string /** * Gets the option parser instance and configures it. - * - * @return \Cake\Console\ConsoleOptionParser */ public function getOptionParser(): ConsoleOptionParser { @@ -74,9 +70,8 @@ public function getOptionParser(): ConsoleOptionParser /** * @param \Cake\Console\Arguments $args Arguments * @param \Cake\Console\ConsoleIo $io ConsoleIo - * @return void */ - public function execute(Arguments $args, ConsoleIo $io): void + public function execute(Arguments $args, ConsoleIo $io): int { /** @var \Cake\Queue\Model\Table\FailedJobsTable $failedJobsTable */ $failedJobsTable = $this->getTableLocator()->get('Cake/Queue.FailedJobs'); @@ -110,18 +105,18 @@ public function execute(Arguments $args, ConsoleIo $io): void if (!$requeueingCount) { $io->out('0 jobs found.'); - return; + return self::CODE_SUCCESS; } if (!$args->getOption('force')) { - $confirmed = $io->askChoice("Requeue {$requeueingCount} jobs?", ['y', 'n'], 'n'); + $confirmed = $io->askChoice(sprintf('Requeue %s jobs?', $requeueingCount), ['y', 'n'], 'n'); if ($confirmed !== 'y') { - return; + return self::CODE_SUCCESS; } } - $io->out("Requeueing {$requeueingCount} jobs."); + $io->out(sprintf('Requeueing %s jobs.', $requeueingCount)); $succeededCount = 0; $failedCount = 0; @@ -129,7 +124,7 @@ public function execute(Arguments $args, ConsoleIo $io): void /** @var array<\Cake\Queue\Model\Entity\FailedJob> $jobsToRequeue */ $jobsToRequeue = $jobsToRequeueQuery->all(); foreach ($jobsToRequeue as $failedJob) { - $io->verbose("Requeueing FailedJob with ID {$failedJob->id}."); + $io->verbose(sprintf('Requeueing FailedJob with ID %d.', $failedJob->id)); try { QueueManager::push( [$failedJob->class, $failedJob->method], @@ -145,19 +140,21 @@ public function execute(Arguments $args, ConsoleIo $io): void $succeededCount++; } catch (Exception $e) { - $io->err("Exception occurred while requeueing FailedJob with ID {$failedJob->id}"); + $io->err('Exception occurred while requeueing FailedJob with ID ' . $failedJob->id); $io->err((string)$e); $failedCount++; } } - if ($failedCount) { - $io->err("Failed to requeue {$failedCount} jobs."); + if ($failedCount !== 0) { + $io->err(sprintf('Failed to requeue %d jobs.', $failedCount)); } - if ($succeededCount) { - $io->success("{$succeededCount} jobs requeued."); + if ($succeededCount !== 0) { + $io->success($succeededCount . ' jobs requeued.'); } + + return self::CODE_SUCCESS; } } diff --git a/src/Command/WorkerCommand.php b/src/Command/WorkerCommand.php index e755b34..0bdb653 100644 --- a/src/Command/WorkerCommand.php +++ b/src/Command/WorkerCommand.php @@ -43,23 +43,16 @@ */ class WorkerCommand extends Command { - /** - * @var \Cake\Core\ContainerInterface|null - */ - protected ?ContainerInterface $container = null; - /** * @param \Cake\Core\ContainerInterface|null $container DI container instance */ - public function __construct(?ContainerInterface $container = null) - { - $this->container = $container; + public function __construct( + protected readonly ?ContainerInterface $container = null, + ) { } /** * Get the command name. - * - * @return string */ public static function defaultName(): string { @@ -68,8 +61,6 @@ public static function defaultName(): string /** * Gets the option parser instance and configures it. - * - * @return \Cake\Console\ConsoleOptionParser */ public function getOptionParser(): ConsoleOptionParser { @@ -122,7 +113,6 @@ public function getOptionParser(): ConsoleOptionParser * * @param \Cake\Console\Arguments $args Arguments * @param \Psr\Log\LoggerInterface $logger Logger instance. - * @return \Enqueue\Consumption\ExtensionInterface */ protected function getQueueExtension(Arguments $args, LoggerInterface $logger): ExtensionInterface { @@ -138,12 +128,12 @@ protected function getQueueExtension(Arguments $args, LoggerInterface $logger): $limitAttempsExtension, ]; - if (!is_null($args->getOption('max-jobs'))) { + if ($args->getOption('max-jobs') !== null) { $maxJobs = (int)$args->getOption('max-jobs'); $extensions[] = new LimitConsumedMessagesExtension($maxJobs); } - if (!is_null($args->getOption('max-runtime'))) { + if ($args->getOption('max-runtime') !== null) { $endTime = new DateTime(sprintf('+%d seconds', (int)$args->getOption('max-runtime'))); $extensions[] = new LimitConsumptionTimeExtension($endTime); } @@ -159,7 +149,6 @@ protected function getQueueExtension(Arguments $args, LoggerInterface $logger): * Creates and returns a LoggerInterface object * * @param \Cake\Console\Arguments $args Arguments - * @return \Psr\Log\LoggerInterface */ protected function getLogger(Arguments $args): LoggerInterface { @@ -177,7 +166,6 @@ protected function getLogger(Arguments $args): LoggerInterface * @param \Cake\Console\Arguments $args Arguments * @param \Cake\Console\ConsoleIo $io ConsoleIo * @param \Psr\Log\LoggerInterface $logger Logger instance - * @return \Interop\Queue\Processor */ protected function getProcessor(Arguments $args, ConsoleIo $io, LoggerInterface $logger): InteropProcessor { @@ -187,12 +175,12 @@ protected function getProcessor(Arguments $args, ConsoleIo $io, LoggerInterface $processorClass = $config['processor'] ?? Processor::class; if (!class_exists($processorClass)) { - $io->error(sprintf(sprintf('Processor class %s not found', $processorClass))); + $io->error(sprintf('Processor class %s not found', $processorClass)); $this->abort(); } if (!is_subclass_of($processorClass, InteropProcessor::class)) { - $io->error(sprintf(sprintf('Processor class %s must implement Interop\Queue\Processor', $processorClass))); + $io->error(sprintf('Processor class %s must implement Interop\Queue\Processor', $processorClass)); $this->abort(); } @@ -202,7 +190,6 @@ protected function getProcessor(Arguments $args, ConsoleIo $io, LoggerInterface /** * @param \Cake\Console\Arguments $args Arguments * @param \Cake\Console\ConsoleIo $io ConsoleIo - * @return int */ public function execute(Arguments $args, ConsoleIo $io): int { @@ -231,10 +218,11 @@ public function execute(Arguments $args, ConsoleIo $io): int $processor->getEventManager()->on($listener); } } + $client = QueueManager::engine($config); $queue = $args->getOption('queue') ? (string)$args->getOption('queue') - : Configure::read("Queue.{$config}.queue", 'default'); + : Configure::read(sprintf('Queue.%s.queue', $config), 'default'); $processorName = $args->getOption('processor') ? (string)$args->getOption('processor') : 'default'; $client->bindTopic($queue, $processor, $processorName); diff --git a/src/Consumption/LimitAttemptsExtension.php b/src/Consumption/LimitAttemptsExtension.php index c3a0af6..846add6 100644 --- a/src/Consumption/LimitAttemptsExtension.php +++ b/src/Consumption/LimitAttemptsExtension.php @@ -25,25 +25,15 @@ class LimitAttemptsExtension implements MessageResultExtensionInterface public const ATTEMPTS_PROPERTY = 'attempts'; /** - * The maximum number of times a job may be attempted. $maxAttempts defined on a - * Job will override this value. - * - * @var int|null + * @param int|null $maxAttempts The maximum number of times a job may be attempted. $maxAttempts defined on a Job will override this value. */ - protected ?int $maxAttempts = null; - - /** - * @param int|null $maxAttempts The maximum number of times a job may be attempted. - * @return void - */ - public function __construct(?int $maxAttempts = null) - { - $this->maxAttempts = $maxAttempts; + public function __construct( + protected readonly ?int $maxAttempts = null, + ) { } /** * @param \Enqueue\Consumption\Context\MessageResult $context The result of the message after it was processed. - * @return void */ public function onResult(MessageResult $context): void { diff --git a/src/Consumption/LimitConsumedMessagesExtension.php b/src/Consumption/LimitConsumedMessagesExtension.php index e202fbe..8953496 100644 --- a/src/Consumption/LimitConsumedMessagesExtension.php +++ b/src/Consumption/LimitConsumedMessagesExtension.php @@ -18,22 +18,14 @@ */ class LimitConsumedMessagesExtension implements PreConsumeExtensionInterface, PostConsumeExtensionInterface { - /** - * @var int - */ - protected int $messageLimit; - - /** - * @var int - */ protected int $messageConsumed = 0; /** * @param int $messageLimit The number of messages to process before exiting. */ - public function __construct(int $messageLimit) - { - $this->messageLimit = $messageLimit; + public function __construct( + protected readonly int $messageLimit, + ) { } /** @@ -41,7 +33,6 @@ public function __construct(int $messageLimit) * The consumption could be interrupted at this step. * * @param \Enqueue\Consumption\Context\PreConsume $context The PreConsume context. - * @return void */ public function onPreConsume(PreConsume $context): void { @@ -56,7 +47,6 @@ public function onPreConsume(PreConsume $context): void * The consumption could be interrupted at this point. * * @param \Enqueue\Consumption\Context\PostConsume $context The PostConsume context. - * @return void */ public function onPostConsume(PostConsume $context): void { @@ -71,7 +61,6 @@ public function onPostConsume(PostConsume $context): void * Check if the consumer should be stopped. * * @param \Psr\Log\LoggerInterface $logger The logger where messages will be logged. - * @return bool */ protected function shouldBeStopped(LoggerInterface $logger): bool { diff --git a/src/Consumption/RemoveUniqueJobIdFromCacheExtension.php b/src/Consumption/RemoveUniqueJobIdFromCacheExtension.php index 74ff3ad..613d61d 100644 --- a/src/Consumption/RemoveUniqueJobIdFromCacheExtension.php +++ b/src/Consumption/RemoveUniqueJobIdFromCacheExtension.php @@ -11,25 +11,16 @@ class RemoveUniqueJobIdFromCacheExtension implements MessageResultExtensionInterface { - /** - * Cache engine name. - * - * @var string - */ - protected string $cache; - /** * @param string $cache Cache engine name. - * @return void */ - public function __construct(string $cache) - { - $this->cache = $cache; + public function __construct( + protected readonly string $cache, + ) { } /** * @param \Enqueue\Consumption\Context\MessageResult $context The result of the message after it was processed. - * @return void */ public function onResult(MessageResult $context): void { diff --git a/src/Job/JobInterface.php b/src/Job/JobInterface.php index 65f84fc..d3dd2b8 100644 --- a/src/Job/JobInterface.php +++ b/src/Job/JobInterface.php @@ -22,7 +22,6 @@ interface JobInterface * Executes logic for Job * * @param \Cake\Queue\Job\Message $message job message - * @return string|null */ public function execute(Message $message): ?string; } diff --git a/src/Job/MailerJob.php b/src/Job/MailerJob.php index 66db133..81d167d 100644 --- a/src/Job/MailerJob.php +++ b/src/Job/MailerJob.php @@ -29,7 +29,6 @@ class MailerJob implements JobInterface * Constructs and dispatches the event from a job message * * @param \Cake\Queue\Job\Message $message job message - * @return string|null */ public function execute(Message $message): ?string { @@ -41,13 +40,13 @@ public function execute(Message $message): ?string try { $mailer = $this->getMailer($mailerName, $mailerConfig); - } catch (MissingMailerException $e) { + } catch (MissingMailerException $missingMailerException) { return Processor::REJECT; } try { $mailer->send($action, $args, $headers); - } catch (BadMethodCallException $e) { + } catch (BadMethodCallException $badMethodCallException) { return Processor::REJECT; } diff --git a/src/Job/Message.php b/src/Job/Message.php index 7da6218..c2b3f3e 100644 --- a/src/Job/Message.php +++ b/src/Job/Message.php @@ -27,31 +27,25 @@ class Message implements JsonSerializable { - protected Context $context; - - protected QueueMessage $originalMessage; - protected array $parsedBody; protected ?Closure $callable = null; - protected ?ContainerInterface $container = null; - /** * @param \Interop\Queue\Message $originalMessage Queue message. * @param \Interop\Queue\Context $context Context. * @param \Cake\Core\ContainerInterface|null $container DI container instance */ - public function __construct(QueueMessage $originalMessage, Context $context, ?ContainerInterface $container = null) - { - $this->context = $context; - $this->originalMessage = $originalMessage; + public function __construct( + protected readonly QueueMessage $originalMessage, + protected readonly Context $context, + protected readonly ?ContainerInterface $container = null, + ) { $this->parsedBody = json_decode($originalMessage->getBody(), true); - $this->container = $container; } /** - * @return \Interop\Queue\Context + * Get the queue context. */ public function getContext(): Context { @@ -59,7 +53,7 @@ public function getContext(): Context } /** - * @return \Interop\Queue\Message + * Get the original queue message. */ public function getOriginalMessage(): QueueMessage { @@ -67,7 +61,9 @@ public function getOriginalMessage(): QueueMessage } /** - * @return array + * Get the parsed message body. + * + * @return array */ public function getParsedBody(): array { @@ -79,12 +75,10 @@ public function getParsedBody(): array * * Supported callables include: * - array of [class, method]. The class will be constructed with no constructor parameters. - * - * @return \Closure */ public function getCallable(): Closure { - if ($this->callable) { + if ($this->callable instanceof Closure) { return $this->callable; } @@ -124,16 +118,11 @@ public function getTarget(): array /** * @param mixed $key Key * @param mixed $default Default value. - * @return mixed */ public function getArgument(mixed $key = null, mixed $default = null): mixed { - if (array_key_exists('data', $this->parsedBody)) { - $data = $this->parsedBody['data']; - } else { - // support old jobs that still use args key - $data = $this->parsedBody['args'][0]; - } + // support old jobs that still use args key + $data = $this->parsedBody['data'] ?? $this->parsedBody['args'][0]; if ($key === null) { return $data; @@ -144,8 +133,6 @@ public function getArgument(mixed $key = null, mixed $default = null): mixed /** * The maximum number of attempts allowed by the job. - * - * @return int|null */ public function getMaxAttempts(): ?int { @@ -157,7 +144,7 @@ public function getMaxAttempts(): ?int } /** - * @return string + * Convert the message to a string representation. */ public function __toString(): string { @@ -165,7 +152,9 @@ public function __toString(): string } /** - * @return array + * Serialize the message to JSON. + * + * @return array */ #[ReturnTypeWillChange] public function jsonSerialize(): array diff --git a/src/Job/SendMailJob.php b/src/Job/SendMailJob.php index 3ba9325..387254a 100644 --- a/src/Job/SendMailJob.php +++ b/src/Job/SendMailJob.php @@ -46,10 +46,11 @@ public function execute(Message $message): ?string if (!is_array($data)) { throw new InvalidArgumentException('Email Message cannot be decoded.'); } + $emailMessage->createFromArray($data); $result = $transport->send($emailMessage); - } catch (Exception $e) { - Log::error(sprintf('An error has occurred processing message: %s', $e->getMessage())); + } catch (Exception $exception) { + Log::error(sprintf('An error has occurred processing message: %s', $exception->getMessage())); } if (!$result) { @@ -64,7 +65,6 @@ public function execute(Message $message): ?string * * @param string $transportClassName Transport class name * @param array $config Transport config - * @return \Cake\Mailer\AbstractTransport * @throws \InvalidArgumentException if empty transport class name, class does not exist or send method is not defined for class */ protected function getTransport(string $transportClassName, array $config): AbstractTransport diff --git a/src/Listener/FailedJobsListener.php b/src/Listener/FailedJobsListener.php index f60d15e..a07280b 100644 --- a/src/Listener/FailedJobsListener.php +++ b/src/Listener/FailedJobsListener.php @@ -39,7 +39,6 @@ public function implementedEvents(): array /** * @param \Cake\Event\EventInterface $event EventInterface. - * @return void */ public function storeFailedJob(object $event): void { @@ -76,14 +75,14 @@ public function storeFailedJob(object $event): void try { $failedJobsTable->saveOrFail($failedJob); /** @phpstan-ignore-next-line */ - } catch (PersistenceFailedException $e) { + } catch (PersistenceFailedException $persistenceFailedException) { $logger = $event->getData('logger'); if (!$logger) { throw new RuntimeException( sprintf('`logger` was not defined on %s event.', $event->getName()), 0, - $e, + $persistenceFailedException, ); } @@ -91,11 +90,11 @@ public function storeFailedJob(object $event): void throw new RuntimeException( sprintf('`logger` is not an instance of `LoggerInterface` on %s event.', $event->getName()), 0, - $e, + $persistenceFailedException, ); } - $logger->error((string)$e); + $logger->error((string)$persistenceFailedException); } } } diff --git a/src/Mailer/QueueTrait.php b/src/Mailer/QueueTrait.php index b9a4a5d..787f36e 100644 --- a/src/Mailer/QueueTrait.php +++ b/src/Mailer/QueueTrait.php @@ -32,7 +32,6 @@ trait QueueTrait * @param array $args Arguments to pass to the triggered mailer action. * @param array $headers Headers to set. * @param array $options an array of options for publishing the job - * @return void * @throws \Cake\Mailer\Exception\MissingActionException */ public function push(string $action, array $args = [], array $headers = [], array $options = []): void diff --git a/src/Mailer/Transport/QueueTransport.php b/src/Mailer/Transport/QueueTransport.php index c798d53..cf7cffa 100644 --- a/src/Mailer/Transport/QueueTransport.php +++ b/src/Mailer/Transport/QueueTransport.php @@ -63,9 +63,8 @@ public function send(Message $message): array /** * Add job to queue * - * @param array $data Data to be sent to job - * @param array $options Job options - * @return void + * @param array $data Data to be sent to job + * @param array $options Job options */ protected function enqueueJob(array $data, array $options): void { @@ -80,7 +79,7 @@ protected function enqueueJob(array $data, array $options): void * Prepare data for job * * @param \Cake\Mailer\Message $message Email message - * @return array + * @return array */ protected function prepareData(Message $message): array { diff --git a/src/Model/Entity/FailedJob.php b/src/Model/Entity/FailedJob.php index a0e0c7a..4effccf 100644 --- a/src/Model/Entity/FailedJob.php +++ b/src/Model/Entity/FailedJob.php @@ -45,7 +45,6 @@ class FailedJob extends Entity ]; /** - * @return array * @see \Cake\Queue\Model\Entity\FailedJob::$decoded_data */ protected function _getDecodedData(): array diff --git a/src/Model/Table/FailedJobsTable.php b/src/Model/Table/FailedJobsTable.php index 208b325..405144d 100644 --- a/src/Model/Table/FailedJobsTable.php +++ b/src/Model/Table/FailedJobsTable.php @@ -30,7 +30,6 @@ class FailedJobsTable extends Table * Initialize method * * @param array $config The configuration for the Table. - * @return void */ public function initialize(array $config): void { @@ -47,7 +46,6 @@ public function initialize(array $config): void * Default validation rules. * * @param \Cake\Validation\Validator $validator Validator instance. - * @return \Cake\Validation\Validator */ public function validationDefault(Validator $validator): Validator { diff --git a/src/Plugin.php b/src/Plugin.php index d607ef0..6141459 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -16,6 +16,7 @@ */ namespace Cake\Queue; +use Bake\Command\SimpleBakeCommand; use Cake\Console\CommandCollection; use Cake\Core\BasePlugin; use Cake\Core\Configure; @@ -46,7 +47,6 @@ class Plugin extends BasePlugin * Load the Queue configuration * * @param \Cake\Core\PluginApplicationInterface $app The host application - * @return void */ public function bootstrap(PluginApplicationInterface $app): void { @@ -68,11 +68,10 @@ public function bootstrap(PluginApplicationInterface $app): void * Add console commands for the plugin. * * @param \Cake\Console\CommandCollection $commands The command collection to update - * @return \Cake\Console\CommandCollection */ public function console(CommandCollection $commands): CommandCollection { - if (class_exists('Bake\Command\SimpleBakeCommand')) { + if (class_exists(SimpleBakeCommand::class)) { $commands->add('bake job', JobCommand::class); } @@ -87,7 +86,6 @@ public function console(CommandCollection $commands): CommandCollection * Add DI container to Worker command * * @param \Cake\Core\ContainerInterface $container The DI container - * @return void */ public function services(ContainerInterface $container): void { diff --git a/src/Queue/Processor.php b/src/Queue/Processor.php index b90601d..bff6628 100644 --- a/src/Queue/Processor.php +++ b/src/Queue/Processor.php @@ -37,25 +37,13 @@ class Processor implements InteropProcessor use EventDispatcherTrait; /** - * @var \Psr\Log\LoggerInterface - */ - protected LoggerInterface $logger; - - /** - * @var \Cake\Core\ContainerInterface|null - */ - protected ?ContainerInterface $container = null; - - /** - * Processor constructor - * - * @param \Psr\Log\LoggerInterface|null $logger Logger instance. + * @param \Psr\Log\LoggerInterface $logger Logger instance. * @param \Cake\Core\ContainerInterface|null $container DI container instance */ - public function __construct(?LoggerInterface $logger = null, ?ContainerInterface $container = null) - { - $this->logger = $logger ?: new NullLogger(); - $this->container = $container; + public function __construct( + protected readonly LoggerInterface $logger = new NullLogger(), + protected readonly ?ContainerInterface $container = null, + ) { } /** @@ -84,13 +72,13 @@ public function process(QueueMessage $message, Context $context): string|object try { $response = $this->processMessage($jobMessage); - } catch (Throwable $e) { - $message->setProperty('jobException', $e); + } catch (Throwable $throwable) { + $message->setProperty('jobException', $throwable); - $this->logger->debug(sprintf('Message encountered exception: %s', $e->getMessage())); + $this->logger->debug(sprintf('Message encountered exception: %s', $throwable->getMessage())); $this->dispatchEvent('Processor.message.exception', [ 'message' => $jobMessage, - 'exception' => $e, + 'exception' => $throwable, 'duration' => (int)((microtime(true) * 1000) - $startTime), ]); diff --git a/src/QueueManager.php b/src/QueueManager.php index 32cd914..c97667f 100644 --- a/src/QueueManager.php +++ b/src/QueueManager.php @@ -24,20 +24,21 @@ use Enqueue\SimpleClient\SimpleClient; use InvalidArgumentException; use LogicException; +use Psr\Log\LoggerInterface; class QueueManager { /** * Configuration sets. * - * @var array + * @var array> */ protected static array $_config = []; /** * Queue clients * - * @var array + * @var array */ protected static array $_clients = []; @@ -72,11 +73,10 @@ class QueueManager * QueueManager::setConfig($arrayOfConfig); * ``` * - * @param array|string $key The name of the configuration, or an array of multiple configs. - * @param array $config An array of name => configuration data for adapter. + * @param array>|string $key The name of the configuration, or an array of multiple configs. + * @param array|null $config An array of name => configuration data for adapter. * @throws \BadMethodCallException When trying to modify an existing config. * @throws \LogicException When trying to store an invalid structured config array. - * @return void */ public static function setConfig(string|array $key, ?array $config = null): void { @@ -84,6 +84,7 @@ public static function setConfig(string|array $key, ?array $config = null): void if (!is_array($key)) { throw new LogicException('If config is null, key must be an array.'); } + foreach ($key as $name => $settings) { static::setConfig($name, $settings); } @@ -126,9 +127,9 @@ public static function setConfig(string|array $key, ?array $config = null): void 'duration' => '+24 hours', ]; - $cacheConfig = array_merge($cacheDefaults, $config['uniqueCache']); + $cacheConfig = [...$cacheDefaults, ...$config['uniqueCache']]; - $config['uniqueCacheKey'] = "Cake/Queue.queueUnique.{$key}"; + $config['uniqueCacheKey'] = 'Cake/Queue.queueUnique.' . $key; Cache::setConfig($config['uniqueCacheKey'], $cacheConfig); } @@ -140,9 +141,9 @@ public static function setConfig(string|array $key, ?array $config = null): void * Reads existing configuration. * * @param string $key The name of the configuration. - * @return mixed Configuration data at the named key or null if the key does not exist. + * @return array|null Configuration data at the named key or null if the key does not exist. */ - public static function getConfig(string $key): mixed + public static function getConfig(string $key): ?array { return static::$_config[$key] ?? null; } @@ -150,7 +151,7 @@ public static function getConfig(string $key): mixed /** * Get the configured queue keys. * - * @return array List of configured queue configuration keys. + * @return array List of configured queue configuration keys. */ public static function configured(): array { @@ -161,7 +162,6 @@ public static function configured(): array * Remove a configured queue adapter. * * @param string $key The config name to drop. - * @return void */ public static function drop(string $key): void { @@ -172,7 +172,6 @@ public static function drop(string $key): void * Get a queueing engine * * @param string $name Key name of a configured adapter to get. - * @return \Enqueue\SimpleClient\SimpleClient */ public static function engine(string $name): SimpleClient { @@ -190,7 +189,7 @@ public static function engine(string $name): SimpleClient static::$_clients[$name] = new SimpleClient($config['url'], $logger); static::$_clients[$name]->setupBroker(); - if (!is_null($config['receiveTimeout'])) { + if ($config['receiveTimeout'] !== null) { static::$_clients[$name]->getQueueConsumer()->setReceiveTimeout($config['receiveTimeout']); } @@ -200,11 +199,11 @@ public static function engine(string $name): SimpleClient /** * Push a single job onto the queue. * - * @param array|string $className The classname of a job that implements the + * @param array|string $className The classname of a job that implements the * \Cake\Queue\Job\JobInterface. The class will be constructed by * \Cake\Queue\Processor and have the execute method invoked. - * @param array $data An array of data that will be passed to the job. - * @param array $options An array of options for publishing the job: + * @param array $data An array of data that will be passed to the job. + * @param array $options An array of options for publishing the job: * - `config` - A queue config name. Defaults to 'default'. * - `delay` - Time (in integer seconds) to delay message, after which it * will be processed. Not all message brokers accept this. Default `null`. @@ -219,7 +218,6 @@ public static function engine(string $name): SimpleClient * - `\Enqueue\Client\MessagePriority::VERY_HIGH` * - `queue` - The name of a queue to use, from queue `config` array or * string 'default' if empty. - * @return void */ public static function push(string|array $className, array $data = [], array $options = []): void { @@ -227,7 +225,7 @@ public static function push(string|array $className, array $data = [], array $op $class = App::className($class, 'Job', 'Job'); if (is_null($class)) { - throw new InvalidArgumentException("`$class` class does not exist."); + throw new InvalidArgumentException(sprintf('`%s` class does not exist.', $class)); } $name = $options['config'] ?? 'default'; @@ -241,16 +239,19 @@ public static function push(string|array $className, array $data = [], array $op if (!empty($class::$shouldBeUnique)) { if (empty($config['uniqueCache'])) { throw new InvalidArgumentException( - "$class::\$shouldBeUnique is set to `true` but `uniqueCache` configuration is missing.", + $class . '::$shouldBeUnique is set to `true` but `uniqueCache` configuration is missing.', ); } $uniqueId = static::getUniqueId($class, $method, $data); if (Cache::read($uniqueId, $config['uniqueCacheKey'])) { - if ($logger) { + if ($logger instanceof LoggerInterface) { $logger->debug( - "An identical instance of $class already exists on the queue. This push will be ignored.", + sprintf( + 'An identical instance of %s already exists on the queue. This push will be ignored.', + $class, + ), ); } @@ -294,16 +295,15 @@ public static function push(string|array $className, array $data = [], array $op } /** - * @param string $class Class name + * @param class-string $class Class name * @param string $method Method name - * @param array $data Message data - * @return string + * @param array $data Message data */ public static function getUniqueId(string $class, string $method, array $data): string { sort($data); - $hashInput = implode([ + $hashInput = implode('', [ $class, $method, json_encode($data), diff --git a/templates/bake/job.twig b/templates/bake/job.twig index 7dc6873..7c32b34 100644 --- a/templates/bake/job.twig +++ b/templates/bake/job.twig @@ -49,7 +49,6 @@ class {{ name }}Job implements JobInterface * Executes logic for {{ name }}Job * * @param \Cake\Queue\Job\Message $message job message - * @return string|null */ public function execute(Message $message): ?string { diff --git a/tests/Fixture/FailedJobsFixture.php b/tests/Fixture/FailedJobsFixture.php index c44743e..26cfcbf 100644 --- a/tests/Fixture/FailedJobsFixture.php +++ b/tests/Fixture/FailedJobsFixture.php @@ -16,8 +16,6 @@ class FailedJobsFixture extends TestFixture /** * Init method - * - * @return void */ public function init(): void { diff --git a/tests/TestCase/Command/PurgeFailedCommandTest.php b/tests/TestCase/Command/PurgeFailedCommandTest.php index cf5cd6f..eb22a53 100644 --- a/tests/TestCase/Command/PurgeFailedCommandTest.php +++ b/tests/TestCase/Command/PurgeFailedCommandTest.php @@ -73,7 +73,7 @@ public function testFailedJobsAreDeletedById() public function testFailedJobsAreDeletedByClass() { $class = LogToDebugJob::class; - $this->exec("queue purge_failed --class {$class} -f"); + $this->exec(sprintf('queue purge_failed --class %s -f', $class)); $this->assertOutputContains('Deleting 2 jobs.'); $this->assertOutputContains('2 jobs deleted.'); diff --git a/tests/TestCase/Command/RequeueCommandTest.php b/tests/TestCase/Command/RequeueCommandTest.php index 480b9e9..bff69fb 100644 --- a/tests/TestCase/Command/RequeueCommandTest.php +++ b/tests/TestCase/Command/RequeueCommandTest.php @@ -133,7 +133,7 @@ public function testJobsAreRequeuedByClass() $this->cleanupConsoleTrait(); $class = LogToDebugJob::class; - $this->exec("queue requeue --class {$class} --queue default -f"); + $this->exec(sprintf('queue requeue --class %s --queue default -f', $class)); $this->assertOutputContains('Requeueing 1 jobs.'); $this->assertOutputContains('1 jobs requeued.'); diff --git a/tests/TestCase/Command/WorkerCommandTest.php b/tests/TestCase/Command/WorkerCommandTest.php index 297fca6..d0bad67 100644 --- a/tests/TestCase/Command/WorkerCommandTest.php +++ b/tests/TestCase/Command/WorkerCommandTest.php @@ -142,8 +142,6 @@ public function testQueueProcessesWithLogger() /** * Data provider for testQueueProcessesJob method - * - * @return array */ public static function dataProviderCallableTypes(): array { diff --git a/tests/TestCase/Job/MailerJobTest.php b/tests/TestCase/Job/MailerJobTest.php index 9a617b9..81dd8c8 100644 --- a/tests/TestCase/Job/MailerJobTest.php +++ b/tests/TestCase/Job/MailerJobTest.php @@ -32,12 +32,16 @@ class MailerJobTest extends TestCase * @var \Cake\Mailer\Mailer|\PHPUnit\Framework\MockObject\MockObject */ protected $mailer; + /** * @var \Cake\Queue\Job\MailerJob|\PHPUnit\Framework\MockObject\MockObject */ protected $job; + protected $mailerConfig; + protected $headers; + protected $args; /** @@ -139,8 +143,6 @@ public function testExecuteBadMethodCallException() /** * Create a simple message for testing. - * - * @return \Cake\Queue\Job\Message */ protected function createMessage(): Message { @@ -157,8 +159,7 @@ protected function createMessage(): Message $connectionFactory = new NullConnectionFactory(); $context = $connectionFactory->createContext(); $originalMessage = new NullMessage(json_encode($messageBody)); - $message = new Message($originalMessage, $context); - return $message; + return new Message($originalMessage, $context); } } diff --git a/tests/TestCase/Job/MessageTest.php b/tests/TestCase/Job/MessageTest.php index e828814..9d09471 100644 --- a/tests/TestCase/Job/MessageTest.php +++ b/tests/TestCase/Job/MessageTest.php @@ -23,6 +23,7 @@ use Enqueue\Null\NullMessage; use Error; use RuntimeException; +use TestApp\WelcomeMailer; class MessageTest extends TestCase { @@ -33,10 +34,10 @@ class MessageTest extends TestCase */ public function testConstructorAndGetters() { - $callable = ['TestApp\WelcomeMailer', 'welcome']; + $callable = [WelcomeMailer::class, 'welcome']; $time = 'sample data ' . time(); $id = 7; - $data = compact('id', 'time'); + $data = ['id' => $id, 'time' => $time]; $parsedBody = [ 'class' => $callable, 'data' => $data, @@ -71,7 +72,7 @@ public function testConstructorAndGetters() */ public function testLegacyArguments() { - $callable = ['TestApp\WelcomeMailer', 'welcome']; + $callable = [WelcomeMailer::class, 'welcome']; $args = [ 'first' => 1, 'second' => 'two', @@ -123,7 +124,7 @@ public function testGetCallableInvalidClass() public function testGetCallableInvalidType() { $parsedBody = [ - 'class' => ['TestApp\WelcomeMailer', 'trash', 'oops'], + 'class' => [WelcomeMailer::class, 'trash', 'oops'], 'args' => [], ]; $messageBody = json_encode($parsedBody); diff --git a/tests/TestCase/Job/SendMailJobTest.php b/tests/TestCase/Job/SendMailJobTest.php index 337c096..d60a219 100644 --- a/tests/TestCase/Job/SendMailJobTest.php +++ b/tests/TestCase/Job/SendMailJobTest.php @@ -109,6 +109,7 @@ public function testExecuteWithAttachments() { $emailMessage = clone $this->message; $emailMessage->addAttachments(['test.txt' => ROOT . 'files' . DS . 'test.txt']); + $message = $this->createMessage(DebugTransport::class, [], $emailMessage); $actual = $this->job->execute($message); $this->assertSame(Processor::ACK, $actual); @@ -147,8 +148,6 @@ public function testExecuteNoAbstractTransport() /** * Create a simple message for testing. - * - * @return \Cake\Queue\Job\Message */ protected function createMessage($transport, $config, $emailMessage): QueueJobMessage { diff --git a/tests/TestCase/Queue/ProcessorTest.php b/tests/TestCase/Queue/ProcessorTest.php index c2eccf9..ccbdc36 100644 --- a/tests/TestCase/Queue/ProcessorTest.php +++ b/tests/TestCase/Queue/ProcessorTest.php @@ -29,6 +29,7 @@ use Interop\Queue\Processor as InteropProcessor; use PHPUnit\Framework\Attributes\DataProvider; use TestApp\TestProcessor; +use TestApp\WelcomeMailer; class ProcessorTest extends TestCase { @@ -38,8 +39,6 @@ class ProcessorTest extends TestCase /** * Data provider for testProcess method - * - * @return array */ public static function dataProviderTestProcess(): array { @@ -187,7 +186,7 @@ public function testProcessJobObject() ]); $messageBody = [ - 'class' => ['TestApp\WelcomeMailer', 'welcome'], + 'class' => [WelcomeMailer::class, 'welcome'], 'args' => [], ]; $connectionFactory = new NullConnectionFactory(); diff --git a/tests/TestCase/QueueTestTrait.php b/tests/TestCase/QueueTestTrait.php index c056223..a15fef9 100644 --- a/tests/TestCase/QueueTestTrait.php +++ b/tests/TestCase/QueueTestTrait.php @@ -37,8 +37,6 @@ trait QueueTestTrait * This is automatically called after each test via the #[After] attribute. * It drops all QueueManager configs and their associated cache configs, * and resets all log configurations. - * - * @return void */ #[After] public function cleanupQueueManagerConfigs(): void @@ -49,7 +47,7 @@ public function cleanupQueueManagerConfigs(): void $queueConfig = QueueManager::getConfig($config); if ($queueConfig && isset($queueConfig['uniqueCacheKey'])) { $cacheKey = $queueConfig['uniqueCacheKey']; - if (Cache::configured($cacheKey)) { + if (Cache::configured()) { Cache::drop($cacheKey); } } @@ -65,13 +63,12 @@ public function cleanupQueueManagerConfigs(): void * Assert that a message was found in debug logs * * @param string $expected The message to search for in logs - * @return void */ protected function assertDebugLogContains($expected): void { $found = $this->debugLogCount($expected); - $this->assertGreaterThanOrEqual(1, $found, "Did not find `{$expected}` in logs."); + $this->assertGreaterThanOrEqual(1, $found, sprintf('Did not find `%s` in logs.', $expected)); } /** @@ -79,13 +76,12 @@ protected function assertDebugLogContains($expected): void * * @param string $expected The message to search for in logs * @param int $times The exact number of times the message should appear - * @return void */ protected function assertDebugLogContainsExactly($expected, $times): void { $found = $this->debugLogCount($expected); - $this->assertSame($times, $found, "Did not find `{$expected}` exactly {$times} times in logs."); + $this->assertSame($times, $found, sprintf('Did not find `%s` exactly %d times in logs.', $expected, $times)); } /** diff --git a/tests/TestCase/Task/JobTaskTest.php b/tests/TestCase/Task/JobTaskTest.php index a49324f..ec4f8f7 100644 --- a/tests/TestCase/Task/JobTaskTest.php +++ b/tests/TestCase/Task/JobTaskTest.php @@ -42,8 +42,6 @@ class JobTaskTest extends TestCase /** * setup method - * - * @return void */ public function setUp(): void { diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 5c6d7c9..e2f7ee2 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -30,13 +30,14 @@ return $root; } } while ($root !== $lastRoot); + throw new Exception('Cannot find the root of the application, unable to run tests'); }; $root = $findRoot(__FILE__); unset($findRoot); chdir($root); -require_once 'vendor/autoload.php'; +require_once $root . '/vendor/autoload.php'; define('CORE_PATH', $root . DS . 'vendor' . DS . 'cakephp' . DS . 'cakephp' . DS); define('ROOT', $root . DS . 'tests' . DS . 'test_app' . DS); @@ -58,6 +59,7 @@ if (Configure::version() <= '5.1.0') { $cache_key = '_cake_core_'; } + Cache::setConfig([ $cache_key => [ 'engine' => 'File', diff --git a/tests/comparisons/JobTask.php b/tests/comparisons/JobTask.php index 822a677..f1e89ae 100644 --- a/tests/comparisons/JobTask.php +++ b/tests/comparisons/JobTask.php @@ -16,7 +16,6 @@ class UploadJob implements JobInterface * Executes logic for UploadJob * * @param \Cake\Queue\Job\Message $message job message - * @return string|null */ public function execute(Message $message): ?string { diff --git a/tests/comparisons/JobTaskWithMaxAttempts.php b/tests/comparisons/JobTaskWithMaxAttempts.php index d8f4c91..ce5f606 100644 --- a/tests/comparisons/JobTaskWithMaxAttempts.php +++ b/tests/comparisons/JobTaskWithMaxAttempts.php @@ -23,7 +23,6 @@ class UploadJob implements JobInterface * Executes logic for UploadJob * * @param \Cake\Queue\Job\Message $message job message - * @return string|null */ public function execute(Message $message): ?string { diff --git a/tests/comparisons/JobTaskWithUnique.php b/tests/comparisons/JobTaskWithUnique.php index f0faf36..2b9aa8a 100644 --- a/tests/comparisons/JobTaskWithUnique.php +++ b/tests/comparisons/JobTaskWithUnique.php @@ -23,7 +23,6 @@ class UploadJob implements JobInterface * Executes logic for UploadJob * * @param \Cake\Queue\Job\Message $message job message - * @return string|null */ public function execute(Message $message): ?string { diff --git a/tests/test_app/src/Queue/TestCustomProcessor.php b/tests/test_app/src/Queue/TestCustomProcessor.php index 56f72eb..14afd6e 100644 --- a/tests/test_app/src/Queue/TestCustomProcessor.php +++ b/tests/test_app/src/Queue/TestCustomProcessor.php @@ -26,14 +26,8 @@ class TestCustomProcessor implements InteropProcessor { use EventDispatcherTrait; - /** - * @var \Psr\Log\LoggerInterface - */ protected LoggerInterface $logger; - /** - * @var \Cake\Core\ContainerInterface|null - */ protected ?ContainerInterface $container = null; /** @@ -73,13 +67,13 @@ public function process(QueueMessage $message, Context $context): string|object try { $response = $this->processMessage($jobMessage); - } catch (Throwable $e) { - $message->setProperty('jobException', $e); + } catch (Throwable $throwable) { + $message->setProperty('jobException', $throwable); - $this->logger->debug(sprintf('Message encountered exception: %s', $e->getMessage())); + $this->logger->debug(sprintf('Message encountered exception: %s', $throwable->getMessage())); $this->dispatchEvent('Processor.message.exception', [ 'message' => $jobMessage, - 'exception' => $e, + 'exception' => $throwable, ]); return Result::requeue('Exception occurred while processing message'); diff --git a/tests/test_app/src/TestProcessor.php b/tests/test_app/src/TestProcessor.php index d2cc69a..ebd12b4 100644 --- a/tests/test_app/src/TestProcessor.php +++ b/tests/test_app/src/TestProcessor.php @@ -15,7 +15,6 @@ class TestProcessor * Job to be used in test testProcessMessageCallableIsString * * @param Message $message The message to process - * @return null * @throws Exception */ public static function processAndThrowException(Message $message) @@ -27,7 +26,6 @@ public static function processAndThrowException(Message $message) * Job to be used in test testProcessMessageCallableIsString * * @param \Cake\Queue\Message $message The message to process - * @return null */ public static function processReturnAck(Message $message) { @@ -40,7 +38,6 @@ public static function processReturnAck(Message $message) * Job to be used in test testProcessMessageCallableIsString * * @param \Cake\Queue\Job\Message $message The message to process - * @return null */ public static function processReturnNull(Message $message) { @@ -53,7 +50,6 @@ public static function processReturnNull(Message $message) * Job to be used in test testProcessMessageCallableIsString * * @param \Cake\Queue\Message $message The message to process - * @return null */ public static function processReturnReject(Message $message) { @@ -66,7 +62,6 @@ public static function processReturnReject(Message $message) * Job to be used in test testProcessMessageCallableIsString * * @param \Cake\Queue\Message $message The message to process - * @return null */ public static function processReturnRequeue(Message $message) { @@ -79,7 +74,6 @@ public static function processReturnRequeue(Message $message) * Job to be used in test testProcessMessageCallableIsString * * @param \Cake\Queue\Message $message The message to process - * @return null */ public static function processReturnString(Message $message) { diff --git a/tests/test_app/src/WelcomeMailerListener.php b/tests/test_app/src/WelcomeMailerListener.php index 2258bd8..75f731d 100644 --- a/tests/test_app/src/WelcomeMailerListener.php +++ b/tests/test_app/src/WelcomeMailerListener.php @@ -25,9 +25,6 @@ */ class WelcomeMailerListener implements EventListenerInterface { - /** - * @return array - */ public function implementedEvents(): array { return []; From 75373f1b2ec3c3578c5c50547ae503c036118dea Mon Sep 17 00:00:00 2001 From: Jasper Smet Date: Thu, 23 Oct 2025 13:54:49 +0200 Subject: [PATCH 2/4] Remove ReturnTypeWillChange attribute Restore check --- src/Job/Message.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Job/Message.php b/src/Job/Message.php index c2b3f3e..24fd5db 100644 --- a/src/Job/Message.php +++ b/src/Job/Message.php @@ -22,7 +22,6 @@ use Interop\Queue\Context; use Interop\Queue\Message as QueueMessage; use JsonSerializable; -use ReturnTypeWillChange; use RuntimeException; class Message implements JsonSerializable @@ -122,7 +121,12 @@ public function getTarget(): array public function getArgument(mixed $key = null, mixed $default = null): mixed { // support old jobs that still use args key - $data = $this->parsedBody['data'] ?? $this->parsedBody['args'][0]; + if (array_key_exists('data', $this->parsedBody)) { + $data = $this->parsedBody['data']; + } else { + // support old jobs that still use args key + $data = $this->parsedBody['args'][0]; + } if ($key === null) { return $data; @@ -156,7 +160,6 @@ public function __toString(): string * * @return array */ - #[ReturnTypeWillChange] public function jsonSerialize(): array { return $this->parsedBody; From 4b06bef4770f5285d753a8a95df8dbe674e11934 Mon Sep 17 00:00:00 2001 From: Jasper Smet Date: Thu, 23 Oct 2025 14:45:21 +0200 Subject: [PATCH 3/4] Re-introduce @return in dockblocks --- rector.php | 5 +++++ src/Command/JobCommand.php | 1 + src/Command/PurgeFailedCommand.php | 5 +++++ src/Command/RequeueCommand.php | 5 +++++ src/Command/WorkerCommand.php | 8 ++++++++ src/Consumption/LimitAttemptsExtension.php | 2 ++ src/Consumption/LimitConsumedMessagesExtension.php | 4 ++++ .../RemoveUniqueJobIdFromCacheExtension.php | 2 ++ src/Job/JobInterface.php | 1 + src/Job/MailerJob.php | 1 + src/Job/Message.php | 14 ++++++++++++++ src/Job/SendMailJob.php | 1 + src/Listener/FailedJobsListener.php | 1 + src/Mailer/QueueTrait.php | 3 ++- src/Mailer/Transport/QueueTransport.php | 2 ++ src/Model/Entity/FailedJob.php | 1 + src/Model/Table/FailedJobsTable.php | 2 ++ src/Plugin.php | 3 +++ src/QueueManager.php | 3 +++ templates/bake/job.twig | 1 + tests/Fixture/FailedJobsFixture.php | 2 ++ tests/TestCase/Command/PurgeFailedCommandTest.php | 3 +++ tests/TestCase/Command/RequeueCommandTest.php | 3 +++ tests/TestCase/Command/WorkerCommandTest.php | 1 + tests/TestCase/Listener/FailedJobsListenerTest.php | 3 +++ tests/TestCase/Queue/ProcessorTest.php | 2 ++ tests/TestCase/QueueTestTrait.php | 6 +++++- tests/comparisons/JobTask.php | 1 + tests/comparisons/JobTaskWithMaxAttempts.php | 1 + tests/comparisons/JobTaskWithUnique.php | 1 + tests/test_app/src/TestProcessor.php | 6 ++++++ tests/test_app/src/WelcomeMailerListener.php | 3 +++ 32 files changed, 95 insertions(+), 2 deletions(-) diff --git a/rector.php b/rector.php index ab1947c..3409996 100644 --- a/rector.php +++ b/rector.php @@ -4,6 +4,8 @@ use Rector\CodeQuality\Rector\If_\SimplifyIfElseToTernaryRector; use Rector\CodingStyle\Rector\ClassMethod\MakeInheritedMethodVisibilitySameAsParentRector; use Rector\Config\RectorConfig; +use Rector\DeadCode\Rector\ClassMethod\RemoveNullTagValueNodeRector; +use Rector\DeadCode\Rector\ClassMethod\RemoveUselessReturnTagRector; use Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector; use Rector\ValueObject\PhpVersion; @@ -17,10 +19,13 @@ DisallowedEmptyRuleFixerRector::class, SimplifyIfElseToTernaryRector::class, MakeInheritedMethodVisibilitySameAsParentRector::class, + RemoveNullTagValueNodeRector::class, + RemoveUselessReturnTagRector::class, ]) ->withParallel() ->withPreparedSets( deadCode: true, codeQuality: true, codingStyle: true, + typeDeclarationDocblocks: true, ); diff --git a/src/Command/JobCommand.php b/src/Command/JobCommand.php index eca7c50..7148df9 100644 --- a/src/Command/JobCommand.php +++ b/src/Command/JobCommand.php @@ -69,6 +69,7 @@ public function templateData(Arguments $arguments): array * Gets the option parser instance and configures it. * * @param \Cake\Console\ConsoleOptionParser $parser The parser to update. + * @return \Cake\Console\ConsoleOptionParser */ public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser { diff --git a/src/Command/PurgeFailedCommand.php b/src/Command/PurgeFailedCommand.php index 8f7c05a..c54cc8d 100644 --- a/src/Command/PurgeFailedCommand.php +++ b/src/Command/PurgeFailedCommand.php @@ -28,6 +28,8 @@ class PurgeFailedCommand extends Command /** * Get the command name. + * + * @return string */ public static function defaultName(): string { @@ -36,6 +38,8 @@ public static function defaultName(): string /** * Gets the option parser instance and configures it. + * + * @return \Cake\Console\ConsoleOptionParser */ public function getOptionParser(): ConsoleOptionParser { @@ -68,6 +72,7 @@ public function getOptionParser(): ConsoleOptionParser /** * @param \Cake\Console\Arguments $args Arguments * @param \Cake\Console\ConsoleIo $io ConsoleIo + * @return int */ public function execute(Arguments $args, ConsoleIo $io): int { diff --git a/src/Command/RequeueCommand.php b/src/Command/RequeueCommand.php index 653a982..ce00f7c 100644 --- a/src/Command/RequeueCommand.php +++ b/src/Command/RequeueCommand.php @@ -30,6 +30,8 @@ class RequeueCommand extends Command /** * Get the command name. + * + * @return string */ public static function defaultName(): string { @@ -38,6 +40,8 @@ public static function defaultName(): string /** * Gets the option parser instance and configures it. + * + * @return \Cake\Console\ConsoleOptionParser */ public function getOptionParser(): ConsoleOptionParser { @@ -70,6 +74,7 @@ public function getOptionParser(): ConsoleOptionParser /** * @param \Cake\Console\Arguments $args Arguments * @param \Cake\Console\ConsoleIo $io ConsoleIo + * @return int */ public function execute(Arguments $args, ConsoleIo $io): int { diff --git a/src/Command/WorkerCommand.php b/src/Command/WorkerCommand.php index 0bdb653..44605d1 100644 --- a/src/Command/WorkerCommand.php +++ b/src/Command/WorkerCommand.php @@ -53,6 +53,8 @@ public function __construct( /** * Get the command name. + * + * @return string */ public static function defaultName(): string { @@ -61,6 +63,8 @@ public static function defaultName(): string /** * Gets the option parser instance and configures it. + * + * @return \Cake\Console\ConsoleOptionParser */ public function getOptionParser(): ConsoleOptionParser { @@ -113,6 +117,7 @@ public function getOptionParser(): ConsoleOptionParser * * @param \Cake\Console\Arguments $args Arguments * @param \Psr\Log\LoggerInterface $logger Logger instance. + * @return \Enqueue\Consumption\ExtensionInterface */ protected function getQueueExtension(Arguments $args, LoggerInterface $logger): ExtensionInterface { @@ -149,6 +154,7 @@ protected function getQueueExtension(Arguments $args, LoggerInterface $logger): * Creates and returns a LoggerInterface object * * @param \Cake\Console\Arguments $args Arguments + * @return \Psr\Log\LoggerInterface */ protected function getLogger(Arguments $args): LoggerInterface { @@ -166,6 +172,7 @@ protected function getLogger(Arguments $args): LoggerInterface * @param \Cake\Console\Arguments $args Arguments * @param \Cake\Console\ConsoleIo $io ConsoleIo * @param \Psr\Log\LoggerInterface $logger Logger instance + * @return \Interop\Queue\Processor */ protected function getProcessor(Arguments $args, ConsoleIo $io, LoggerInterface $logger): InteropProcessor { @@ -190,6 +197,7 @@ protected function getProcessor(Arguments $args, ConsoleIo $io, LoggerInterface /** * @param \Cake\Console\Arguments $args Arguments * @param \Cake\Console\ConsoleIo $io ConsoleIo + * @return int */ public function execute(Arguments $args, ConsoleIo $io): int { diff --git a/src/Consumption/LimitAttemptsExtension.php b/src/Consumption/LimitAttemptsExtension.php index 846add6..0a87881 100644 --- a/src/Consumption/LimitAttemptsExtension.php +++ b/src/Consumption/LimitAttemptsExtension.php @@ -26,6 +26,7 @@ class LimitAttemptsExtension implements MessageResultExtensionInterface /** * @param int|null $maxAttempts The maximum number of times a job may be attempted. $maxAttempts defined on a Job will override this value. + * @return void */ public function __construct( protected readonly ?int $maxAttempts = null, @@ -34,6 +35,7 @@ public function __construct( /** * @param \Enqueue\Consumption\Context\MessageResult $context The result of the message after it was processed. + * @return void */ public function onResult(MessageResult $context): void { diff --git a/src/Consumption/LimitConsumedMessagesExtension.php b/src/Consumption/LimitConsumedMessagesExtension.php index 8953496..c5c7bd8 100644 --- a/src/Consumption/LimitConsumedMessagesExtension.php +++ b/src/Consumption/LimitConsumedMessagesExtension.php @@ -22,6 +22,7 @@ class LimitConsumedMessagesExtension implements PreConsumeExtensionInterface, Po /** * @param int $messageLimit The number of messages to process before exiting. + * @return void */ public function __construct( protected readonly int $messageLimit, @@ -33,6 +34,7 @@ public function __construct( * The consumption could be interrupted at this step. * * @param \Enqueue\Consumption\Context\PreConsume $context The PreConsume context. + * @return void */ public function onPreConsume(PreConsume $context): void { @@ -47,6 +49,7 @@ public function onPreConsume(PreConsume $context): void * The consumption could be interrupted at this point. * * @param \Enqueue\Consumption\Context\PostConsume $context The PostConsume context. + * @return void */ public function onPostConsume(PostConsume $context): void { @@ -61,6 +64,7 @@ public function onPostConsume(PostConsume $context): void * Check if the consumer should be stopped. * * @param \Psr\Log\LoggerInterface $logger The logger where messages will be logged. + * @return bool */ protected function shouldBeStopped(LoggerInterface $logger): bool { diff --git a/src/Consumption/RemoveUniqueJobIdFromCacheExtension.php b/src/Consumption/RemoveUniqueJobIdFromCacheExtension.php index 613d61d..8ad1fc6 100644 --- a/src/Consumption/RemoveUniqueJobIdFromCacheExtension.php +++ b/src/Consumption/RemoveUniqueJobIdFromCacheExtension.php @@ -13,6 +13,7 @@ class RemoveUniqueJobIdFromCacheExtension implements MessageResultExtensionInter { /** * @param string $cache Cache engine name. + * @return void */ public function __construct( protected readonly string $cache, @@ -21,6 +22,7 @@ public function __construct( /** * @param \Enqueue\Consumption\Context\MessageResult $context The result of the message after it was processed. + * @return void */ public function onResult(MessageResult $context): void { diff --git a/src/Job/JobInterface.php b/src/Job/JobInterface.php index d3dd2b8..65f84fc 100644 --- a/src/Job/JobInterface.php +++ b/src/Job/JobInterface.php @@ -22,6 +22,7 @@ interface JobInterface * Executes logic for Job * * @param \Cake\Queue\Job\Message $message job message + * @return string|null */ public function execute(Message $message): ?string; } diff --git a/src/Job/MailerJob.php b/src/Job/MailerJob.php index 81d167d..3d6d71e 100644 --- a/src/Job/MailerJob.php +++ b/src/Job/MailerJob.php @@ -29,6 +29,7 @@ class MailerJob implements JobInterface * Constructs and dispatches the event from a job message * * @param \Cake\Queue\Job\Message $message job message + * @return string|null */ public function execute(Message $message): ?string { diff --git a/src/Job/Message.php b/src/Job/Message.php index 24fd5db..f1b504c 100644 --- a/src/Job/Message.php +++ b/src/Job/Message.php @@ -26,6 +26,9 @@ class Message implements JsonSerializable { + /** + * @var array + */ protected array $parsedBody; protected ?Closure $callable = null; @@ -45,6 +48,8 @@ public function __construct( /** * Get the queue context. + * + * @return \Interop\Queue\Context */ public function getContext(): Context { @@ -53,6 +58,8 @@ public function getContext(): Context /** * Get the original queue message. + * + * @return \Interop\Queue\Message */ public function getOriginalMessage(): QueueMessage { @@ -74,6 +81,8 @@ public function getParsedBody(): array * * Supported callables include: * - array of [class, method]. The class will be constructed with no constructor parameters. + * + * @return \Closure */ public function getCallable(): Closure { @@ -117,6 +126,7 @@ public function getTarget(): array /** * @param mixed $key Key * @param mixed $default Default value. + * @return mixed */ public function getArgument(mixed $key = null, mixed $default = null): mixed { @@ -137,6 +147,8 @@ public function getArgument(mixed $key = null, mixed $default = null): mixed /** * The maximum number of attempts allowed by the job. + * + * @return int|null */ public function getMaxAttempts(): ?int { @@ -149,6 +161,8 @@ public function getMaxAttempts(): ?int /** * Convert the message to a string representation. + * + * @return string */ public function __toString(): string { diff --git a/src/Job/SendMailJob.php b/src/Job/SendMailJob.php index 387254a..efb7ea7 100644 --- a/src/Job/SendMailJob.php +++ b/src/Job/SendMailJob.php @@ -66,6 +66,7 @@ public function execute(Message $message): ?string * @param string $transportClassName Transport class name * @param array $config Transport config * @throws \InvalidArgumentException if empty transport class name, class does not exist or send method is not defined for class + * @return \Cake\Mailer\AbstractTransport */ protected function getTransport(string $transportClassName, array $config): AbstractTransport { diff --git a/src/Listener/FailedJobsListener.php b/src/Listener/FailedJobsListener.php index a07280b..c983fb4 100644 --- a/src/Listener/FailedJobsListener.php +++ b/src/Listener/FailedJobsListener.php @@ -39,6 +39,7 @@ public function implementedEvents(): array /** * @param \Cake\Event\EventInterface $event EventInterface. + * @return void */ public function storeFailedJob(object $event): void { diff --git a/src/Mailer/QueueTrait.php b/src/Mailer/QueueTrait.php index 787f36e..fe94110 100644 --- a/src/Mailer/QueueTrait.php +++ b/src/Mailer/QueueTrait.php @@ -31,8 +31,9 @@ trait QueueTrait * @param string $action The name of the mailer action to trigger. * @param array $args Arguments to pass to the triggered mailer action. * @param array $headers Headers to set. - * @param array $options an array of options for publishing the job + * @param array $options an array of options for publishing the job * @throws \Cake\Mailer\Exception\MissingActionException + * @return void */ public function push(string $action, array $args = [], array $headers = [], array $options = []): void { diff --git a/src/Mailer/Transport/QueueTransport.php b/src/Mailer/Transport/QueueTransport.php index cf7cffa..cc19d7d 100644 --- a/src/Mailer/Transport/QueueTransport.php +++ b/src/Mailer/Transport/QueueTransport.php @@ -36,6 +36,7 @@ class QueueTransport extends AbstractTransport /** * @inheritDoc + * @return array */ public function send(Message $message): array { @@ -65,6 +66,7 @@ public function send(Message $message): array * * @param array $data Data to be sent to job * @param array $options Job options + * @return void */ protected function enqueueJob(array $data, array $options): void { diff --git a/src/Model/Entity/FailedJob.php b/src/Model/Entity/FailedJob.php index 4effccf..62f1fc4 100644 --- a/src/Model/Entity/FailedJob.php +++ b/src/Model/Entity/FailedJob.php @@ -46,6 +46,7 @@ class FailedJob extends Entity /** * @see \Cake\Queue\Model\Entity\FailedJob::$decoded_data + * @return array */ protected function _getDecodedData(): array { diff --git a/src/Model/Table/FailedJobsTable.php b/src/Model/Table/FailedJobsTable.php index 405144d..208b325 100644 --- a/src/Model/Table/FailedJobsTable.php +++ b/src/Model/Table/FailedJobsTable.php @@ -30,6 +30,7 @@ class FailedJobsTable extends Table * Initialize method * * @param array $config The configuration for the Table. + * @return void */ public function initialize(array $config): void { @@ -46,6 +47,7 @@ public function initialize(array $config): void * Default validation rules. * * @param \Cake\Validation\Validator $validator Validator instance. + * @return \Cake\Validation\Validator */ public function validationDefault(Validator $validator): Validator { diff --git a/src/Plugin.php b/src/Plugin.php index 6141459..92cb0de 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -47,6 +47,7 @@ class Plugin extends BasePlugin * Load the Queue configuration * * @param \Cake\Core\PluginApplicationInterface $app The host application + * @return void */ public function bootstrap(PluginApplicationInterface $app): void { @@ -68,6 +69,7 @@ public function bootstrap(PluginApplicationInterface $app): void * Add console commands for the plugin. * * @param \Cake\Console\CommandCollection $commands The command collection to update + * @return \Cake\Console\CommandCollection */ public function console(CommandCollection $commands): CommandCollection { @@ -86,6 +88,7 @@ public function console(CommandCollection $commands): CommandCollection * Add DI container to Worker command * * @param \Cake\Core\ContainerInterface $container The DI container + * @return void */ public function services(ContainerInterface $container): void { diff --git a/src/QueueManager.php b/src/QueueManager.php index c97667f..976fd6c 100644 --- a/src/QueueManager.php +++ b/src/QueueManager.php @@ -77,6 +77,7 @@ class QueueManager * @param array|null $config An array of name => configuration data for adapter. * @throws \BadMethodCallException When trying to modify an existing config. * @throws \LogicException When trying to store an invalid structured config array. + * @return void */ public static function setConfig(string|array $key, ?array $config = null): void { @@ -162,6 +163,7 @@ public static function configured(): array * Remove a configured queue adapter. * * @param string $key The config name to drop. + * @return void */ public static function drop(string $key): void { @@ -172,6 +174,7 @@ public static function drop(string $key): void * Get a queueing engine * * @param string $name Key name of a configured adapter to get. + * @return \Enqueue\SimpleClient\SimpleClient */ public static function engine(string $name): SimpleClient { diff --git a/templates/bake/job.twig b/templates/bake/job.twig index 7c32b34..7dc6873 100644 --- a/templates/bake/job.twig +++ b/templates/bake/job.twig @@ -49,6 +49,7 @@ class {{ name }}Job implements JobInterface * Executes logic for {{ name }}Job * * @param \Cake\Queue\Job\Message $message job message + * @return string|null */ public function execute(Message $message): ?string { diff --git a/tests/Fixture/FailedJobsFixture.php b/tests/Fixture/FailedJobsFixture.php index 26cfcbf..c44743e 100644 --- a/tests/Fixture/FailedJobsFixture.php +++ b/tests/Fixture/FailedJobsFixture.php @@ -16,6 +16,8 @@ class FailedJobsFixture extends TestFixture /** * Init method + * + * @return void */ public function init(): void { diff --git a/tests/TestCase/Command/PurgeFailedCommandTest.php b/tests/TestCase/Command/PurgeFailedCommandTest.php index eb22a53..40af581 100644 --- a/tests/TestCase/Command/PurgeFailedCommandTest.php +++ b/tests/TestCase/Command/PurgeFailedCommandTest.php @@ -29,6 +29,9 @@ class PurgeFailedCommandTest extends TestCase { use ConsoleIntegrationTestTrait; + /** + * @var string[] + */ protected array $fixtures = [ 'plugin.Cake/Queue.FailedJobs', ]; diff --git a/tests/TestCase/Command/RequeueCommandTest.php b/tests/TestCase/Command/RequeueCommandTest.php index bff69fb..5887b51 100644 --- a/tests/TestCase/Command/RequeueCommandTest.php +++ b/tests/TestCase/Command/RequeueCommandTest.php @@ -34,6 +34,9 @@ class RequeueCommandTest extends TestCase use ConsoleIntegrationTestTrait; use QueueTestTrait; + /** + * @var string[] + */ protected array $fixtures = [ 'plugin.Cake/Queue.FailedJobs', ]; diff --git a/tests/TestCase/Command/WorkerCommandTest.php b/tests/TestCase/Command/WorkerCommandTest.php index d0bad67..5b8efb3 100644 --- a/tests/TestCase/Command/WorkerCommandTest.php +++ b/tests/TestCase/Command/WorkerCommandTest.php @@ -142,6 +142,7 @@ public function testQueueProcessesWithLogger() /** * Data provider for testQueueProcessesJob method + * @return array|string[]>> */ public static function dataProviderCallableTypes(): array { diff --git a/tests/TestCase/Listener/FailedJobsListenerTest.php b/tests/TestCase/Listener/FailedJobsListenerTest.php index ab181a0..d5a56e9 100644 --- a/tests/TestCase/Listener/FailedJobsListenerTest.php +++ b/tests/TestCase/Listener/FailedJobsListenerTest.php @@ -39,6 +39,9 @@ class FailedJobsListenerTest extends TestCase { use QueueTestTrait; + /** + * @var string[] + */ protected array $fixtures = [ 'plugin.Cake/Queue.FailedJobs', ]; diff --git a/tests/TestCase/Queue/ProcessorTest.php b/tests/TestCase/Queue/ProcessorTest.php index ccbdc36..ff57b0b 100644 --- a/tests/TestCase/Queue/ProcessorTest.php +++ b/tests/TestCase/Queue/ProcessorTest.php @@ -39,6 +39,8 @@ class ProcessorTest extends TestCase /** * Data provider for testProcess method + * + * @return array */ public static function dataProviderTestProcess(): array { diff --git a/tests/TestCase/QueueTestTrait.php b/tests/TestCase/QueueTestTrait.php index a15fef9..f24f205 100644 --- a/tests/TestCase/QueueTestTrait.php +++ b/tests/TestCase/QueueTestTrait.php @@ -37,6 +37,8 @@ trait QueueTestTrait * This is automatically called after each test via the #[After] attribute. * It drops all QueueManager configs and their associated cache configs, * and resets all log configurations. + * + * @return void */ #[After] public function cleanupQueueManagerConfigs(): void @@ -63,6 +65,7 @@ public function cleanupQueueManagerConfigs(): void * Assert that a message was found in debug logs * * @param string $expected The message to search for in logs + * @return void */ protected function assertDebugLogContains($expected): void { @@ -76,6 +79,7 @@ protected function assertDebugLogContains($expected): void * * @param string $expected The message to search for in logs * @param int $times The exact number of times the message should appear + * @return void */ protected function assertDebugLogContainsExactly($expected, $times): void { @@ -90,7 +94,7 @@ protected function assertDebugLogContainsExactly($expected, $times): void * @param string $search The message to search for * @return int The number of times the message was found */ - protected function debugLogCount($search) + protected function debugLogCount($search): int { $log = Log::engine('debug'); $found = 0; diff --git a/tests/comparisons/JobTask.php b/tests/comparisons/JobTask.php index f1e89ae..822a677 100644 --- a/tests/comparisons/JobTask.php +++ b/tests/comparisons/JobTask.php @@ -16,6 +16,7 @@ class UploadJob implements JobInterface * Executes logic for UploadJob * * @param \Cake\Queue\Job\Message $message job message + * @return string|null */ public function execute(Message $message): ?string { diff --git a/tests/comparisons/JobTaskWithMaxAttempts.php b/tests/comparisons/JobTaskWithMaxAttempts.php index ce5f606..d8f4c91 100644 --- a/tests/comparisons/JobTaskWithMaxAttempts.php +++ b/tests/comparisons/JobTaskWithMaxAttempts.php @@ -23,6 +23,7 @@ class UploadJob implements JobInterface * Executes logic for UploadJob * * @param \Cake\Queue\Job\Message $message job message + * @return string|null */ public function execute(Message $message): ?string { diff --git a/tests/comparisons/JobTaskWithUnique.php b/tests/comparisons/JobTaskWithUnique.php index 2b9aa8a..f0faf36 100644 --- a/tests/comparisons/JobTaskWithUnique.php +++ b/tests/comparisons/JobTaskWithUnique.php @@ -23,6 +23,7 @@ class UploadJob implements JobInterface * Executes logic for UploadJob * * @param \Cake\Queue\Job\Message $message job message + * @return string|null */ public function execute(Message $message): ?string { diff --git a/tests/test_app/src/TestProcessor.php b/tests/test_app/src/TestProcessor.php index ebd12b4..39a9cbf 100644 --- a/tests/test_app/src/TestProcessor.php +++ b/tests/test_app/src/TestProcessor.php @@ -16,6 +16,7 @@ class TestProcessor * * @param Message $message The message to process * @throws Exception + * @return null */ public static function processAndThrowException(Message $message) { @@ -26,6 +27,7 @@ public static function processAndThrowException(Message $message) * Job to be used in test testProcessMessageCallableIsString * * @param \Cake\Queue\Message $message The message to process + * @return null */ public static function processReturnAck(Message $message) { @@ -38,6 +40,7 @@ public static function processReturnAck(Message $message) * Job to be used in test testProcessMessageCallableIsString * * @param \Cake\Queue\Job\Message $message The message to process + * @return null */ public static function processReturnNull(Message $message) { @@ -50,6 +53,7 @@ public static function processReturnNull(Message $message) * Job to be used in test testProcessMessageCallableIsString * * @param \Cake\Queue\Message $message The message to process + * @return null */ public static function processReturnReject(Message $message) { @@ -62,6 +66,7 @@ public static function processReturnReject(Message $message) * Job to be used in test testProcessMessageCallableIsString * * @param \Cake\Queue\Message $message The message to process + * @return null */ public static function processReturnRequeue(Message $message) { @@ -74,6 +79,7 @@ public static function processReturnRequeue(Message $message) * Job to be used in test testProcessMessageCallableIsString * * @param \Cake\Queue\Message $message The message to process + * @return null */ public static function processReturnString(Message $message) { diff --git a/tests/test_app/src/WelcomeMailerListener.php b/tests/test_app/src/WelcomeMailerListener.php index 75f731d..243c2b5 100644 --- a/tests/test_app/src/WelcomeMailerListener.php +++ b/tests/test_app/src/WelcomeMailerListener.php @@ -25,6 +25,9 @@ */ class WelcomeMailerListener implements EventListenerInterface { + /** + * @return array{} + */ public function implementedEvents(): array { return []; From 64238476c43521e48dc1a9ccb84344da6bd21035 Mon Sep 17 00:00:00 2001 From: Jasper Smet Date: Thu, 23 Oct 2025 14:52:40 +0200 Subject: [PATCH 4/4] Fix rector rule --- rector.php | 4 ++++ src/Mailer/Transport/QueueTransport.php | 1 - tests/TestCase/Command/WorkerCommandTest.php | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/rector.php b/rector.php index 3409996..330dc43 100644 --- a/rector.php +++ b/rector.php @@ -7,6 +7,7 @@ use Rector\DeadCode\Rector\ClassMethod\RemoveNullTagValueNodeRector; use Rector\DeadCode\Rector\ClassMethod\RemoveUselessReturnTagRector; use Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector; +use Rector\TypeDeclarationDocblocks\Rector\ClassMethod\DocblockReturnArrayFromDirectArrayInstanceRector; use Rector\ValueObject\PhpVersion; return RectorConfig::configure() @@ -21,6 +22,9 @@ MakeInheritedMethodVisibilitySameAsParentRector::class, RemoveNullTagValueNodeRector::class, RemoveUselessReturnTagRector::class, + DocblockReturnArrayFromDirectArrayInstanceRector::class => [ + __DIR__ . '/src/Mailer/Transport/QueueTransport.php', + ], ]) ->withParallel() ->withPreparedSets( diff --git a/src/Mailer/Transport/QueueTransport.php b/src/Mailer/Transport/QueueTransport.php index cc19d7d..da45783 100644 --- a/src/Mailer/Transport/QueueTransport.php +++ b/src/Mailer/Transport/QueueTransport.php @@ -36,7 +36,6 @@ class QueueTransport extends AbstractTransport /** * @inheritDoc - * @return array */ public function send(Message $message): array { diff --git a/tests/TestCase/Command/WorkerCommandTest.php b/tests/TestCase/Command/WorkerCommandTest.php index 5b8efb3..f77552d 100644 --- a/tests/TestCase/Command/WorkerCommandTest.php +++ b/tests/TestCase/Command/WorkerCommandTest.php @@ -142,6 +142,7 @@ public function testQueueProcessesWithLogger() /** * Data provider for testQueueProcessesJob method + * * @return array|string[]>> */ public static function dataProviderCallableTypes(): array