From 35a92355e9d0a064727212d3b8ff5e839014c32d Mon Sep 17 00:00:00 2001 From: Mark Scherer Date: Sun, 24 May 2026 19:00:09 +0200 Subject: [PATCH 1/8] Apply conservative Rector cleanup --- src/Command/AddCommand.php | 2 +- src/Command/BakeQueueTaskCommand.php | 8 +++--- src/Command/InfoCommand.php | 2 +- src/Controller/Admin/LoadHelperTrait.php | 6 +---- src/Controller/Admin/QueueAppController.php | 2 -- src/Controller/Admin/QueueController.php | 27 +++---------------- .../Admin/QueueProcessesController.php | 8 +++--- src/Controller/Admin/QueuedJobsController.php | 22 +++++++-------- src/Generator/Task/QueuedJobTask.php | 5 ++-- src/Mailer/Transport/SimpleQueueTransport.php | 2 +- src/Model/Behavior/JsonableBehavior.php | 10 +++---- src/Model/Table/QueuedJobsTable.php | 11 ++++---- src/Queue/Config.php | 2 +- src/Queue/Processor.php | 20 +++++--------- src/Queue/Task.php | 2 +- src/Queue/Task/EmailTask.php | 2 +- src/Queue/Task/ExecuteTask.php | 6 +---- src/Queue/Task/MonitorExampleTask.php | 2 +- src/Queue/Task/ProgressExampleTask.php | 2 +- src/Queue/TaskFinder.php | 2 +- src/View/Helper/QueueHelper.php | 21 +++------------ tests/TestCase/Command/RunCommandTest.php | 2 +- .../Controller/Admin/QueueControllerTest.php | 2 +- .../Admin/QueuedJobsControllerTest.php | 2 +- .../Model/Table/QueuedJobsTableTest.php | 12 ++++----- tests/TestCase/Queue/ProcessorTest.php | 2 +- tests/TestCase/Queue/Task/EmailTaskTest.php | 2 +- .../View/Helper/QueueProgressHelperTest.php | 2 +- tests/bootstrap.php | 2 +- tests/schema.php | 2 +- 30 files changed, 67 insertions(+), 125 deletions(-) diff --git a/src/Command/AddCommand.php b/src/Command/AddCommand.php index dc68fcd0..6aae0932 100644 --- a/src/Command/AddCommand.php +++ b/src/Command/AddCommand.php @@ -59,7 +59,7 @@ public function execute(Arguments $args, ConsoleIo $io) { $taskName = $args->getArgument('task'); if (!$taskName) { $io->out(count($tasks) . ' tasks available:'); - foreach ($tasks as $task => $className) { + foreach (array_keys($tasks) as $task) { $io->out(' - ' . $task); } diff --git a/src/Command/BakeQueueTaskCommand.php b/src/Command/BakeQueueTaskCommand.php index 1ae64f98..7296f7fe 100644 --- a/src/Command/BakeQueueTaskCommand.php +++ b/src/Command/BakeQueueTaskCommand.php @@ -86,12 +86,12 @@ protected function generateTaskTestContent(string $name, string $namespace): str } $taskClassNamespace = $namespace . '\Queue\\Task\\' . str_replace(DS, '\\', $name); - if (strpos($name, '/') !== false) { + if (str_contains($name, '/')) { $parts = explode('/', $name); $name = array_pop($parts); } - $content = <<getAddableTasks(); $io->out(count($tasks) . ' tasks available:'); - foreach ($tasks as $task => $className) { + foreach (array_keys($tasks) as $task) { if (array_key_exists($task, $addableTasks)) { $task .= ' [addable via CLI]'; } diff --git a/src/Controller/Admin/LoadHelperTrait.php b/src/Controller/Admin/LoadHelperTrait.php index a1337169..f40d6814 100644 --- a/src/Controller/Admin/LoadHelperTrait.php +++ b/src/Controller/Admin/LoadHelperTrait.php @@ -28,11 +28,7 @@ protected function loadHelpers(): void { } // Configure helper: prefer Shim, fallback to Queue's own - if (Plugin::isLoaded('Shim')) { - $helpers[] = 'Shim.Configure'; - } else { - $helpers[] = 'Queue.Configure'; - } + $helpers[] = Plugin::isLoaded('Shim') ? 'Shim.Configure' : 'Queue.Configure'; if (Configure::read('Icon.sets') && class_exists(IconHelper::class)) { $helpers[] = 'Templating.Icon'; diff --git a/src/Controller/Admin/QueueAppController.php b/src/Controller/Admin/QueueAppController.php index 9f156db8..13f0d3a6 100644 --- a/src/Controller/Admin/QueueAppController.php +++ b/src/Controller/Admin/QueueAppController.php @@ -111,8 +111,6 @@ public function beforeFilter(EventInterface $event): void { try { $allowed = $gate($this->request) === true; - } catch (ForbiddenException $e) { - throw $e; } catch (Throwable $e) { Log::warning(sprintf('Queue.adminAccess threw %s: %s', $e::class, $e->getMessage())); diff --git a/src/Controller/Admin/QueueController.php b/src/Controller/Admin/QueueController.php index 56035a10..e82a4603 100644 --- a/src/Controller/Admin/QueueController.php +++ b/src/Controller/Admin/QueueController.php @@ -118,28 +118,7 @@ public function index() { $configurations = (array)Configure::read('Queue'); - $this->set(compact( - 'new', - 'current', - 'data', - 'pendingDetails', - 'scheduledDetails', - 'pendingDetailsTruncated', - 'scheduledDetailsTruncated', - 'detailsLimit', - 'totalPending', - 'status', - 'tasks', - 'addableTasks', - 'taskDescriptions', - 'servers', - 'workers', - 'pendingJobs', - 'scheduledJobs', - 'runningJobs', - 'failedJobs', - 'configurations', - )); + $this->set(['new' => $new, 'current' => $current, 'data' => $data, 'pendingDetails' => $pendingDetails, 'scheduledDetails' => $scheduledDetails, 'pendingDetailsTruncated' => $pendingDetailsTruncated, 'scheduledDetailsTruncated' => $scheduledDetailsTruncated, 'detailsLimit' => $detailsLimit, 'totalPending' => $totalPending, 'status' => $status, 'tasks' => $tasks, 'addableTasks' => $addableTasks, 'taskDescriptions' => $taskDescriptions, 'servers' => $servers, 'workers' => $workers, 'pendingJobs' => $pendingJobs, 'scheduledJobs' => $scheduledJobs, 'runningJobs' => $runningJobs, 'failedJobs' => $failedJobs, 'configurations' => $configurations]); } /** @@ -249,7 +228,7 @@ public function processes() { $terminated = $QueueProcesses->find()->where(['terminate' => true])->all()->toArray(); $key = $QueueProcesses->buildServerString(); - $this->set(compact('terminated', 'processes', 'key')); + $this->set(['terminated' => $terminated, 'processes' => $processes, 'key' => $key]); } /** @@ -307,7 +286,7 @@ protected function refererRedirect(array|string $default) { if (is_array($url)) { throw new NotFoundException('Invalid array in query string'); } - if ($url && (mb_substr($url, 0, 1) !== '/' || mb_substr($url, 0, 2) === '//')) { + if ($url && (mb_substr((string) $url, 0, 1) !== '/' || mb_substr((string) $url, 0, 2) === '//')) { $url = null; } diff --git a/src/Controller/Admin/QueueProcessesController.php b/src/Controller/Admin/QueueProcessesController.php index 7ad23a82..22b1fb48 100644 --- a/src/Controller/Admin/QueueProcessesController.php +++ b/src/Controller/Admin/QueueProcessesController.php @@ -48,7 +48,7 @@ public function initialize(): void { public function index() { $queueProcesses = $this->paginate(); - $this->set(compact('queueProcesses')); + $this->set(['queueProcesses' => $queueProcesses]); } /** @@ -61,7 +61,7 @@ public function index() { public function view(?int $id = null) { $queueProcess = $this->QueueProcesses->get($id); - $this->set(compact('queueProcess')); + $this->set(['queueProcess' => $queueProcess]); } /** @@ -84,7 +84,7 @@ public function edit(?int $id = null) { $this->Flash->error(__d('queue', 'The queue process could not be saved. Please, try again.')); } - $this->set(compact('queueProcess')); + $this->set(['queueProcess' => $queueProcess]); } /** @@ -100,7 +100,7 @@ public function terminate(?int $id = null) { $queueProcess->terminate = true; $this->QueueProcesses->saveOrFail($queueProcess); $this->Flash->success(__d('queue', 'The queue process has been deleted.')); - } catch (Exception $exception) { + } catch (Exception) { $this->Flash->error(__d('queue', 'The queue process could not be deleted. Please, try again.')); } diff --git a/src/Controller/Admin/QueuedJobsController.php b/src/Controller/Admin/QueuedJobsController.php index ae47f5ab..df2b8d06 100644 --- a/src/Controller/Admin/QueuedJobsController.php +++ b/src/Controller/Admin/QueuedJobsController.php @@ -75,7 +75,7 @@ public function index() { } $queuedJobs = $this->paginate($query); - $this->set(compact('queuedJobs')); + $this->set(['queuedJobs' => $queuedJobs]); if (Configure::read('Queue.isSearchEnabled') !== false && Plugin::isLoaded('Search')) { $jobTypes = $this->QueuedJobs->find()->where()->find( @@ -83,7 +83,7 @@ public function index() { keyField: 'job_task', valueField: 'job_task', )->distinct('job_task')->toArray(); - $this->set(compact('jobTypes')); + $this->set(['jobTypes' => $jobTypes]); } } @@ -112,7 +112,7 @@ public function stats(): void { keyField: 'job_task', valueField: 'job_task', )->distinct('job_task')->toArray(); - $this->set(compact('stats', 'jobTypes', 'jobType')); + $this->set(['stats' => $stats, 'jobTypes' => $jobTypes, 'jobType' => $jobType]); } /** @@ -153,7 +153,7 @@ public function heatmap(): void { valueField: 'job_task', )->distinct('job_task')->toArray(); - $this->set(compact('heatmapData', 'jobTypes', 'jobType', 'metric', 'days')); + $this->set(['heatmapData' => $heatmapData, 'jobTypes' => $jobTypes, 'jobType' => $jobType, 'metric' => $metric, 'days' => $days]); } /** @@ -173,7 +173,7 @@ public function view(?int $id = null) { $this->response = $this->response->withDownload('queued-job-' . $id . '.json'); } - $this->set(compact('queuedJob')); + $this->set(['queuedJob' => $queuedJob]); $this->viewBuilder()->setOption('serialize', ['queuedJob']); } @@ -286,7 +286,7 @@ public function edit(?int $id = null) { $this->Flash->error(__d('queue', 'The queued job could not be saved. Please try again.')); } - $this->set(compact('queuedJob')); + $this->set(['queuedJob' => $queuedJob]); } /** @@ -322,7 +322,7 @@ public function data(?int $id = null) { } } - $this->set(compact('queuedJob')); + $this->set(['queuedJob' => $queuedJob]); } /** @@ -407,7 +407,7 @@ public function test() { $taskFinder = new TaskFinder(); $allTasks = $taskFinder->all(); $tasks = []; - foreach ($allTasks as $task => $className) { + foreach (array_keys($allTasks) as $task) { if (!str_starts_with($task, 'Queue.')) { continue; } @@ -440,7 +440,7 @@ public function test() { $this->Flash->error(__d('queue', 'The job could not be queued. Please try again.')); } - $this->set(compact('tasks', 'queuedJob')); + $this->set(['tasks' => $tasks, 'queuedJob' => $queuedJob]); } /** @@ -458,7 +458,7 @@ public function migrate() { ->toArray(); $tasks = []; - foreach ($allTasks as $task => $className) { + foreach (array_keys($allTasks) as $task) { if (!str_starts_with($task, 'Queue.')) { continue; } @@ -488,7 +488,7 @@ public function migrate() { return $this->redirect(['action' => 'migrate']); } - $this->set(compact('tasks')); + $this->set(['tasks' => $tasks]); } } diff --git a/src/Generator/Task/QueuedJobTask.php b/src/Generator/Task/QueuedJobTask.php index 09d1dcc9..5e9877d5 100644 --- a/src/Generator/Task/QueuedJobTask.php +++ b/src/Generator/Task/QueuedJobTask.php @@ -24,7 +24,7 @@ public function collect(): array { $list = []; $names = $this->collectQueuedJobTasks(); - foreach ($names as $name => $className) { + foreach (array_keys($names) as $name) { $list[$name] = "'$name'"; } @@ -44,9 +44,8 @@ public function collect(): array { */ protected function collectQueuedJobTasks(): array { $taskFinder = new TaskFinder(); - $tasks = $taskFinder->all(); - return $tasks; + return $taskFinder->all(); } } diff --git a/src/Mailer/Transport/SimpleQueueTransport.php b/src/Mailer/Transport/SimpleQueueTransport.php index 9c6fb1de..89ce6301 100644 --- a/src/Mailer/Transport/SimpleQueueTransport.php +++ b/src/Mailer/Transport/SimpleQueueTransport.php @@ -58,7 +58,7 @@ public function send(Message $message): array { foreach ($settings as $setting => $value) { /** @phpstan-ignore-next-line */ - if (array_key_exists(0, $value) && ($value[0] === null || $value[0] === [])) { + if ($value[0] === null || $value[0] === []) { unset($settings[$setting]); } } diff --git a/src/Model/Behavior/JsonableBehavior.php b/src/Model/Behavior/JsonableBehavior.php index 9b875eeb..41395b67 100644 --- a/src/Model/Behavior/JsonableBehavior.php +++ b/src/Model/Behavior/JsonableBehavior.php @@ -172,14 +172,12 @@ protected function _getMappedFields() { * @return string|null */ public function _encode($val) { - if (!empty($this->_config['fields'])) { - if ($this->_config['input'] === 'json') { - if (!is_string($val)) { + if (!empty($this->_config['fields']) && $this->_config['input'] === 'json') { + if (!is_string($val)) { throw new InvalidArgumentException('Only accepts JSON string for input type `json`'); } - $val = $this->_fromJson($val); - } - } + $val = $this->_fromJson($val); + } if (!is_array($val)) { return null; } diff --git a/src/Model/Table/QueuedJobsTable.php b/src/Model/Table/QueuedJobsTable.php index 077a3e5d..aa3b7146 100644 --- a/src/Model/Table/QueuedJobsTable.php +++ b/src/Model/Table/QueuedJobsTable.php @@ -267,7 +267,7 @@ public function createJob(string $jobTask, array|object|null $data = null, array * @return string */ protected function jobTask(string $jobType): string { - if ($this->taskFinder === null) { + if (!$this->taskFinder instanceof \Queue\Queue\TaskFinder) { $this->taskFinder = new TaskFinder(); } @@ -981,7 +981,7 @@ public function getHeatmapData(string $field = 'created', int $days = 30, ?strin // MySQL DAYOFWEEK returns 1=Sunday, 2=Monday, etc. Adjust to 0=Sunday if ($driverName === static::DRIVER_MYSQL) { - $day = $day - 1; + $day -= 1; } // Ensure day is in valid range (0-6) @@ -1260,10 +1260,9 @@ public function truncate(): void { * @return string */ protected function getDriverName(): string { - $className = explode('\\', $this->getConnection()->config()['driver']); - $name = end($className) ?: ''; + $className = explode('\\', (string) $this->getConnection()->config()['driver']); - return $name; + return end($className) ?: ''; } /** @@ -1277,7 +1276,7 @@ protected function addFilter(array $conditions, string $key, array $values): arr $include = []; $exclude = []; foreach ($values as $value) { - if (substr($value, 0, 1) === '-') { + if (str_starts_with($value, '-')) { $exclude[] = substr($value, 1); } else { $include[] = $value; diff --git a/src/Queue/Config.php b/src/Queue/Config.php index baa4a2c5..0fd209ec 100644 --- a/src/Queue/Config.php +++ b/src/Queue/Config.php @@ -27,7 +27,7 @@ public static function defaultworkertimeout(): int { ); } } - $timeout = $timeout ?? 600; // 10min default + $timeout ??= 600; // 10min default if ($timeout <= 0) { throw new InvalidArgumentException('Queue.defaultRequeueTimeout (or deprecated defaultworkertimeout) is less or equal than zero. Indefinite running of jobs is not supported.'); diff --git a/src/Queue/Processor.php b/src/Queue/Processor.php index 6c75ca58..36b2412d 100644 --- a/src/Queue/Processor.php +++ b/src/Queue/Processor.php @@ -198,10 +198,10 @@ public function run(array $args): int { pcntl_async_signals(true); } if (function_exists('pcntl_signal')) { - pcntl_signal(SIGTERM, [&$this, 'exit']); - pcntl_signal(SIGINT, [&$this, 'abort']); - pcntl_signal(SIGTSTP, [&$this, 'abort']); - pcntl_signal(SIGQUIT, [&$this, 'abort']); + pcntl_signal(SIGTERM, $this->exit(...)); + pcntl_signal(SIGINT, $this->abort(...)); + pcntl_signal(SIGTSTP, $this->abort(...)); + pcntl_signal(SIGQUIT, $this->abort(...)); if (Configure::read('Queue.canInterruptSleep')) { // Defining a signal handler here will make the worker wake up // from its sleep() when SIGUSR1 is received. Since waking it @@ -222,12 +222,12 @@ public function run(array $args): int { try { $this->updatePid($pid); - } catch (RecordNotFoundException $exception) { + } catch (RecordNotFoundException) { // Manually killed $this->exit = true; continue; - } catch (ProcessEndingException $exception) { + } catch (ProcessEndingException) { // Soft killed, e.g. during deploy update $this->exit = true; @@ -533,13 +533,7 @@ protected function initPid(): string { * @return string */ protected function retrievePid(): string { - if (function_exists('posix_getpid')) { - $pid = (string)posix_getpid(); - } else { - $pid = $this->QueuedJobs->key(); - } - - return $pid; + return function_exists('posix_getpid') ? (string)posix_getpid() : $this->QueuedJobs->key(); } /** diff --git a/src/Queue/Task.php b/src/Queue/Task.php index 60d9a05b..35e14f28 100644 --- a/src/Queue/Task.php +++ b/src/Queue/Task.php @@ -98,7 +98,7 @@ public function __construct(?Io $io = null, ?LoggerInterface $logger = null) { $QueuedJobs = $tableLocator->get($this->queueModelClass); $this->QueuedJobs = $QueuedJobs; - if (isset($this->defaultTable)) { + if (property_exists($this, 'defaultTable') && $this->defaultTable !== null) { $this->fetchTable(); } } diff --git a/src/Queue/Task/EmailTask.php b/src/Queue/Task/EmailTask.php index e01298ea..5bb5f528 100644 --- a/src/Queue/Task/EmailTask.php +++ b/src/Queue/Task/EmailTask.php @@ -205,7 +205,7 @@ public function run(array $data, int $jobId): void { } foreach ($settings as $method => $setting) { - $setter = 'set' . ucfirst($method); + $setter = 'set' . ucfirst((string) $method); if (in_array($method, ['theme', 'template', 'layout'], true)) { call_user_func_array([$this->mailer->viewBuilder(), $setter], (array)$setting); diff --git a/src/Queue/Task/ExecuteTask.php b/src/Queue/Task/ExecuteTask.php index 39b8971b..bd0ffc2b 100644 --- a/src/Queue/Task/ExecuteTask.php +++ b/src/Queue/Task/ExecuteTask.php @@ -106,11 +106,7 @@ public function run(array $data, int $jobId): void { } } - if ($data['escape']) { - $command = escapeshellarg($rawCommand); - } else { - $command = $rawCommand; - } + $command = $data['escape'] ? escapeshellarg($rawCommand) : $rawCommand; if ($data['params']) { $params = $data['params']; diff --git a/src/Queue/Task/MonitorExampleTask.php b/src/Queue/Task/MonitorExampleTask.php index a0400c00..a9c75216 100644 --- a/src/Queue/Task/MonitorExampleTask.php +++ b/src/Queue/Task/MonitorExampleTask.php @@ -102,7 +102,7 @@ protected function getSystemMemInfo(): array { $data = explode("\n", file_get_contents('/proc/meminfo') ?: ''); $meminfo = []; foreach ($data as $line) { - if (strpos($line, ':') === false) { + if (!str_contains($line, ':')) { continue; } [$key, $val] = explode(':', $line); diff --git a/src/Queue/Task/ProgressExampleTask.php b/src/Queue/Task/ProgressExampleTask.php index 81ab7cea..a1e59f9b 100644 --- a/src/Queue/Task/ProgressExampleTask.php +++ b/src/Queue/Task/ProgressExampleTask.php @@ -75,7 +75,7 @@ public function description(): ?string { public function run(array $data, int $jobId): void { $this->io->hr(); $this->io->out('CakePHP Queue ProgressExample task.'); - $seconds = !empty($data['duration']) ? (int)$data['duration'] : 2 * static::MINUTE; + $seconds = empty($data['duration']) ? 2 * static::MINUTE : (int)$data['duration']; $this->io->out('A total of ' . $seconds . ' seconds need to pass...'); for ($i = 0; $i < $seconds; $i++) { diff --git a/src/Queue/TaskFinder.php b/src/Queue/TaskFinder.php index 2582bb6f..a47eadef 100644 --- a/src/Queue/TaskFinder.php +++ b/src/Queue/TaskFinder.php @@ -145,7 +145,7 @@ public function resolve(string $jobTask): string { if (!str_contains($jobTask, '\\')) { // Let's try matching without plugin prefix - foreach ($all as $name => $className) { + foreach (array_keys($all) as $name) { if (!str_contains($name, '.')) { continue; } diff --git a/src/View/Helper/QueueHelper.php b/src/View/Helper/QueueHelper.php index 0a31d67f..a769a6d7 100644 --- a/src/View/Helper/QueueHelper.php +++ b/src/View/Helper/QueueHelper.php @@ -36,11 +36,7 @@ public function hasFailed(QueuedJob $queuedJob): bool { // Requeued $taskConfig = $this->taskConfig($queuedJob->job_task); - if ($taskConfig && $queuedJob->attempts <= $taskConfig['retries']) { - return false; - } - - return true; + return !($taskConfig && $queuedJob->attempts <= $taskConfig['retries']); } /** @@ -85,11 +81,7 @@ public function isRequeued(QueuedJob $queuedJob): bool { } $taskConfig = $this->taskConfig($queuedJob->job_task); - if ($taskConfig && $queuedJob->attempts <= $taskConfig['retries']) { - return true; - } - - return false; + return $taskConfig && $queuedJob->attempts <= $taskConfig['retries']; } /** @@ -111,13 +103,8 @@ public function isRestarted(QueuedJob $queuedJob): bool { if ($queuedJob->attempts < 1) { return false; } - - // Must NOT have a failure_message (it was cleared by reset) - if ($queuedJob->failure_message) { - return false; - } - - return true; + // Must NOT have a failure_message (it was cleared by reset) + return !$queuedJob->failure_message; } /** diff --git a/tests/TestCase/Command/RunCommandTest.php b/tests/TestCase/Command/RunCommandTest.php index f2cef917..98425e1c 100644 --- a/tests/TestCase/Command/RunCommandTest.php +++ b/tests/TestCase/Command/RunCommandTest.php @@ -78,7 +78,7 @@ public function testServiceInjection(): void { */ protected function _needsConnection() { $config = ConnectionManager::getConfig('test'); - $skip = strpos($config['driver'], 'Mysql') === false && strpos($config['driver'], 'Postgres') === false; + $skip = !str_contains((string) $config['driver'], 'Mysql') && !str_contains((string) $config['driver'], 'Postgres'); $this->skipIf($skip, 'Only Mysql/Postgres is working yet for this.'); } diff --git a/tests/TestCase/Controller/Admin/QueueControllerTest.php b/tests/TestCase/Controller/Admin/QueueControllerTest.php index 9ff026fc..6847b937 100644 --- a/tests/TestCase/Controller/Admin/QueueControllerTest.php +++ b/tests/TestCase/Controller/Admin/QueueControllerTest.php @@ -349,7 +349,7 @@ public function testIndexStandalone(): void { */ protected function _needsConnection() { $config = ConnectionManager::getConfig('test'); - $skip = strpos($config['driver'], 'Mysql') === false && strpos($config['driver'], 'Postgres') === false; + $skip = !str_contains((string) $config['driver'], 'Mysql') && !str_contains((string) $config['driver'], 'Postgres'); $this->skipIf($skip, 'Only Mysql/Postgres is working yet for this.'); } diff --git a/tests/TestCase/Controller/Admin/QueuedJobsControllerTest.php b/tests/TestCase/Controller/Admin/QueuedJobsControllerTest.php index 3604a7aa..ecbe36cb 100644 --- a/tests/TestCase/Controller/Admin/QueuedJobsControllerTest.php +++ b/tests/TestCase/Controller/Admin/QueuedJobsControllerTest.php @@ -433,7 +433,7 @@ public function testImport() { */ protected function _needsConnection() { $config = ConnectionManager::getConfig('test'); - $skip = strpos($config['driver'], 'Mysql') === false && strpos($config['driver'], 'Postgres') === false; + $skip = !str_contains((string) $config['driver'], 'Mysql') && !str_contains((string) $config['driver'], 'Postgres'); $this->skipIf($skip, 'Only Mysql/Postgres is working yet for this.'); } diff --git a/tests/TestCase/Model/Table/QueuedJobsTableTest.php b/tests/TestCase/Model/Table/QueuedJobsTableTest.php index 8f65f0b3..a6ded010 100644 --- a/tests/TestCase/Model/Table/QueuedJobsTableTest.php +++ b/tests/TestCase/Model/Table/QueuedJobsTableTest.php @@ -321,12 +321,10 @@ public function testSequence() { } /** - * Test creating Jobs to run close to a specified time, and strtotime parsing. - * Using toUnixString() function to convert Time object to timestamp, instead of strtotime - * - * @return null - */ - public function testNotBefore() { + * Test creating Jobs to run close to a specified time, and strtotime parsing. + * Using toUnixString() function to convert Time object to timestamp, instead of strtotime + */ + public function testNotBefore() { $this->assertTrue((bool)$this->QueuedJobs->createJob('Foo', null, ['notBefore' => '+ 1 Min'])); $this->assertTrue((bool)$this->QueuedJobs->createJob('Foo', null, ['notBefore' => '+ 1 Day'])); $this->assertTrue((bool)$this->QueuedJobs->createJob('Foo', null, ['notBefore' => '2009-07-01 12:00:00'])); @@ -945,7 +943,7 @@ public function testJobCreatedEventFired(): void { */ protected function _needsConnection() { $config = ConnectionManager::getConfig('test'); - $skip = strpos($config['driver'], 'Mysql') === false && strpos($config['driver'], 'Postgres') === false; + $skip = !str_contains((string) $config['driver'], 'Mysql') && !str_contains((string) $config['driver'], 'Postgres'); $this->skipIf($skip, 'Only Mysql/Postgres is working yet for this.'); } diff --git a/tests/TestCase/Queue/ProcessorTest.php b/tests/TestCase/Queue/ProcessorTest.php index 156a23d5..b8b2718d 100644 --- a/tests/TestCase/Queue/ProcessorTest.php +++ b/tests/TestCase/Queue/ProcessorTest.php @@ -222,7 +222,7 @@ public function testRunVerboseShowsIdlePollOutput() { */ protected function _needsConnection() { $config = ConnectionManager::getConfig('test'); - $skip = strpos($config['driver'], 'Mysql') === false && strpos($config['driver'], 'Postgres') === false; + $skip = !str_contains((string) $config['driver'], 'Mysql') && !str_contains((string) $config['driver'], 'Postgres'); $this->skipIf($skip, 'Only Mysql/Postgres is working yet for this.'); } diff --git a/tests/TestCase/Queue/Task/EmailTaskTest.php b/tests/TestCase/Queue/Task/EmailTaskTest.php index e6523879..6e2f44ac 100644 --- a/tests/TestCase/Queue/Task/EmailTaskTest.php +++ b/tests/TestCase/Queue/Task/EmailTaskTest.php @@ -415,7 +415,7 @@ public function testRunWithAttachments() { */ protected function _skipPostgres() { $config = ConnectionManager::getConfig('test'); - $skip = strpos($config['driver'], 'Postgres') !== false; + $skip = str_contains((string) $config['driver'], 'Postgres'); $this->skipIf($skip, 'Only non Postgres is working yet for this.'); } diff --git a/tests/TestCase/View/Helper/QueueProgressHelperTest.php b/tests/TestCase/View/Helper/QueueProgressHelperTest.php index 0281e50d..92cbbc77 100644 --- a/tests/TestCase/View/Helper/QueueProgressHelperTest.php +++ b/tests/TestCase/View/Helper/QueueProgressHelperTest.php @@ -227,7 +227,7 @@ public function testHtmlTimeoutProgressBar() { */ protected function _needsConnection() { $config = ConnectionManager::getConfig('test'); - $skip = strpos($config['driver'], 'Mysql') === false && strpos($config['driver'], 'Postgres') === false; + $skip = !str_contains((string) $config['driver'], 'Mysql') && !str_contains((string) $config['driver'], 'Postgres'); $this->skipIf($skip, 'Only Mysql/Postgres is working yet for this.'); } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index dcfe5881..641b4f58 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -19,7 +19,7 @@ define('DS', DIRECTORY_SEPARATOR); } if (!defined('WINDOWS')) { - if (DS === '\\' || substr(PHP_OS, 0, 3) === 'WIN') { + if (DS === '\\' || str_starts_with(PHP_OS, 'WIN')) { define('WINDOWS', true); } else { define('WINDOWS', false); diff --git a/tests/schema.php b/tests/schema.php index 324e5ec8..163ac34d 100644 --- a/tests/schema.php +++ b/tests/schema.php @@ -21,7 +21,7 @@ $fieldsObject = (new ReflectionClass($class))->getProperty('fields'); $tableObject = (new ReflectionClass($class))->getProperty('table'); $tableName = $tableObject->getDefaultValue(); - } catch (ReflectionException $e) { + } catch (ReflectionException) { continue; } From 681db9d7a0e9b2bf14fb4107c534dbbbf57f76a7 Mon Sep 17 00:00:00 2001 From: Mark Scherer Date: Sun, 24 May 2026 19:10:27 +0200 Subject: [PATCH 2/8] Run PHPCS cleanup --- src/Controller/Admin/QueueController.php | 2 +- src/Model/Behavior/JsonableBehavior.php | 8 ++++---- src/Model/Table/QueuedJobsTable.php | 4 ++-- src/Queue/Task/EmailTask.php | 2 +- src/View/Helper/QueueHelper.php | 11 +++++++---- tests/TestCase/Command/RunCommandTest.php | 2 +- .../TestCase/Controller/Admin/QueueControllerTest.php | 2 +- .../Controller/Admin/QueuedJobsControllerTest.php | 2 +- tests/TestCase/Model/Table/QueuedJobsTableTest.php | 6 ++++-- tests/TestCase/Queue/ProcessorTest.php | 2 +- tests/TestCase/Queue/Task/EmailTaskTest.php | 2 +- .../TestCase/View/Helper/QueueProgressHelperTest.php | 2 +- 12 files changed, 25 insertions(+), 20 deletions(-) diff --git a/src/Controller/Admin/QueueController.php b/src/Controller/Admin/QueueController.php index e82a4603..e3723884 100644 --- a/src/Controller/Admin/QueueController.php +++ b/src/Controller/Admin/QueueController.php @@ -286,7 +286,7 @@ protected function refererRedirect(array|string $default) { if (is_array($url)) { throw new NotFoundException('Invalid array in query string'); } - if ($url && (mb_substr((string) $url, 0, 1) !== '/' || mb_substr((string) $url, 0, 2) === '//')) { + if ($url && (mb_substr((string)$url, 0, 1) !== '/' || mb_substr((string)$url, 0, 2) === '//')) { $url = null; } diff --git a/src/Model/Behavior/JsonableBehavior.php b/src/Model/Behavior/JsonableBehavior.php index 41395b67..4be10b61 100644 --- a/src/Model/Behavior/JsonableBehavior.php +++ b/src/Model/Behavior/JsonableBehavior.php @@ -173,11 +173,11 @@ protected function _getMappedFields() { */ public function _encode($val) { if (!empty($this->_config['fields']) && $this->_config['input'] === 'json') { - if (!is_string($val)) { + if (!is_string($val)) { throw new InvalidArgumentException('Only accepts JSON string for input type `json`'); - } - $val = $this->_fromJson($val); - } + } + $val = $this->_fromJson($val); + } if (!is_array($val)) { return null; } diff --git a/src/Model/Table/QueuedJobsTable.php b/src/Model/Table/QueuedJobsTable.php index aa3b7146..4d81707f 100644 --- a/src/Model/Table/QueuedJobsTable.php +++ b/src/Model/Table/QueuedJobsTable.php @@ -267,7 +267,7 @@ public function createJob(string $jobTask, array|object|null $data = null, array * @return string */ protected function jobTask(string $jobType): string { - if (!$this->taskFinder instanceof \Queue\Queue\TaskFinder) { + if (!$this->taskFinder instanceof TaskFinder) { $this->taskFinder = new TaskFinder(); } @@ -1260,7 +1260,7 @@ public function truncate(): void { * @return string */ protected function getDriverName(): string { - $className = explode('\\', (string) $this->getConnection()->config()['driver']); + $className = explode('\\', (string)$this->getConnection()->config()['driver']); return end($className) ?: ''; } diff --git a/src/Queue/Task/EmailTask.php b/src/Queue/Task/EmailTask.php index 5bb5f528..498b4363 100644 --- a/src/Queue/Task/EmailTask.php +++ b/src/Queue/Task/EmailTask.php @@ -205,7 +205,7 @@ public function run(array $data, int $jobId): void { } foreach ($settings as $method => $setting) { - $setter = 'set' . ucfirst((string) $method); + $setter = 'set' . ucfirst((string)$method); if (in_array($method, ['theme', 'template', 'layout'], true)) { call_user_func_array([$this->mailer->viewBuilder(), $setter], (array)$setting); diff --git a/src/View/Helper/QueueHelper.php b/src/View/Helper/QueueHelper.php index a769a6d7..9977c79f 100644 --- a/src/View/Helper/QueueHelper.php +++ b/src/View/Helper/QueueHelper.php @@ -36,7 +36,8 @@ public function hasFailed(QueuedJob $queuedJob): bool { // Requeued $taskConfig = $this->taskConfig($queuedJob->job_task); - return !($taskConfig && $queuedJob->attempts <= $taskConfig['retries']); + + return !($taskConfig && $queuedJob->attempts <= $taskConfig['retries']); } /** @@ -81,7 +82,8 @@ public function isRequeued(QueuedJob $queuedJob): bool { } $taskConfig = $this->taskConfig($queuedJob->job_task); - return $taskConfig && $queuedJob->attempts <= $taskConfig['retries']; + + return $taskConfig && $queuedJob->attempts <= $taskConfig['retries']; } /** @@ -103,8 +105,9 @@ public function isRestarted(QueuedJob $queuedJob): bool { if ($queuedJob->attempts < 1) { return false; } - // Must NOT have a failure_message (it was cleared by reset) - return !$queuedJob->failure_message; + + // Must NOT have a failure_message (it was cleared by reset) + return !$queuedJob->failure_message; } /** diff --git a/tests/TestCase/Command/RunCommandTest.php b/tests/TestCase/Command/RunCommandTest.php index 98425e1c..e9a99166 100644 --- a/tests/TestCase/Command/RunCommandTest.php +++ b/tests/TestCase/Command/RunCommandTest.php @@ -78,7 +78,7 @@ public function testServiceInjection(): void { */ protected function _needsConnection() { $config = ConnectionManager::getConfig('test'); - $skip = !str_contains((string) $config['driver'], 'Mysql') && !str_contains((string) $config['driver'], 'Postgres'); + $skip = !str_contains((string)$config['driver'], 'Mysql') && !str_contains((string)$config['driver'], 'Postgres'); $this->skipIf($skip, 'Only Mysql/Postgres is working yet for this.'); } diff --git a/tests/TestCase/Controller/Admin/QueueControllerTest.php b/tests/TestCase/Controller/Admin/QueueControllerTest.php index 6847b937..28610d6d 100644 --- a/tests/TestCase/Controller/Admin/QueueControllerTest.php +++ b/tests/TestCase/Controller/Admin/QueueControllerTest.php @@ -349,7 +349,7 @@ public function testIndexStandalone(): void { */ protected function _needsConnection() { $config = ConnectionManager::getConfig('test'); - $skip = !str_contains((string) $config['driver'], 'Mysql') && !str_contains((string) $config['driver'], 'Postgres'); + $skip = !str_contains((string)$config['driver'], 'Mysql') && !str_contains((string)$config['driver'], 'Postgres'); $this->skipIf($skip, 'Only Mysql/Postgres is working yet for this.'); } diff --git a/tests/TestCase/Controller/Admin/QueuedJobsControllerTest.php b/tests/TestCase/Controller/Admin/QueuedJobsControllerTest.php index ecbe36cb..5c933724 100644 --- a/tests/TestCase/Controller/Admin/QueuedJobsControllerTest.php +++ b/tests/TestCase/Controller/Admin/QueuedJobsControllerTest.php @@ -433,7 +433,7 @@ public function testImport() { */ protected function _needsConnection() { $config = ConnectionManager::getConfig('test'); - $skip = !str_contains((string) $config['driver'], 'Mysql') && !str_contains((string) $config['driver'], 'Postgres'); + $skip = !str_contains((string)$config['driver'], 'Mysql') && !str_contains((string)$config['driver'], 'Postgres'); $this->skipIf($skip, 'Only Mysql/Postgres is working yet for this.'); } diff --git a/tests/TestCase/Model/Table/QueuedJobsTableTest.php b/tests/TestCase/Model/Table/QueuedJobsTableTest.php index a6ded010..4ecf8a41 100644 --- a/tests/TestCase/Model/Table/QueuedJobsTableTest.php +++ b/tests/TestCase/Model/Table/QueuedJobsTableTest.php @@ -323,8 +323,10 @@ public function testSequence() { /** * Test creating Jobs to run close to a specified time, and strtotime parsing. * Using toUnixString() function to convert Time object to timestamp, instead of strtotime + * + * @return void */ - public function testNotBefore() { + public function testNotBefore() { $this->assertTrue((bool)$this->QueuedJobs->createJob('Foo', null, ['notBefore' => '+ 1 Min'])); $this->assertTrue((bool)$this->QueuedJobs->createJob('Foo', null, ['notBefore' => '+ 1 Day'])); $this->assertTrue((bool)$this->QueuedJobs->createJob('Foo', null, ['notBefore' => '2009-07-01 12:00:00'])); @@ -943,7 +945,7 @@ public function testJobCreatedEventFired(): void { */ protected function _needsConnection() { $config = ConnectionManager::getConfig('test'); - $skip = !str_contains((string) $config['driver'], 'Mysql') && !str_contains((string) $config['driver'], 'Postgres'); + $skip = !str_contains((string)$config['driver'], 'Mysql') && !str_contains((string)$config['driver'], 'Postgres'); $this->skipIf($skip, 'Only Mysql/Postgres is working yet for this.'); } diff --git a/tests/TestCase/Queue/ProcessorTest.php b/tests/TestCase/Queue/ProcessorTest.php index b8b2718d..1170e168 100644 --- a/tests/TestCase/Queue/ProcessorTest.php +++ b/tests/TestCase/Queue/ProcessorTest.php @@ -222,7 +222,7 @@ public function testRunVerboseShowsIdlePollOutput() { */ protected function _needsConnection() { $config = ConnectionManager::getConfig('test'); - $skip = !str_contains((string) $config['driver'], 'Mysql') && !str_contains((string) $config['driver'], 'Postgres'); + $skip = !str_contains((string)$config['driver'], 'Mysql') && !str_contains((string)$config['driver'], 'Postgres'); $this->skipIf($skip, 'Only Mysql/Postgres is working yet for this.'); } diff --git a/tests/TestCase/Queue/Task/EmailTaskTest.php b/tests/TestCase/Queue/Task/EmailTaskTest.php index 6e2f44ac..c51ee31e 100644 --- a/tests/TestCase/Queue/Task/EmailTaskTest.php +++ b/tests/TestCase/Queue/Task/EmailTaskTest.php @@ -415,7 +415,7 @@ public function testRunWithAttachments() { */ protected function _skipPostgres() { $config = ConnectionManager::getConfig('test'); - $skip = str_contains((string) $config['driver'], 'Postgres'); + $skip = str_contains((string)$config['driver'], 'Postgres'); $this->skipIf($skip, 'Only non Postgres is working yet for this.'); } diff --git a/tests/TestCase/View/Helper/QueueProgressHelperTest.php b/tests/TestCase/View/Helper/QueueProgressHelperTest.php index 92cbbc77..0a1925fa 100644 --- a/tests/TestCase/View/Helper/QueueProgressHelperTest.php +++ b/tests/TestCase/View/Helper/QueueProgressHelperTest.php @@ -227,7 +227,7 @@ public function testHtmlTimeoutProgressBar() { */ protected function _needsConnection() { $config = ConnectionManager::getConfig('test'); - $skip = !str_contains((string) $config['driver'], 'Mysql') && !str_contains((string) $config['driver'], 'Postgres'); + $skip = !str_contains((string)$config['driver'], 'Mysql') && !str_contains((string)$config['driver'], 'Postgres'); $this->skipIf($skip, 'Only Mysql/Postgres is working yet for this.'); } From 42eb8afde9e949c4f47df046c7bbff771b8c1db7 Mon Sep 17 00:00:00 2001 From: Mark Scherer Date: Sun, 24 May 2026 20:12:57 +0200 Subject: [PATCH 3/8] Restore safe typed property checks --- src/Model/Behavior/JsonableBehavior.php | 2 +- src/Queue/Task.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Model/Behavior/JsonableBehavior.php b/src/Model/Behavior/JsonableBehavior.php index 4be10b61..4c43e3c2 100644 --- a/src/Model/Behavior/JsonableBehavior.php +++ b/src/Model/Behavior/JsonableBehavior.php @@ -174,7 +174,7 @@ protected function _getMappedFields() { public function _encode($val) { if (!empty($this->_config['fields']) && $this->_config['input'] === 'json') { if (!is_string($val)) { - throw new InvalidArgumentException('Only accepts JSON string for input type `json`'); + throw new InvalidArgumentException('Only accepts JSON string for input type `json`'); } $val = $this->_fromJson($val); } diff --git a/src/Queue/Task.php b/src/Queue/Task.php index 35e14f28..60d9a05b 100644 --- a/src/Queue/Task.php +++ b/src/Queue/Task.php @@ -98,7 +98,7 @@ public function __construct(?Io $io = null, ?LoggerInterface $logger = null) { $QueuedJobs = $tableLocator->get($this->queueModelClass); $this->QueuedJobs = $QueuedJobs; - if (property_exists($this, 'defaultTable') && $this->defaultTable !== null) { + if (isset($this->defaultTable)) { $this->fetchTable(); } } From 65b08893819685fb00572b6133bbd1f611b614b7 Mon Sep 17 00:00:00 2001 From: Mark Scherer Date: Mon, 25 May 2026 04:12:15 +0200 Subject: [PATCH 4/8] Restore compact() for matching view vars --- src/Controller/Admin/QueueProcessesController.php | 6 +++--- src/Controller/Admin/QueuedJobsController.php | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Controller/Admin/QueueProcessesController.php b/src/Controller/Admin/QueueProcessesController.php index 22b1fb48..a1c1c876 100644 --- a/src/Controller/Admin/QueueProcessesController.php +++ b/src/Controller/Admin/QueueProcessesController.php @@ -48,7 +48,7 @@ public function initialize(): void { public function index() { $queueProcesses = $this->paginate(); - $this->set(['queueProcesses' => $queueProcesses]); + $this->set(compact('queueProcesses')); } /** @@ -61,7 +61,7 @@ public function index() { public function view(?int $id = null) { $queueProcess = $this->QueueProcesses->get($id); - $this->set(['queueProcess' => $queueProcess]); + $this->set(compact('queueProcess')); } /** @@ -84,7 +84,7 @@ public function edit(?int $id = null) { $this->Flash->error(__d('queue', 'The queue process could not be saved. Please, try again.')); } - $this->set(['queueProcess' => $queueProcess]); + $this->set(compact('queueProcess')); } /** diff --git a/src/Controller/Admin/QueuedJobsController.php b/src/Controller/Admin/QueuedJobsController.php index df2b8d06..78bd3863 100644 --- a/src/Controller/Admin/QueuedJobsController.php +++ b/src/Controller/Admin/QueuedJobsController.php @@ -75,7 +75,7 @@ public function index() { } $queuedJobs = $this->paginate($query); - $this->set(['queuedJobs' => $queuedJobs]); + $this->set(compact('queuedJobs')); if (Configure::read('Queue.isSearchEnabled') !== false && Plugin::isLoaded('Search')) { $jobTypes = $this->QueuedJobs->find()->where()->find( @@ -83,7 +83,7 @@ public function index() { keyField: 'job_task', valueField: 'job_task', )->distinct('job_task')->toArray(); - $this->set(['jobTypes' => $jobTypes]); + $this->set(compact('jobTypes')); } } @@ -173,7 +173,7 @@ public function view(?int $id = null) { $this->response = $this->response->withDownload('queued-job-' . $id . '.json'); } - $this->set(['queuedJob' => $queuedJob]); + $this->set(compact('queuedJob')); $this->viewBuilder()->setOption('serialize', ['queuedJob']); } @@ -286,7 +286,7 @@ public function edit(?int $id = null) { $this->Flash->error(__d('queue', 'The queued job could not be saved. Please try again.')); } - $this->set(['queuedJob' => $queuedJob]); + $this->set(compact('queuedJob')); } /** @@ -322,7 +322,7 @@ public function data(?int $id = null) { } } - $this->set(['queuedJob' => $queuedJob]); + $this->set(compact('queuedJob')); } /** @@ -488,7 +488,7 @@ public function migrate() { return $this->redirect(['action' => 'migrate']); } - $this->set(['tasks' => $tasks]); + $this->set(compact('tasks')); } } From e8528011172332f051e8a95ef299274b578457db Mon Sep 17 00:00:00 2001 From: Mark Scherer Date: Mon, 25 May 2026 04:29:54 +0200 Subject: [PATCH 5/8] Address queue review follow-ups --- src/Controller/Admin/QueueController.php | 23 ++++++++++++++++++- src/Model/Table/QueuedJobsTable.php | 2 +- src/Queue/TaskFinder.php | 2 +- .../Model/Table/QueuedJobsTableTest.php | 10 ++++---- 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/src/Controller/Admin/QueueController.php b/src/Controller/Admin/QueueController.php index e3723884..87d87d13 100644 --- a/src/Controller/Admin/QueueController.php +++ b/src/Controller/Admin/QueueController.php @@ -118,7 +118,28 @@ public function index() { $configurations = (array)Configure::read('Queue'); - $this->set(['new' => $new, 'current' => $current, 'data' => $data, 'pendingDetails' => $pendingDetails, 'scheduledDetails' => $scheduledDetails, 'pendingDetailsTruncated' => $pendingDetailsTruncated, 'scheduledDetailsTruncated' => $scheduledDetailsTruncated, 'detailsLimit' => $detailsLimit, 'totalPending' => $totalPending, 'status' => $status, 'tasks' => $tasks, 'addableTasks' => $addableTasks, 'taskDescriptions' => $taskDescriptions, 'servers' => $servers, 'workers' => $workers, 'pendingJobs' => $pendingJobs, 'scheduledJobs' => $scheduledJobs, 'runningJobs' => $runningJobs, 'failedJobs' => $failedJobs, 'configurations' => $configurations]); + $this->set(compact( + 'new', + 'current', + 'data', + 'pendingDetails', + 'scheduledDetails', + 'pendingDetailsTruncated', + 'scheduledDetailsTruncated', + 'detailsLimit', + 'totalPending', + 'status', + 'tasks', + 'addableTasks', + 'taskDescriptions', + 'servers', + 'workers', + 'pendingJobs', + 'scheduledJobs', + 'runningJobs', + 'failedJobs', + 'configurations', + )); } /** diff --git a/src/Model/Table/QueuedJobsTable.php b/src/Model/Table/QueuedJobsTable.php index 4d81707f..67e1b535 100644 --- a/src/Model/Table/QueuedJobsTable.php +++ b/src/Model/Table/QueuedJobsTable.php @@ -267,7 +267,7 @@ public function createJob(string $jobTask, array|object|null $data = null, array * @return string */ protected function jobTask(string $jobType): string { - if (!$this->taskFinder instanceof TaskFinder) { + if (!($this->taskFinder instanceof TaskFinder)) { $this->taskFinder = new TaskFinder(); } diff --git a/src/Queue/TaskFinder.php b/src/Queue/TaskFinder.php index a47eadef..ce1573ee 100644 --- a/src/Queue/TaskFinder.php +++ b/src/Queue/TaskFinder.php @@ -145,7 +145,7 @@ public function resolve(string $jobTask): string { if (!str_contains($jobTask, '\\')) { // Let's try matching without plugin prefix - foreach (array_keys($all) as $name) { + foreach ($all as $name => $_) { if (!str_contains($name, '.')) { continue; } diff --git a/tests/TestCase/Model/Table/QueuedJobsTableTest.php b/tests/TestCase/Model/Table/QueuedJobsTableTest.php index 4ecf8a41..3dd24c0d 100644 --- a/tests/TestCase/Model/Table/QueuedJobsTableTest.php +++ b/tests/TestCase/Model/Table/QueuedJobsTableTest.php @@ -321,11 +321,11 @@ public function testSequence() { } /** - * Test creating Jobs to run close to a specified time, and strtotime parsing. - * Using toUnixString() function to convert Time object to timestamp, instead of strtotime - * - * @return void - */ + * Test creating Jobs to run close to a specified time, and strtotime parsing. + * Using toUnixString() function to convert Time object to timestamp, instead of strtotime + * + * @return void + */ public function testNotBefore() { $this->assertTrue((bool)$this->QueuedJobs->createJob('Foo', null, ['notBefore' => '+ 1 Min'])); $this->assertTrue((bool)$this->QueuedJobs->createJob('Foo', null, ['notBefore' => '+ 1 Day'])); From 9802cd1658c2a2a9970ca0585970cd99a200ba94 Mon Sep 17 00:00:00 2001 From: Mark Scherer Date: Mon, 25 May 2026 05:05:07 +0200 Subject: [PATCH 6/8] Restore compact() for matching view vars --- src/Controller/Admin/QueueController.php | 2 +- src/Controller/Admin/QueuedJobsController.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Controller/Admin/QueueController.php b/src/Controller/Admin/QueueController.php index 87d87d13..71d5676a 100644 --- a/src/Controller/Admin/QueueController.php +++ b/src/Controller/Admin/QueueController.php @@ -249,7 +249,7 @@ public function processes() { $terminated = $QueueProcesses->find()->where(['terminate' => true])->all()->toArray(); $key = $QueueProcesses->buildServerString(); - $this->set(['terminated' => $terminated, 'processes' => $processes, 'key' => $key]); + $this->set(compact('terminated', 'processes', 'key')); } /** diff --git a/src/Controller/Admin/QueuedJobsController.php b/src/Controller/Admin/QueuedJobsController.php index 78bd3863..ad2476c4 100644 --- a/src/Controller/Admin/QueuedJobsController.php +++ b/src/Controller/Admin/QueuedJobsController.php @@ -112,7 +112,7 @@ public function stats(): void { keyField: 'job_task', valueField: 'job_task', )->distinct('job_task')->toArray(); - $this->set(['stats' => $stats, 'jobTypes' => $jobTypes, 'jobType' => $jobType]); + $this->set(compact('stats', 'jobTypes', 'jobType')); } /** @@ -153,7 +153,7 @@ public function heatmap(): void { valueField: 'job_task', )->distinct('job_task')->toArray(); - $this->set(['heatmapData' => $heatmapData, 'jobTypes' => $jobTypes, 'jobType' => $jobType, 'metric' => $metric, 'days' => $days]); + $this->set(compact('heatmapData', 'jobTypes', 'jobType', 'metric', 'days')); } /** @@ -440,7 +440,7 @@ public function test() { $this->Flash->error(__d('queue', 'The job could not be queued. Please try again.')); } - $this->set(['tasks' => $tasks, 'queuedJob' => $queuedJob]); + $this->set(compact('tasks', 'queuedJob')); } /** From 14ffacf5cb29e0539479132885f87256d7331036 Mon Sep 17 00:00:00 2001 From: Mark Scherer Date: Mon, 25 May 2026 13:54:04 +0200 Subject: [PATCH 7/8] Fix queue cleanup regressions --- src/Controller/Admin/QueueAppController.php | 2 ++ src/Mailer/Transport/SimpleQueueTransport.php | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Controller/Admin/QueueAppController.php b/src/Controller/Admin/QueueAppController.php index 13f0d3a6..9f156db8 100644 --- a/src/Controller/Admin/QueueAppController.php +++ b/src/Controller/Admin/QueueAppController.php @@ -111,6 +111,8 @@ public function beforeFilter(EventInterface $event): void { try { $allowed = $gate($this->request) === true; + } catch (ForbiddenException $e) { + throw $e; } catch (Throwable $e) { Log::warning(sprintf('Queue.adminAccess threw %s: %s', $e::class, $e->getMessage())); diff --git a/src/Mailer/Transport/SimpleQueueTransport.php b/src/Mailer/Transport/SimpleQueueTransport.php index 89ce6301..be209351 100644 --- a/src/Mailer/Transport/SimpleQueueTransport.php +++ b/src/Mailer/Transport/SimpleQueueTransport.php @@ -57,7 +57,6 @@ public function send(Message $message): array { ]; foreach ($settings as $setting => $value) { - /** @phpstan-ignore-next-line */ if ($value[0] === null || $value[0] === []) { unset($settings[$setting]); } From c0a46a966b007da3836a27f077f4d540aa516b4f Mon Sep 17 00:00:00 2001 From: Mark Scherer Date: Mon, 25 May 2026 13:57:39 +0200 Subject: [PATCH 8/8] Fix queue static analysis types --- src/Model/Table/QueueProcessesTable.php | 1 + src/Model/Table/QueuedJobsTable.php | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/Model/Table/QueueProcessesTable.php b/src/Model/Table/QueueProcessesTable.php index 4e29e908..49f2c0b8 100644 --- a/src/Model/Table/QueueProcessesTable.php +++ b/src/Model/Table/QueueProcessesTable.php @@ -242,6 +242,7 @@ public function status(): array { ->enableHydration(false) ->all() ->toArray(); + /** @var array $results */ if (!$results) { return []; diff --git a/src/Model/Table/QueuedJobsTable.php b/src/Model/Table/QueuedJobsTable.php index 67e1b535..ab4398d8 100644 --- a/src/Model/Table/QueuedJobsTable.php +++ b/src/Model/Table/QueuedJobsTable.php @@ -221,6 +221,7 @@ public function createJob(string $jobTask, array|object|null $data = null, array throw new InvalidArgumentException('createJob() with `unique` requires a `reference` to dedupe on.'); } + /** @var \Queue\Model\Entity\QueuedJob|null $existing */ $existing = $this->find() ->where([ 'reference' => $config->getReferenceOrFail(), @@ -451,6 +452,7 @@ public function getFullStats(?string $jobTask = null): array { ->limit(static::STATS_LIMIT) ->all() ->toArray(); + /** @var array $jobs */ $result = [];