Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .phive/phars.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<phive xmlns="https://phar.io/phive">
<phar name="phpstan" version="1.10.56" installed="1.10.56" location="./tools/phpstan" copy="false"/>
<phar name="psalm" version="5.20.0" installed="5.20.0" location="./tools/psalm" copy="false"/>
<phar name="phpstan" version="2.1.17" installed="2.1.17" location="./tools/phpstan" copy="false"/>
</phive>
7 changes: 1 addition & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 7 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -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
10 changes: 6 additions & 4 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -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
3 changes: 0 additions & 3 deletions psalm-baseline.xml

This file was deleted.

28 changes: 0 additions & 28 deletions psalm.xml

This file was deleted.

2 changes: 1 addition & 1 deletion src/Command/RequeueCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public function execute(Arguments $args, ConsoleIo $io): void
'config' => $failedJob->config,
'priority' => $failedJob->priority,
'queue' => $failedJob->queue,
]
],
);

$failedJobsTable->deleteOrFail($failedJob);
Expand Down
2 changes: 1 addition & 1 deletion src/Command/WorkerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/Consumption/LimitAttemptsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ 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');

$this->dispatchEvent(
'Consumption.LimitAttemptsExtension.failed',
['exception' => $exception, 'logger' => $context->getLogger()],
$jobMessage
$jobMessage,
);

return;
Expand All @@ -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.'),
);
}
}
2 changes: 1 addition & 1 deletion src/Consumption/LimitConsumedMessagesExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/Consumption/RemoveUniqueJobIdFromCacheExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public function onResult(MessageResult $context): void

[$class, $method] = $jobMessage->getTarget();

/** @psalm-suppress InvalidPropertyFetch */
if (empty($class::$shouldBeUnique)) {
return;
}
Expand Down
7 changes: 3 additions & 4 deletions src/Job/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
));
}

Expand Down Expand Up @@ -153,7 +153,6 @@ public function getMaxAttempts(): ?int

$class = $target[0];

/** @psalm-suppress InvalidPropertyFetch */
return $class::$maxAttempts ?? null;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Listener/FailedJobsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,15 @@ public function storeFailedJob(object $event): void
throw new RuntimeException(
sprintf('`logger` was not defined on %s event.', $event->getName()),
0,
$e
$e,
);
}

if (!($logger instanceof LoggerInterface)) {
throw new RuntimeException(
sprintf('`logger` is not an instance of `LoggerInterface` on %s event.', $event->getName()),
0,
$e
$e,
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Mailer/Transport/QueueTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function send(Message $message): array
'returnPath',
'cc',
'bcc',
]
],
);

return ['headers' => $headers, 'message' => 'Message has been enqueued'];
Expand All @@ -72,7 +72,7 @@ protected function enqueueJob(array $data, array $options): void
QueueManager::push(
[SendMailJob::class, 'execute'],
$data,
$options
$options,
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
);
}

Expand Down
6 changes: 2 additions & 4 deletions src/QueueManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,10 @@

$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.",

Check warning on line 234 in src/QueueManager.php

View check run for this annotation

Codecov / codecov/patch

src/QueueManager.php#L234

Added line #L234 was not covered by tests
);
}

Expand All @@ -241,7 +240,7 @@
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.",
);
}

Expand Down Expand Up @@ -277,7 +276,6 @@
$client = static::engine($name);
$client->sendEvent($queue, $message);

/** @psalm-suppress InvalidPropertyFetch */
if (!empty($class::$shouldBeUnique)) {
$uniqueId = static::getUniqueId($class, $method, $data);

Expand Down
10 changes: 5 additions & 5 deletions tests/TestCase/Job/MailerJobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ public function testExecute()
->with(
$this->equalTo('welcome'),
$this->equalTo($this->args),
$this->equalTo($this->headers)
$this->equalTo($this->headers),
)
->willReturn(['Message sent']);

$this->job->expects($this->once())
->method('getMailer')
->with(
$this->equalTo('SampleTest'),
$this->equalTo($this->mailerConfig)
$this->equalTo($this->mailerConfig),
)->willReturn($this->mailer);

$message = $this->createMessage();
Expand All @@ -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();
Expand All @@ -121,15 +121,15 @@ 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'));

$this->job->expects($this->once())
->method('getMailer')
->with(
$this->equalTo('SampleTest'),
$this->equalTo($this->mailerConfig)
$this->equalTo($this->mailerConfig),
)->willReturn($this->mailer);

$message = $this->createMessage();
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/Listener/FailedJobsListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -160,7 +160,7 @@ public function testStoreFailedJobException($eventData, $exceptionMessage)
$event = new Event(
'Consumption.LimitAttemptsExtension.failed',
$message,
$eventData
$eventData,
);

$this->expectException(RuntimeException::class);
Expand Down
6 changes: 3 additions & 3 deletions tests/TestCase/Mailer/Transport/QueueTransportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function testSend()
'returnPath',
'cc',
'bcc',
]
],
);

$expected = ['headers' => $headers, 'message' => 'Message has been enqueued'];
Expand All @@ -93,7 +93,7 @@ public function testSendCustomTransport()
'queue' => 'default',
'url' => $this->getFsQueueUrl(),
]);
$message = (new Message());
$message = new Message();

$transport = new QueueTransport([
'transport' => SmtpTransport::class,
Expand Down Expand Up @@ -124,7 +124,7 @@ public function testSendBcTransport()
'queue' => 'default',
'url' => $this->getFsQueueUrl(),
]);
$message = (new Message());
$message = new Message();

$transport = new QueueTransport([
'transport' => SmtpTransport::class,
Expand Down
6 changes: 3 additions & 3 deletions tests/TestCase/Task/JobTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
);
}

Expand All @@ -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),
);
}

Expand All @@ -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),
);
}
}