Skip to content

Commit 5b36a41

Browse files
committed
refactor(core): static analysis improvements
1 parent e12affb commit 5b36a41

File tree

7 files changed

+37
-61
lines changed

7 files changed

+37
-61
lines changed

src/Bridge/Doctrine/Transport/Configuration/Connection.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function __construct(
3535
private DbalConnection $connection,
3636
private bool $autoSetup
3737
) {
38-
parent::__construct($connection);
38+
parent::__construct(driverConnection: $connection);
3939
}
4040

4141
/**
@@ -286,7 +286,7 @@ public function toArray(): array
286286
$statement = $this->executeQuery($queryBuilder->getSQL());
287287

288288
$keys = $statement->fetchAllAssociative();
289-
if (!$keys) {
289+
if ([] === $keys) {
290290
throw new RuntimeException('No result found');
291291
}
292292

@@ -311,7 +311,7 @@ public function count(): int
311311
$statement = $this->executeQuery($queryBuilder->getSQL());
312312
$result = $statement->fetchAssociative();
313313

314-
if (!$result) {
314+
if (false === $result || [] === $result) {
315315
throw new RuntimeException('No result found');
316316
}
317317

@@ -349,7 +349,7 @@ protected function addTableToSchema(Schema $schema): void
349349
protected function executeQuery(string $sql, array $parameters = [], array $types = []): Result
350350
{
351351
try {
352-
return $this->connection->executeQuery($sql, $parameters, $types);
352+
return $this->connection->executeQuery(sql: $sql, params: $parameters, types: $types);
353353
} catch (Throwable $throwable) {
354354
if ($this->connection->isTransactionActive()) {
355355
throw $throwable;
@@ -359,7 +359,7 @@ protected function executeQuery(string $sql, array $parameters = [], array $type
359359
$this->setup();
360360
}
361361

362-
return $this->connection->executeQuery($sql, $parameters, $types);
362+
return $this->connection->executeQuery(sql: $sql, params: $parameters, types: $types);
363363
}
364364
}
365365

@@ -372,11 +372,11 @@ public function configureSchema(Schema $schema, DBALConnection $dbalConnection):
372372
return;
373373
}
374374

375-
if ($schema->hasTable(self::TABLE_NAME)) {
375+
if ($schema->hasTable(name: self::TABLE_NAME)) {
376376
return;
377377
}
378378

379-
$this->addTableToSchema($schema);
379+
$this->addTableToSchema(schema: $schema);
380380
}
381381

382382
/**
@@ -388,7 +388,7 @@ private function setup(): void
388388
$schemaAssetsFilter = $configuration->getSchemaAssetsFilter();
389389
$configuration->setSchemaAssetsFilter();
390390
$this->updateSchema();
391-
$configuration->setSchemaAssetsFilter($schemaAssetsFilter);
391+
$configuration->setSchemaAssetsFilter(callable: $schemaAssetsFilter);
392392

393393
$this->autoSetup = false;
394394
}

src/Fiber/AbstractFiberHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ protected function handleOperationViaFiber(Closure $func): TaskListInterface|Laz
4040
});
4141

4242
try {
43-
$return = $fiber->start($func);
43+
$return = $fiber->start(args: $func);
4444
} catch (Throwable $throwable) {
4545
$this->logger->critical(message: sprintf('An error occurred while performing the action: %s', $throwable->getMessage()));
4646

src/Runner/HttpTaskRunner.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
*/
1818
final class HttpTaskRunner implements RunnerInterface
1919
{
20-
public function __construct(private ?HttpClientInterface $httpClient = null)
20+
private HttpClientInterface $httpClient;
21+
22+
public function __construct(?HttpClientInterface $httpClient = null)
2123
{
2224
$this->httpClient = $httpClient ?? HttpClient::create();
2325
}

src/Runner/ProbeTaskRunner.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
*/
2121
final class ProbeTaskRunner implements RunnerInterface
2222
{
23-
public function __construct(private ?HttpClientInterface $httpClient = null)
23+
private HttpClientInterface $httpClient;
24+
25+
public function __construct(?HttpClientInterface $httpClient = null)
2426
{
2527
$this->httpClient = $httpClient ?? HttpClient::create();
2628
}
@@ -36,6 +38,7 @@ public function run(TaskInterface $task, WorkerInterface $worker): Output
3638

3739
try {
3840
$response = $this->httpClient->request(method: 'GET', url: $task->getExternalProbePath());
41+
3942
$body = $response->toArray();
4043
if (!array_key_exists(key: 'failedTasks', array: $body) || ($task->getErrorOnFailedTasks() && 0 !== $body['failedTasks'])) {
4144
throw new RuntimeException(message: 'The probe state is invalid');

src/Transport/FiberTransport.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function __construct(
2222
private TransportInterface $transport,
2323
protected ?LoggerInterface $logger = null
2424
) {
25-
parent::__construct($logger);
25+
parent::__construct(logger: $logger);
2626
}
2727

2828
/**
@@ -32,7 +32,7 @@ public function __construct(
3232
*/
3333
public function get(string $name, bool $lazy = false): TaskInterface|LazyTask
3434
{
35-
return $this->handleOperationViaFiber(fn (): TaskInterface|LazyTask => $this->transport->get($name, $lazy));
35+
return $this->handleOperationViaFiber(func: fn (): TaskInterface|LazyTask => $this->transport->get(name: $name, lazy: $lazy));
3636
}
3737

3838
/**
@@ -42,7 +42,7 @@ public function get(string $name, bool $lazy = false): TaskInterface|LazyTask
4242
*/
4343
public function list(bool $lazy = false): TaskListInterface|LazyTaskList
4444
{
45-
return $this->handleOperationViaFiber(fn (): TaskListInterface|LazyTaskList => $this->transport->list($lazy));
45+
return $this->handleOperationViaFiber(func: fn (): TaskListInterface|LazyTaskList => $this->transport->list(lazy: $lazy));
4646
}
4747

4848
/**
@@ -52,8 +52,8 @@ public function list(bool $lazy = false): TaskListInterface|LazyTaskList
5252
*/
5353
public function create(TaskInterface $task): void
5454
{
55-
$this->handleOperationViaFiber(function () use ($task): void {
56-
$this->transport->create($task);
55+
$this->handleOperationViaFiber(func: function () use ($task): void {
56+
$this->transport->create(task: $task);
5757
});
5858
}
5959

@@ -64,8 +64,8 @@ public function create(TaskInterface $task): void
6464
*/
6565
public function update(string $name, TaskInterface $updatedTask): void
6666
{
67-
$this->handleOperationViaFiber(function () use ($name, $updatedTask): void {
68-
$this->transport->update($name, $updatedTask);
67+
$this->handleOperationViaFiber(func: function () use ($name, $updatedTask): void {
68+
$this->transport->update(name: $name, updatedTask: $updatedTask);
6969
});
7070
}
7171

@@ -76,8 +76,8 @@ public function update(string $name, TaskInterface $updatedTask): void
7676
*/
7777
public function delete(string $name): void
7878
{
79-
$this->handleOperationViaFiber(function () use ($name): void {
80-
$this->transport->delete($name);
79+
$this->handleOperationViaFiber(func: function () use ($name): void {
80+
$this->transport->delete(name: $name);
8181
});
8282
}
8383

@@ -88,8 +88,8 @@ public function delete(string $name): void
8888
*/
8989
public function pause(string $name): void
9090
{
91-
$this->handleOperationViaFiber(function () use ($name): void {
92-
$this->transport->pause($name);
91+
$this->handleOperationViaFiber(func: function () use ($name): void {
92+
$this->transport->pause(name: $name);
9393
});
9494
}
9595

@@ -100,8 +100,8 @@ public function pause(string $name): void
100100
*/
101101
public function resume(string $name): void
102102
{
103-
$this->handleOperationViaFiber(function () use ($name): void {
104-
$this->transport->resume($name);
103+
$this->handleOperationViaFiber(func: function () use ($name): void {
104+
$this->transport->resume(name: $name);
105105
});
106106
}
107107

@@ -112,7 +112,7 @@ public function resume(string $name): void
112112
*/
113113
public function clear(): void
114114
{
115-
$this->handleOperationViaFiber(function (): void {
115+
$this->handleOperationViaFiber(func: function (): void {
116116
$this->transport->clear();
117117
});
118118
}
@@ -124,6 +124,6 @@ public function clear(): void
124124
*/
125125
public function getConfiguration(): ConfigurationInterface
126126
{
127-
return $this->handleOperationViaFiber(fn (): ConfigurationInterface => $this->transport->getConfiguration());
127+
return $this->handleOperationViaFiber(func: fn (): ConfigurationInterface => $this->transport->getConfiguration());
128128
}
129129
}

tests/AbstractSchedulerTestCase.php

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -53,24 +53,12 @@ public function testSchedulerCanScheduleTasksWithCustomTimezone(): void
5353
self::assertCount(expectedCount: 1, haystack: $scheduler->getTasks());
5454
}
5555

56-
/**
57-
* @throws Exception {@see Scheduler::__construct()}
58-
* @throws Throwable {@see FiberScheduler::getTimezone()}
59-
*/
60-
public function testSchedulerCanReturnTheTimezone(): void
61-
{
62-
$scheduler = $this->getScheduler();
63-
64-
$timezone = $scheduler->getTimezone();
65-
self::assertSame(expected: 'UTC', actual: $timezone->getName());
66-
}
67-
6856
/**
6957
* @throws Throwable {@see Scheduler::__construct()}
7058
*/
7159
public function testSchedulerCanRebootWithEmptyTasks(): void
7260
{
73-
$scheduler = $this->buildScheduler();
61+
$scheduler = $this->getScheduler();
7462

7563
$scheduler->schedule(new NullTask('bar'));
7664
self::assertCount(1, $scheduler->getTasks());
@@ -84,7 +72,7 @@ public function testSchedulerCanRebootWithEmptyTasks(): void
8472
*/
8573
public function testSchedulerCanReboot(): void
8674
{
87-
$scheduler = $this->buildScheduler();
75+
$scheduler = $this->getScheduler();
8876

8977
$scheduler->schedule(new NullTask('foo', [
9078
'expression' => '@reboot',
@@ -104,7 +92,7 @@ public function testSchedulerCannotPreemptEmptyDueTasks(): void
10492
{
10593
$task = new NullTask('foo');
10694

107-
$scheduler = $this->buildScheduler();
95+
$scheduler = $this->getScheduler();
10896

10997
$scheduler->preempt('foo', static fn (TaskInterface $task): bool => $task->getName() === 'bar');
11098
self::assertNotSame(TaskInterface::READY_TO_EXECUTE, $task->getState());
@@ -116,10 +104,10 @@ public function testSchedulerCannotPreemptEmptyDueTasks(): void
116104
*/
117105
public function testSchedulerCanReturnTheTimezone(): void
118106
{
119-
$scheduler = $this->buildScheduler();
107+
$scheduler = $this->getScheduler();
120108

121109
$timezone = $scheduler->getTimezone();
122-
self::assertSame('UTC', $timezone->getName());
110+
self::assertSame(expected: 'UTC', actual: $timezone->getName());
123111
}
124112

125113
/**

tests/LazySchedulerTest.php

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
*/
5858
final class LazySchedulerTest extends AbstractSchedulerTestCase
5959
{
60-
protected function buildScheduler(): SchedulerInterface
60+
protected function getScheduler(): SchedulerInterface
6161
{
6262
return new LazyScheduler(new Scheduler('UTC', new InMemoryTransport(new InMemoryConfiguration(), new SchedulePolicyOrchestrator([
6363
new FirstInFirstOutPolicy(),
@@ -832,23 +832,6 @@ public function testTaskCanBeUpdatedAsynchronously(): void
832832
self::assertSame('0 * * * *', $scheduler->getTasks()->get('foo')->getExpression());
833833
}
834834

835-
/**
836-
* @throws Exception {@see Scheduler::__construct()}
837-
*/
838-
public function testSchedulerCanReturnTheTimezone(): void
839-
{
840-
$scheduler = new LazyScheduler(new Scheduler('UTC', new InMemoryTransport(new InMemoryConfiguration([
841-
'execution_mode' => 'first_in_first_out',
842-
]), new SchedulePolicyOrchestrator([
843-
new FirstInFirstOutPolicy(),
844-
])), new SchedulerMiddlewareStack(), new EventDispatcher()));
845-
self::assertFalse($scheduler->isInitialized());
846-
847-
$timezone = $scheduler->getTimezone();
848-
self::assertSame('UTC', $timezone->getName());
849-
self::assertTrue($scheduler->isInitialized());
850-
}
851-
852835
/**
853836
* @return Generator<array<int, ShellTask>>
854837
*/

0 commit comments

Comments
 (0)