diff --git a/.phive/phars.xml b/.phive/phars.xml index 1f56b2b..f5aa330 100644 --- a/.phive/phars.xml +++ b/.phive/phars.xml @@ -1,5 +1,4 @@ - - + diff --git a/composer.json b/composer.json index a9fb670..fa2db36 100644 --- a/composer.json +++ b/composer.json @@ -61,14 +61,9 @@ ], "cs-check": "phpcs --colors -p src/ tests/", "cs-fix": "phpcbf --colors -p src/ tests/", - "stan": [ - "@phpstan", - "@psalm" - ], + "stan": "@phpstan", "phpstan": "tools/phpstan analyse", - "psalm": "tools/psalm --show-info=false", "stan-baseline": "tools/phpstan --generate-baseline", - "psalm-baseline": "tools/psalm --set-baseline=psalm-baseline.xml", "stan-setup": "phive install", "test": "phpunit", "test-coverage": "phpunit --coverage-clover=clover.xml" diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon new file mode 100644 index 0000000..b2d742e --- /dev/null +++ b/phpstan-baseline.neon @@ -0,0 +1,7 @@ +parameters: + ignoreErrors: + - + message: '#^Parameter \#1 \$callback of static method Closure\:\:fromCallable\(\) expects callable\(\)\: mixed, array\{mixed, string\} given\.$#' + identifier: argument.type + count: 1 + path: src/Job/Message.php diff --git a/phpstan.neon b/phpstan.neon index 621db66..82f9a15 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,12 +1,14 @@ +includes: + - phpstan-baseline.neon + parameters: level: 8 - checkMissingIterableValueType: false - checkGenericClassInNonGenericObjectType: false treatPhpDocTypesAsCertain: false bootstrapFiles: - tests/bootstrap.php paths: - src/ ignoreErrors: - - '#Parameter \#1 \$callback of static method Closure::fromCallable\(\) expects callable\(\): mixed, array\{mixed, string\} given.#' - - '#Method Cake\\Queue\\Job\\Message::getTarget\(\) should return array\{class-string, string\} but returns non-empty-array.#' + - identifier: missingType.iterableValue + - identifier: missingType.generics + - identifier: trait.unused diff --git a/psalm-baseline.xml b/psalm-baseline.xml deleted file mode 100644 index 396c873..0000000 --- a/psalm-baseline.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/psalm.xml b/psalm.xml deleted file mode 100644 index b231aa7..0000000 --- a/psalm.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/src/Command/RequeueCommand.php b/src/Command/RequeueCommand.php index de6cb88..b9efd02 100644 --- a/src/Command/RequeueCommand.php +++ b/src/Command/RequeueCommand.php @@ -138,7 +138,7 @@ public function execute(Arguments $args, ConsoleIo $io): void 'config' => $failedJob->config, 'priority' => $failedJob->priority, 'queue' => $failedJob->queue, - ] + ], ); $failedJobsTable->deleteOrFail($failedJob); diff --git a/src/Command/WorkerCommand.php b/src/Command/WorkerCommand.php index f97148b..6541f19 100644 --- a/src/Command/WorkerCommand.php +++ b/src/Command/WorkerCommand.php @@ -110,7 +110,7 @@ public function getOptionParser(): ConsoleOptionParser 'short' => 'a', ]); $parser->setDescription( - 'Runs a queue worker that consumes from the named queue.' + 'Runs a queue worker that consumes from the named queue.', ); return $parser; diff --git a/src/Consumption/LimitAttemptsExtension.php b/src/Consumption/LimitAttemptsExtension.php index 3d2da34..c3a0af6 100644 --- a/src/Consumption/LimitAttemptsExtension.php +++ b/src/Consumption/LimitAttemptsExtension.php @@ -65,7 +65,7 @@ public function onResult(MessageResult $context): void if ($attemptNumber >= $maxAttempts) { $context->changeResult( - Result::reject(sprintf('The maximum number of %d allowed attempts was reached.', $maxAttempts)) + Result::reject(sprintf('The maximum number of %d allowed attempts was reached.', $maxAttempts)), ); $exception = (string)$message->getProperty('jobException'); @@ -73,7 +73,7 @@ public function onResult(MessageResult $context): void $this->dispatchEvent( 'Consumption.LimitAttemptsExtension.failed', ['exception' => $exception, 'logger' => $context->getLogger()], - $jobMessage + $jobMessage, ); return; @@ -88,7 +88,7 @@ public function onResult(MessageResult $context): void $producer->send($consumer->getQueue(), $newMessage); $context->changeResult( - Result::reject('A copy of the message was sent with an incremented attempt count.') + Result::reject('A copy of the message was sent with an incremented attempt count.'), ); } } diff --git a/src/Consumption/LimitConsumedMessagesExtension.php b/src/Consumption/LimitConsumedMessagesExtension.php index 680f8b4..e202fbe 100644 --- a/src/Consumption/LimitConsumedMessagesExtension.php +++ b/src/Consumption/LimitConsumedMessagesExtension.php @@ -79,7 +79,7 @@ protected function shouldBeStopped(LoggerInterface $logger): bool $logger->debug(sprintf( '[LimitConsumedMessagesExtension] Message consumption is interrupted since the message limit ' . 'reached. limit: "%s"', - $this->messageLimit + $this->messageLimit, )); return true; diff --git a/src/Consumption/RemoveUniqueJobIdFromCacheExtension.php b/src/Consumption/RemoveUniqueJobIdFromCacheExtension.php index 9aeb8d5..74ff3ad 100644 --- a/src/Consumption/RemoveUniqueJobIdFromCacheExtension.php +++ b/src/Consumption/RemoveUniqueJobIdFromCacheExtension.php @@ -39,7 +39,6 @@ public function onResult(MessageResult $context): void [$class, $method] = $jobMessage->getTarget(); - /** @psalm-suppress InvalidPropertyFetch */ if (empty($class::$shouldBeUnique)) { return; } diff --git a/src/Job/Message.php b/src/Job/Message.php index 5627b74..7da6218 100644 --- a/src/Job/Message.php +++ b/src/Job/Message.php @@ -104,17 +104,17 @@ public function getCallable(): Closure * Get the target class and method. * * @return array{string, string} - * @psalm-return array{class-string, string} + * @phpstan-return array{class-string, string} */ public function getTarget(): array { - /** @var array|null $target */ + /** @var array{class-string, string}|null $target */ $target = $this->parsedBody['class'] ?? null; if (!is_array($target) || count($target) !== 2) { throw new RuntimeException(sprintf( 'Message class should be in the form `[class, method]` got `%s`', - json_encode($target) + json_encode($target), )); } @@ -153,7 +153,6 @@ public function getMaxAttempts(): ?int $class = $target[0]; - /** @psalm-suppress InvalidPropertyFetch */ return $class::$maxAttempts ?? null; } diff --git a/src/Listener/FailedJobsListener.php b/src/Listener/FailedJobsListener.php index 1064f37..f60d15e 100644 --- a/src/Listener/FailedJobsListener.php +++ b/src/Listener/FailedJobsListener.php @@ -83,7 +83,7 @@ public function storeFailedJob(object $event): void throw new RuntimeException( sprintf('`logger` was not defined on %s event.', $event->getName()), 0, - $e + $e, ); } @@ -91,7 +91,7 @@ public function storeFailedJob(object $event): void throw new RuntimeException( sprintf('`logger` is not an instance of `LoggerInterface` on %s event.', $event->getName()), 0, - $e + $e, ); } diff --git a/src/Mailer/Transport/QueueTransport.php b/src/Mailer/Transport/QueueTransport.php index 8c7688b..c798d53 100644 --- a/src/Mailer/Transport/QueueTransport.php +++ b/src/Mailer/Transport/QueueTransport.php @@ -54,7 +54,7 @@ public function send(Message $message): array 'returnPath', 'cc', 'bcc', - ] + ], ); return ['headers' => $headers, 'message' => 'Message has been enqueued']; @@ -72,7 +72,7 @@ protected function enqueueJob(array $data, array $options): void QueueManager::push( [SendMailJob::class, 'execute'], $data, - $options + $options, ); } diff --git a/src/Plugin.php b/src/Plugin.php index 413fb5c..d607ef0 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -53,7 +53,7 @@ public function bootstrap(PluginApplicationInterface $app): void if (!Configure::read('Queue')) { throw new InvalidArgumentException( 'Missing `Queue` configuration key, please check the CakePHP Queue documentation' . - ' to complete the plugin setup.' + ' to complete the plugin setup.', ); } diff --git a/src/QueueManager.php b/src/QueueManager.php index 664ec31..aac4739 100644 --- a/src/QueueManager.php +++ b/src/QueueManager.php @@ -228,11 +228,10 @@ public static function push(string|array $className, array $data = [], array $op $logger = $config['logger'] ? Log::engine($config['logger']) : null; - /** @psalm-suppress InvalidPropertyFetch */ 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.", ); } @@ -241,7 +240,7 @@ public static function push(string|array $className, array $data = [], array $op if (Cache::read($uniqueId, $config['uniqueCacheKey'])) { if ($logger) { $logger->debug( - "An identical instance of $class already exists on the queue. This push will be ignored." + "An identical instance of $class already exists on the queue. This push will be ignored.", ); } @@ -277,7 +276,6 @@ public static function push(string|array $className, array $data = [], array $op $client = static::engine($name); $client->sendEvent($queue, $message); - /** @psalm-suppress InvalidPropertyFetch */ if (!empty($class::$shouldBeUnique)) { $uniqueId = static::getUniqueId($class, $method, $data); diff --git a/tests/TestCase/Job/MailerJobTest.php b/tests/TestCase/Job/MailerJobTest.php index 112a69d..9a617b9 100644 --- a/tests/TestCase/Job/MailerJobTest.php +++ b/tests/TestCase/Job/MailerJobTest.php @@ -71,7 +71,7 @@ public function testExecute() ->with( $this->equalTo('welcome'), $this->equalTo($this->args), - $this->equalTo($this->headers) + $this->equalTo($this->headers), ) ->willReturn(['Message sent']); @@ -79,7 +79,7 @@ public function testExecute() ->method('getMailer') ->with( $this->equalTo('SampleTest'), - $this->equalTo($this->mailerConfig) + $this->equalTo($this->mailerConfig), )->willReturn($this->mailer); $message = $this->createMessage(); @@ -101,7 +101,7 @@ public function testExecuteMissingMailerException() ->method('getMailer') ->with( $this->equalTo('SampleTest'), - $this->equalTo($this->mailerConfig) + $this->equalTo($this->mailerConfig), )->willThrowException(new MissingMailerException('Missing mailer for testExecuteMissingMailerException')); $message = $this->createMessage(); @@ -121,7 +121,7 @@ public function testExecuteBadMethodCallException() ->with( $this->equalTo('welcome'), $this->equalTo($this->args), - $this->equalTo($this->headers) + $this->equalTo($this->headers), ) ->willThrowException(new BadMethodCallException('Welcome is not a valid method')); @@ -129,7 +129,7 @@ public function testExecuteBadMethodCallException() ->method('getMailer') ->with( $this->equalTo('SampleTest'), - $this->equalTo($this->mailerConfig) + $this->equalTo($this->mailerConfig), )->willReturn($this->mailer); $message = $this->createMessage(); diff --git a/tests/TestCase/Listener/FailedJobsListenerTest.php b/tests/TestCase/Listener/FailedJobsListenerTest.php index b126260..9a9a71c 100644 --- a/tests/TestCase/Listener/FailedJobsListenerTest.php +++ b/tests/TestCase/Listener/FailedJobsListenerTest.php @@ -76,7 +76,7 @@ public function testFailedJobIsAddedWhenEventIsFired() $event = new Event( 'Consumption.LimitAttemptsExtension.failed', $message, - ['exception' => 'some message'] + ['exception' => 'some message'], ); /** @var \Cake\Queue\Model\Table\FailedJobsTable $failedJobsTable */ @@ -160,7 +160,7 @@ public function testStoreFailedJobException($eventData, $exceptionMessage) $event = new Event( 'Consumption.LimitAttemptsExtension.failed', $message, - $eventData + $eventData, ); $this->expectException(RuntimeException::class); diff --git a/tests/TestCase/Mailer/Transport/QueueTransportTest.php b/tests/TestCase/Mailer/Transport/QueueTransportTest.php index 6539e0b..61ff9a5 100644 --- a/tests/TestCase/Mailer/Transport/QueueTransportTest.php +++ b/tests/TestCase/Mailer/Transport/QueueTransportTest.php @@ -67,7 +67,7 @@ public function testSend() 'returnPath', 'cc', 'bcc', - ] + ], ); $expected = ['headers' => $headers, 'message' => 'Message has been enqueued']; @@ -93,7 +93,7 @@ public function testSendCustomTransport() 'queue' => 'default', 'url' => $this->getFsQueueUrl(), ]); - $message = (new Message()); + $message = new Message(); $transport = new QueueTransport([ 'transport' => SmtpTransport::class, @@ -124,7 +124,7 @@ public function testSendBcTransport() 'queue' => 'default', 'url' => $this->getFsQueueUrl(), ]); - $message = (new Message()); + $message = new Message(); $transport = new QueueTransport([ 'transport' => SmtpTransport::class, diff --git a/tests/TestCase/Task/JobTaskTest.php b/tests/TestCase/Task/JobTaskTest.php index 8236c86..a49324f 100644 --- a/tests/TestCase/Task/JobTaskTest.php +++ b/tests/TestCase/Task/JobTaskTest.php @@ -73,7 +73,7 @@ public function testMain() $this->assertOutputContains('Creating file ' . $this->generatedFile); $this->assertSameAsFile( $this->comparisonDir . 'JobTask.php', - file_get_contents($this->generatedFile) + file_get_contents($this->generatedFile), ); } @@ -87,7 +87,7 @@ public function testMainWithUnique() $this->assertOutputContains('Creating file ' . $this->generatedFile); $this->assertSameAsFile( $this->comparisonDir . 'JobTaskWithUnique.php', - file_get_contents($this->generatedFile) + file_get_contents($this->generatedFile), ); } @@ -101,7 +101,7 @@ public function testMainWithMaxAttempts() $this->assertOutputContains('Creating file ' . $this->generatedFile); $this->assertSameAsFile( $this->comparisonDir . 'JobTaskWithMaxAttempts.php', - file_get_contents($this->generatedFile) + file_get_contents($this->generatedFile), ); } }