Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .assets/_symfony_scheduler_/bar.json
Original file line number Diff line number Diff line change
@@ -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"}
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
7 changes: 6 additions & 1 deletion phpstan.neon.8.0.dist
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
7 changes: 6 additions & 1 deletion phpstan.neon.8.1.dist
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
10 changes: 3 additions & 7 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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: [
Expand Down
10 changes: 8 additions & 2 deletions src/Task/HttpTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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']
: []
;
}

/**
Expand Down
4 changes: 4 additions & 0 deletions src/Test/Constraint/Probe/ProbeExecutedTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public function toString(): string
*/
protected function matches($other): bool
{
if (!$other instanceof ProbeInterface) {
return false;
}

return $this->expectedCount === $other->getExecutedTasks();
}
}
4 changes: 4 additions & 0 deletions src/Test/Constraint/Probe/ProbeFailedTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public function toString(): string
*/
protected function matches($other): bool
{
if (!$other instanceof ProbeInterface) {
return false;
}

return $this->expectedCount === $other->getFailedTasks();
}
}
4 changes: 4 additions & 0 deletions src/Test/Constraint/Probe/ProbeScheduledTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public function toString(): string
*/
protected function matches($other): bool
{
if (!$other instanceof ProbeInterface) {
return false;
}

return $this->expectedCount === $other->getScheduledTasks();
}
}
6 changes: 6 additions & 0 deletions src/Test/Constraint/Probe/ProbeState.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use PHPUnit\Framework\Constraint\Constraint;
use SchedulerBundle\Probe\ProbeInterface;

use Throwable;
use function json_encode;
use function sprintf;

Expand All @@ -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(),
Expand Down
10 changes: 9 additions & 1 deletion src/Test/Constraint/Scheduler/SchedulerDueTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use PHPUnit\Framework\Constraint\Constraint;
use SchedulerBundle\SchedulerInterface;

use Throwable;
use function sprintf;

/**
Expand All @@ -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();
}
}
8 changes: 7 additions & 1 deletion src/Test/Constraint/TaskExecuted.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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;
}

Expand Down
7 changes: 5 additions & 2 deletions src/Test/Constraint/TaskFailed.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use SchedulerBundle\Event\TaskEventList;

use function count;
use function is_countable;
use function sprintf;

/**
Expand All @@ -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());
}
}
8 changes: 7 additions & 1 deletion src/Test/Constraint/TaskQueued.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -43,7 +47,9 @@ private function countQueuedTasks(TaskEventList $taskEventList): int
continue;
}

if (!$taskEvent->getTask()->isQueued()) {
$task = $taskEvent->getTask();

if (!$task->isQueued()) {
continue;
}

Expand Down
6 changes: 5 additions & 1 deletion src/Test/Constraint/TaskScheduled.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
6 changes: 5 additions & 1 deletion src/Test/Constraint/TaskUnscheduled.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
5 changes: 4 additions & 1 deletion src/Worker/Worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion tests/Bridge/Redis/Transport/RedisTransportFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down