Skip to content

Commit 35a9235

Browse files
committed
Apply conservative Rector cleanup
1 parent 0737053 commit 35a9235

30 files changed

Lines changed: 67 additions & 125 deletions

src/Command/AddCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function execute(Arguments $args, ConsoleIo $io) {
5959
$taskName = $args->getArgument('task');
6060
if (!$taskName) {
6161
$io->out(count($tasks) . ' tasks available:');
62-
foreach ($tasks as $task => $className) {
62+
foreach (array_keys($tasks) as $task) {
6363
$io->out(' - ' . $task);
6464
}
6565

src/Command/BakeQueueTaskCommand.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,12 @@ protected function generateTaskTestContent(string $name, string $namespace): str
8686
}
8787
$taskClassNamespace = $namespace . '\Queue\\Task\\' . str_replace(DS, '\\', $name);
8888

89-
if (strpos($name, '/') !== false) {
89+
if (str_contains($name, '/')) {
9090
$parts = explode('/', $name);
9191
$name = array_pop($parts);
9292
}
9393

94-
$content = <<<TXT
94+
return <<<TXT
9595
<?php
9696
9797
namespace $namespace\Test\TestCase\Queue\Task$subNamespace;
@@ -122,8 +122,6 @@ public function testRun(): void {
122122
}
123123
124124
TXT;
125-
126-
return $content;
127125
}
128126

129127
/**
@@ -148,7 +146,7 @@ public function templateData(Arguments $arguments): array {
148146
$namespace .= '\\Queue\\Task';
149147

150148
$namespacePart = null;
151-
if (strpos($name, '/') !== false) {
149+
if (str_contains($name, '/')) {
152150
$parts = explode('/', $name);
153151
$name = array_pop($parts);
154152
$namespacePart = implode('\\', $parts);

src/Command/InfoCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function execute(Arguments $args, ConsoleIo $io) {
5959
$addableTasks = $this->getAddableTasks();
6060

6161
$io->out(count($tasks) . ' tasks available:');
62-
foreach ($tasks as $task => $className) {
62+
foreach (array_keys($tasks) as $task) {
6363
if (array_key_exists($task, $addableTasks)) {
6464
$task .= ' <info>[addable via CLI]</info>';
6565
}

src/Controller/Admin/LoadHelperTrait.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,7 @@ protected function loadHelpers(): void {
2828
}
2929

3030
// Configure helper: prefer Shim, fallback to Queue's own
31-
if (Plugin::isLoaded('Shim')) {
32-
$helpers[] = 'Shim.Configure';
33-
} else {
34-
$helpers[] = 'Queue.Configure';
35-
}
31+
$helpers[] = Plugin::isLoaded('Shim') ? 'Shim.Configure' : 'Queue.Configure';
3632

3733
if (Configure::read('Icon.sets') && class_exists(IconHelper::class)) {
3834
$helpers[] = 'Templating.Icon';

src/Controller/Admin/QueueAppController.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,6 @@ public function beforeFilter(EventInterface $event): void {
111111

112112
try {
113113
$allowed = $gate($this->request) === true;
114-
} catch (ForbiddenException $e) {
115-
throw $e;
116114
} catch (Throwable $e) {
117115
Log::warning(sprintf('Queue.adminAccess threw %s: %s', $e::class, $e->getMessage()));
118116

src/Controller/Admin/QueueController.php

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -118,28 +118,7 @@ public function index() {
118118

119119
$configurations = (array)Configure::read('Queue');
120120

121-
$this->set(compact(
122-
'new',
123-
'current',
124-
'data',
125-
'pendingDetails',
126-
'scheduledDetails',
127-
'pendingDetailsTruncated',
128-
'scheduledDetailsTruncated',
129-
'detailsLimit',
130-
'totalPending',
131-
'status',
132-
'tasks',
133-
'addableTasks',
134-
'taskDescriptions',
135-
'servers',
136-
'workers',
137-
'pendingJobs',
138-
'scheduledJobs',
139-
'runningJobs',
140-
'failedJobs',
141-
'configurations',
142-
));
121+
$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]);
143122
}
144123

145124
/**
@@ -249,7 +228,7 @@ public function processes() {
249228
$terminated = $QueueProcesses->find()->where(['terminate' => true])->all()->toArray();
250229
$key = $QueueProcesses->buildServerString();
251230

252-
$this->set(compact('terminated', 'processes', 'key'));
231+
$this->set(['terminated' => $terminated, 'processes' => $processes, 'key' => $key]);
253232
}
254233

255234
/**
@@ -307,7 +286,7 @@ protected function refererRedirect(array|string $default) {
307286
if (is_array($url)) {
308287
throw new NotFoundException('Invalid array in query string');
309288
}
310-
if ($url && (mb_substr($url, 0, 1) !== '/' || mb_substr($url, 0, 2) === '//')) {
289+
if ($url && (mb_substr((string) $url, 0, 1) !== '/' || mb_substr((string) $url, 0, 2) === '//')) {
311290
$url = null;
312291
}
313292

src/Controller/Admin/QueueProcessesController.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function initialize(): void {
4848
public function index() {
4949
$queueProcesses = $this->paginate();
5050

51-
$this->set(compact('queueProcesses'));
51+
$this->set(['queueProcesses' => $queueProcesses]);
5252
}
5353

5454
/**
@@ -61,7 +61,7 @@ public function index() {
6161
public function view(?int $id = null) {
6262
$queueProcess = $this->QueueProcesses->get($id);
6363

64-
$this->set(compact('queueProcess'));
64+
$this->set(['queueProcess' => $queueProcess]);
6565
}
6666

6767
/**
@@ -84,7 +84,7 @@ public function edit(?int $id = null) {
8484
$this->Flash->error(__d('queue', 'The queue process could not be saved. Please, try again.'));
8585
}
8686

87-
$this->set(compact('queueProcess'));
87+
$this->set(['queueProcess' => $queueProcess]);
8888
}
8989

9090
/**
@@ -100,7 +100,7 @@ public function terminate(?int $id = null) {
100100
$queueProcess->terminate = true;
101101
$this->QueueProcesses->saveOrFail($queueProcess);
102102
$this->Flash->success(__d('queue', 'The queue process has been deleted.'));
103-
} catch (Exception $exception) {
103+
} catch (Exception) {
104104
$this->Flash->error(__d('queue', 'The queue process could not be deleted. Please, try again.'));
105105
}
106106

src/Controller/Admin/QueuedJobsController.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,15 @@ public function index() {
7575
}
7676
$queuedJobs = $this->paginate($query);
7777

78-
$this->set(compact('queuedJobs'));
78+
$this->set(['queuedJobs' => $queuedJobs]);
7979

8080
if (Configure::read('Queue.isSearchEnabled') !== false && Plugin::isLoaded('Search')) {
8181
$jobTypes = $this->QueuedJobs->find()->where()->find(
8282
'list',
8383
keyField: 'job_task',
8484
valueField: 'job_task',
8585
)->distinct('job_task')->toArray();
86-
$this->set(compact('jobTypes'));
86+
$this->set(['jobTypes' => $jobTypes]);
8787
}
8888
}
8989

@@ -112,7 +112,7 @@ public function stats(): void {
112112
keyField: 'job_task',
113113
valueField: 'job_task',
114114
)->distinct('job_task')->toArray();
115-
$this->set(compact('stats', 'jobTypes', 'jobType'));
115+
$this->set(['stats' => $stats, 'jobTypes' => $jobTypes, 'jobType' => $jobType]);
116116
}
117117

118118
/**
@@ -153,7 +153,7 @@ public function heatmap(): void {
153153
valueField: 'job_task',
154154
)->distinct('job_task')->toArray();
155155

156-
$this->set(compact('heatmapData', 'jobTypes', 'jobType', 'metric', 'days'));
156+
$this->set(['heatmapData' => $heatmapData, 'jobTypes' => $jobTypes, 'jobType' => $jobType, 'metric' => $metric, 'days' => $days]);
157157
}
158158

159159
/**
@@ -173,7 +173,7 @@ public function view(?int $id = null) {
173173
$this->response = $this->response->withDownload('queued-job-' . $id . '.json');
174174
}
175175

176-
$this->set(compact('queuedJob'));
176+
$this->set(['queuedJob' => $queuedJob]);
177177
$this->viewBuilder()->setOption('serialize', ['queuedJob']);
178178
}
179179

@@ -286,7 +286,7 @@ public function edit(?int $id = null) {
286286
$this->Flash->error(__d('queue', 'The queued job could not be saved. Please try again.'));
287287
}
288288

289-
$this->set(compact('queuedJob'));
289+
$this->set(['queuedJob' => $queuedJob]);
290290
}
291291

292292
/**
@@ -322,7 +322,7 @@ public function data(?int $id = null) {
322322
}
323323
}
324324

325-
$this->set(compact('queuedJob'));
325+
$this->set(['queuedJob' => $queuedJob]);
326326
}
327327

328328
/**
@@ -407,7 +407,7 @@ public function test() {
407407
$taskFinder = new TaskFinder();
408408
$allTasks = $taskFinder->all();
409409
$tasks = [];
410-
foreach ($allTasks as $task => $className) {
410+
foreach (array_keys($allTasks) as $task) {
411411
if (!str_starts_with($task, 'Queue.')) {
412412
continue;
413413
}
@@ -440,7 +440,7 @@ public function test() {
440440
$this->Flash->error(__d('queue', 'The job could not be queued. Please try again.'));
441441
}
442442

443-
$this->set(compact('tasks', 'queuedJob'));
443+
$this->set(['tasks' => $tasks, 'queuedJob' => $queuedJob]);
444444
}
445445

446446
/**
@@ -458,7 +458,7 @@ public function migrate() {
458458
->toArray();
459459

460460
$tasks = [];
461-
foreach ($allTasks as $task => $className) {
461+
foreach (array_keys($allTasks) as $task) {
462462
if (!str_starts_with($task, 'Queue.')) {
463463
continue;
464464
}
@@ -488,7 +488,7 @@ public function migrate() {
488488
return $this->redirect(['action' => 'migrate']);
489489
}
490490

491-
$this->set(compact('tasks'));
491+
$this->set(['tasks' => $tasks]);
492492
}
493493

494494
}

src/Generator/Task/QueuedJobTask.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function collect(): array {
2424
$list = [];
2525

2626
$names = $this->collectQueuedJobTasks();
27-
foreach ($names as $name => $className) {
27+
foreach (array_keys($names) as $name) {
2828
$list[$name] = "'$name'";
2929
}
3030

@@ -44,9 +44,8 @@ public function collect(): array {
4444
*/
4545
protected function collectQueuedJobTasks(): array {
4646
$taskFinder = new TaskFinder();
47-
$tasks = $taskFinder->all();
4847

49-
return $tasks;
48+
return $taskFinder->all();
5049
}
5150

5251
}

src/Mailer/Transport/SimpleQueueTransport.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function send(Message $message): array {
5858

5959
foreach ($settings as $setting => $value) {
6060
/** @phpstan-ignore-next-line */
61-
if (array_key_exists(0, $value) && ($value[0] === null || $value[0] === [])) {
61+
if ($value[0] === null || $value[0] === []) {
6262
unset($settings[$setting]);
6363
}
6464
}

0 commit comments

Comments
 (0)