Skip to content

Commit d01d1a4

Browse files
authored
Apply conservative Rector cleanup (#500)
* Apply conservative Rector cleanup * Run PHPCS cleanup * Restore safe typed property checks * Restore compact() for matching view vars * Address queue review follow-ups * Restore compact() for matching view vars * Fix queue cleanup regressions * Fix queue static analysis types
1 parent 0737053 commit d01d1a4

29 files changed

Lines changed: 51 additions & 79 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/QueueController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ protected function refererRedirect(array|string $default) {
307307
if (is_array($url)) {
308308
throw new NotFoundException('Invalid array in query string');
309309
}
310-
if ($url && (mb_substr($url, 0, 1) !== '/' || mb_substr($url, 0, 2) === '//')) {
310+
if ($url && (mb_substr((string)$url, 0, 1) !== '/' || mb_substr((string)$url, 0, 2) === '//')) {
311311
$url = null;
312312
}
313313

src/Controller/Admin/QueueProcessesController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}
@@ -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
}

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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ public function send(Message $message): array {
5757
];
5858

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

src/Model/Behavior/JsonableBehavior.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,11 @@ protected function _getMappedFields() {
172172
* @return string|null
173173
*/
174174
public function _encode($val) {
175-
if (!empty($this->_config['fields'])) {
176-
if ($this->_config['input'] === 'json') {
177-
if (!is_string($val)) {
178-
throw new InvalidArgumentException('Only accepts JSON string for input type `json`');
179-
}
180-
$val = $this->_fromJson($val);
175+
if (!empty($this->_config['fields']) && $this->_config['input'] === 'json') {
176+
if (!is_string($val)) {
177+
throw new InvalidArgumentException('Only accepts JSON string for input type `json`');
181178
}
179+
$val = $this->_fromJson($val);
182180
}
183181
if (!is_array($val)) {
184182
return null;

0 commit comments

Comments
 (0)