-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathBatchPolicy.php
35 lines (29 loc) · 878 Bytes
/
BatchPolicy.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
declare(strict_types=1);
namespace SchedulerBundle\SchedulePolicy;
use SchedulerBundle\Task\TaskInterface;
use SchedulerBundle\Task\TaskListInterface;
/**
* @author Guillaume Loulier <[email protected]>
*/
final class BatchPolicy implements PolicyInterface
{
/**
* {@inheritdoc}
*/
public function sort(TaskListInterface $tasks): TaskListInterface
{
$tasks->walk(func: static function (TaskInterface $task): void {
$priority = $task->getPriority();
$task->setPriority(priority: --$priority);
});
return $tasks->uasort(func: static fn (TaskInterface $task, TaskInterface $nextTask): int => $task->getPriority() <=> $nextTask->getPriority());
}
/**
* {@inheritdoc}
*/
public function support(string $policy): bool
{
return 'batch' === $policy;
}
}