diff --git a/.assets/_symfony_scheduler_/bar.json b/.assets/_symfony_scheduler_/bar.json new file mode 100644 index 00000000..c2f798a7 --- /dev/null +++ b/.assets/_symfony_scheduler_/bar.json @@ -0,0 +1 @@ +{"body":{"message":{"class":"stdClass","payload":[]},"name":"bar","arrivalTime":null,"beforeScheduling":null,"beforeSchedulingNotificationBag":null,"afterSchedulingNotificationBag":null,"beforeExecutingNotificationBag":null,"afterExecutingNotificationBag":null,"afterScheduling":null,"beforeExecuting":null,"afterExecuting":null,"description":null,"expression":"* * * * *","executionAbsoluteDeadline":null,"executionComputationTime":null,"executionDelay":null,"executionMemoryUsage":0,"executionPeriod":null,"executionRelativeDeadline":null,"executionStartDate":null,"executionEndDate":null,"executionStartTime":null,"executionEndTime":null,"accessLockBag":null,"lastExecution":null,"maxDuration":null,"maxExecutions":null,"maxRetries":null,"nice":null,"state":"enabled","executionState":null,"output":false,"priority":0,"queued":false,"scheduledAt":"2022-05-06 07:01:13.350780","singleRun":false,"deleteAfterExecute":false,"tags":[],"timezone":"UTC","tracked":true},"taskInternalType":"SchedulerBundle\\Task\\MessengerTask"} \ No newline at end of file diff --git a/composer.json b/composer.json index 4249623a..35aae54b 100644 --- a/composer.json +++ b/composer.json @@ -143,7 +143,7 @@ "phpstan/phpstan-symfony": "^1.2.19", "phpunit/phpunit": "^9.5.26", "psr/cache": "^1.0 || ^2.0 || ^3.0", - "rector/rector": "0.15.10", + "rector/rector": "0.15.23", "symfony/cache": "^5.4 || ^6.0", "symfony/dependency-injection": "^5.4 || ^6.0", "symfony/error-handler": "^5.4 || ^6.0", @@ -153,7 +153,8 @@ "symfony/mercure": "^0.5.3", "symfony/messenger": "^5.4 || ^6.0", "symfony/notifier": "^5.4 || ^6.0", - "symfony/rate-limiter": "^5.4 || ^6.0" + "symfony/rate-limiter": "^5.4 || ^6.0", + "tomasvotruba/type-coverage": "^0.1.1" }, "suggest": { "symfony/http-client": "For dispatching http tasks and / or using external probe clients", diff --git a/phpstan.neon.8.0.dist b/phpstan.neon.8.0.dist index f0c1f8df..8e5b6a33 100644 --- a/phpstan.neon.8.0.dist +++ b/phpstan.neon.8.0.dist @@ -4,7 +4,7 @@ includes: - vendor/phpstan/phpstan-phpunit/extension.neon - vendor/phpstan/phpstan-strict-rules/rules.neon - vendor/phpstan/phpstan-symfony/extension.neon - #- vendor/tomasvotruba/cognitive-complexity/config/extension.neon + - vendor/tomasvotruba/type-coverage/config/extension.neon parameters: level: 8 @@ -22,3 +22,8 @@ parameters: #cognitive_complexity: # class: 50 # function: 8 + type_coverage: + return_type: 90 + param_type: 90 + property_type: 90 + print_suggestions: true \ No newline at end of file diff --git a/phpstan.neon.8.1.dist b/phpstan.neon.8.1.dist index 10df217a..9d3a307d 100644 --- a/phpstan.neon.8.1.dist +++ b/phpstan.neon.8.1.dist @@ -4,7 +4,7 @@ includes: - vendor/phpstan/phpstan-phpunit/extension.neon - vendor/phpstan/phpstan-strict-rules/rules.neon - vendor/phpstan/phpstan-symfony/extension.neon - #- vendor/tomasvotruba/cognitive-complexity/config/extension.neon + - vendor/tomasvotruba/type-coverage/config/extension.neon parameters: level: 8 @@ -19,3 +19,8 @@ parameters: #cognitive_complexity: # class: 50 # function: 8 + type_coverage: + return_type: 90 + param_type: 90 + property_type: 90 + print_suggestions: true diff --git a/rector.php b/rector.php index b8838d38..51b796f1 100644 --- a/rector.php +++ b/rector.php @@ -6,6 +6,7 @@ use Rector\Core\ValueObject\PhpVersion; use Rector\Doctrine\Set\DoctrineSetList; use Rector\PHPUnit\Set\PHPUnitSetList; +use Rector\Set\ValueObject\LevelSetList; use Rector\Set\ValueObject\SetList; use Rector\Symfony\Set\SymfonySetList; @@ -45,16 +46,11 @@ ]); $rectorConfig->sets(sets: [ + LevelSetList::UP_TO_PHP_80, + SetList::PSR_4, SetList::CODE_QUALITY, SetList::DEAD_CODE, SetList::EARLY_RETURN, - SetList::PHP_70, - SetList::PHP_71, - SetList::PHP_72, - SetList::PHP_73, - SetList::PHP_74, - SetList::PHP_80, - SetList::PSR_4, ]); $rectorConfig->sets(sets: [ diff --git a/src/Task/HttpTask.php b/src/Task/HttpTask.php index dae554f2..31e4dea8 100644 --- a/src/Task/HttpTask.php +++ b/src/Task/HttpTask.php @@ -56,7 +56,10 @@ public function setUrl(string $url): self public function getMethod(): string { - return $this->options['method'] ?? 'GET'; + return is_string(value: $this->options['method']) + ? $this->options['method'] + : 'GET' + ; } public function setMethod(string $method): self @@ -71,7 +74,10 @@ public function setMethod(string $method): self */ public function getClientOptions(): array { - return is_array(value: $this->options['client_options']) ? $this->options['client_options'] : []; + return is_array(value: $this->options['client_options']) + ? $this->options['client_options'] + : [] + ; } /** diff --git a/src/Test/Constraint/Probe/ProbeExecutedTask.php b/src/Test/Constraint/Probe/ProbeExecutedTask.php index f6ea2144..698af81b 100644 --- a/src/Test/Constraint/Probe/ProbeExecutedTask.php +++ b/src/Test/Constraint/Probe/ProbeExecutedTask.php @@ -31,6 +31,10 @@ public function toString(): string */ protected function matches($other): bool { + if (!$other instanceof ProbeInterface) { + return false; + } + return $this->expectedCount === $other->getExecutedTasks(); } } diff --git a/src/Test/Constraint/Probe/ProbeFailedTask.php b/src/Test/Constraint/Probe/ProbeFailedTask.php index 2c0fbff6..3504fd63 100644 --- a/src/Test/Constraint/Probe/ProbeFailedTask.php +++ b/src/Test/Constraint/Probe/ProbeFailedTask.php @@ -31,6 +31,10 @@ public function toString(): string */ protected function matches($other): bool { + if (!$other instanceof ProbeInterface) { + return false; + } + return $this->expectedCount === $other->getFailedTasks(); } } diff --git a/src/Test/Constraint/Probe/ProbeScheduledTask.php b/src/Test/Constraint/Probe/ProbeScheduledTask.php index 05515788..16df1931 100644 --- a/src/Test/Constraint/Probe/ProbeScheduledTask.php +++ b/src/Test/Constraint/Probe/ProbeScheduledTask.php @@ -31,6 +31,10 @@ public function toString(): string */ protected function matches($other): bool { + if (!$other instanceof ProbeInterface) { + return false; + } + return $this->expectedCount === $other->getScheduledTasks(); } } diff --git a/src/Test/Constraint/Probe/ProbeState.php b/src/Test/Constraint/Probe/ProbeState.php index 1f41091e..c87a7176 100644 --- a/src/Test/Constraint/Probe/ProbeState.php +++ b/src/Test/Constraint/Probe/ProbeState.php @@ -7,6 +7,7 @@ use PHPUnit\Framework\Constraint\Constraint; use SchedulerBundle\Probe\ProbeInterface; +use Throwable; use function json_encode; use function sprintf; @@ -32,9 +33,14 @@ public function toString(): string /** * @param mixed|ProbeInterface $other + * @throws Throwable {@see ProbeInterface::getScheduledTasks()} */ protected function matches($other): bool { + if (!$other instanceof ProbeInterface) { + return false; + } + return $this->expectedState === [ 'executedTasks' => $other->getExecutedTasks(), 'failedTasks' => $other->getFailedTasks(), diff --git a/src/Test/Constraint/Scheduler/SchedulerDueTask.php b/src/Test/Constraint/Scheduler/SchedulerDueTask.php index 700f5943..5d6ef77f 100644 --- a/src/Test/Constraint/Scheduler/SchedulerDueTask.php +++ b/src/Test/Constraint/Scheduler/SchedulerDueTask.php @@ -7,6 +7,7 @@ use PHPUnit\Framework\Constraint\Constraint; use SchedulerBundle\SchedulerInterface; +use Throwable; use function sprintf; /** @@ -28,9 +29,16 @@ public function toString(): string /** * @param mixed|SchedulerInterface $other + * @throws Throwable {@see SchedulerInterface::getDueTasks()} */ protected function matches($other): bool { - return $this->expectedCount === $other->getDueTasks()->count(); + if (!$other instanceof SchedulerInterface) { + return false; + } + + $dueTasks = $other->getDueTasks(); + + return $this->expectedCount === $dueTasks->count(); } } diff --git a/src/Test/Constraint/TaskExecuted.php b/src/Test/Constraint/TaskExecuted.php index 743e9324..eb5666ea 100644 --- a/src/Test/Constraint/TaskExecuted.php +++ b/src/Test/Constraint/TaskExecuted.php @@ -33,6 +33,10 @@ public function toString(): string */ protected function matches($other): bool { + if (!$other instanceof TaskEventList) { + return false; + } + return $this->expectedCount === $this->countExecutedTasks($other); } @@ -44,7 +48,9 @@ private function countExecutedTasks(TaskEventList $taskEventList): int continue; } - if (TaskInterface::SUCCEED !== $taskEvent->getTask()->getExecutionState()) { + $task = $taskEvent->getTask(); + + if (TaskInterface::SUCCEED !== $task->getExecutionState()) { continue; } diff --git a/src/Test/Constraint/TaskFailed.php b/src/Test/Constraint/TaskFailed.php index c4c4b3f4..5fac5515 100644 --- a/src/Test/Constraint/TaskFailed.php +++ b/src/Test/Constraint/TaskFailed.php @@ -8,7 +8,6 @@ use SchedulerBundle\Event\TaskEventList; use function count; -use function is_countable; use function sprintf; /** @@ -33,6 +32,10 @@ public function toString(): string */ protected function matches($other): bool { - return $this->expectedCount === (is_countable($other->getFailedTaskEvents()) ? count($other->getFailedTaskEvents()) : 0); + if (!$other instanceof TaskEventList) { + return false; + } + + return $this->expectedCount === count($other->getFailedTaskEvents()); } } diff --git a/src/Test/Constraint/TaskQueued.php b/src/Test/Constraint/TaskQueued.php index 443eece6..295ef7e8 100644 --- a/src/Test/Constraint/TaskQueued.php +++ b/src/Test/Constraint/TaskQueued.php @@ -32,6 +32,10 @@ public function toString(): string */ protected function matches($other): bool { + if (!$other instanceof TaskEventList) { + return false; + } + return $this->expectedCount === $this->countQueuedTasks($other); } @@ -43,7 +47,9 @@ private function countQueuedTasks(TaskEventList $taskEventList): int continue; } - if (!$taskEvent->getTask()->isQueued()) { + $task = $taskEvent->getTask(); + + if (!$task->isQueued()) { continue; } diff --git a/src/Test/Constraint/TaskScheduled.php b/src/Test/Constraint/TaskScheduled.php index 3e31603a..3620e724 100644 --- a/src/Test/Constraint/TaskScheduled.php +++ b/src/Test/Constraint/TaskScheduled.php @@ -32,6 +32,10 @@ public function toString(): string */ protected function matches($other): bool { - return $this->expectedCount === (is_countable($other->getScheduledTaskEvents()) ? count($other->getScheduledTaskEvents()) : 0); + if (!$other instanceof TaskEventList) { + return false; + } + + return $this->expectedCount === count($other->getScheduledTaskEvents()); } } diff --git a/src/Test/Constraint/TaskUnscheduled.php b/src/Test/Constraint/TaskUnscheduled.php index 1711fc9f..94936c22 100644 --- a/src/Test/Constraint/TaskUnscheduled.php +++ b/src/Test/Constraint/TaskUnscheduled.php @@ -32,6 +32,10 @@ public function toString(): string */ protected function matches($other): bool { - return $this->expectedCount === (is_countable($other->getUnscheduledTaskEvents()) ? count($other->getUnscheduledTaskEvents()) : 0); + if (!$other instanceof TaskEventList) { + return false; + } + + return $this->expectedCount === count($other->getUnscheduledTaskEvents()); } } diff --git a/src/Worker/Worker.php b/src/Worker/Worker.php index 06b64bac..cbfc0c3f 100644 --- a/src/Worker/Worker.php +++ b/src/Worker/Worker.php @@ -118,7 +118,10 @@ public function execute(WorkerConfiguration $configuration, TaskInterface ...$ta */ public function preempt(TaskListInterface $preemptTaskList, TaskListInterface $toPreemptTasksList): void { - $nonExecutedTasks = $toPreemptTasksList->slice(...$preemptTaskList->map(func: static fn (TaskInterface $task): string => $task->getName(), keepKeys: false)); + /** @var string[] $taskNameList */ + $taskNameList = $preemptTaskList->map(func: static fn (TaskInterface $task): string => $task->getName(), keepKeys: false); + + $nonExecutedTasks = $toPreemptTasksList->slice(...$taskNameList); $nonExecutedTasks->walk(func: function (TaskInterface $task): void { $accessLockBag = $task->getAccessLockBag(); diff --git a/tests/Bridge/Redis/Transport/RedisTransportFactoryTest.php b/tests/Bridge/Redis/Transport/RedisTransportFactoryTest.php index ade83f73..6a03c374 100644 --- a/tests/Bridge/Redis/Transport/RedisTransportFactoryTest.php +++ b/tests/Bridge/Redis/Transport/RedisTransportFactoryTest.php @@ -49,7 +49,7 @@ public function testTransportCanBeBuilt(): void self::assertSame($dsn->getPort(), $transport->getConfiguration()->get('port')); self::assertSame($dsn->getScheme(), $transport->getConfiguration()->get('scheme')); self::assertSame($dsn->getOption('timeout', 30), $transport->getConfiguration()->get('timeout')); - self::assertSame($dsn->getOption('auth'), $this->transport->getConfiguration()->get('auth')); + self::assertSame($dsn->getOption('auth'), $transport->getConfiguration()->get('auth')); self::assertArrayHasKey('execution_mode', $transport->getConfiguration()->toArray()); self::assertSame('first_in_first_out', $transport->getConfiguration()->get('execution_mode')); self::assertArrayHasKey('list', $transport->getConfiguration()->toArray());