| 1 | <?php |
||
| 8 | final class GroupProcessManager implements Manager |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * @var Manager |
||
| 12 | */ |
||
| 13 | private $manager; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * @var Task[][] |
||
| 17 | */ |
||
| 18 | private $waiting = []; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @var Task[][] |
||
| 22 | */ |
||
| 23 | private $queuing = []; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @param Manager $manager |
||
| 27 | */ |
||
| 28 | 1 | public function __construct(Manager $manager) |
|
| 32 | |||
| 33 | /** |
||
| 34 | * @inheritdoc |
||
| 35 | * |
||
| 36 | * @param Task $task |
||
| 37 | * |
||
| 38 | * @return $this |
||
| 39 | */ |
||
| 40 | 1 | public function addTask(Task $task) |
|
| 46 | |||
| 47 | /** |
||
| 48 | * Adds a group of tasks to be handled. |
||
| 49 | * |
||
| 50 | * @param Task[] $tasks |
||
| 51 | * |
||
| 52 | * @return $this |
||
| 53 | */ |
||
| 54 | 1 | public function addTaskGroup(array $tasks) |
|
| 55 | { |
||
| 56 | 1 | foreach ($tasks as $task) { |
|
| 57 | 1 | assert($task instanceof Task); |
|
| 58 | } |
||
| 59 | |||
| 60 | 1 | array_push($this->waiting, $tasks); |
|
| 61 | |||
| 62 | 1 | return $this; |
|
| 63 | } |
||
| 64 | |||
| 65 | /** |
||
| 66 | * @inheritdoc |
||
| 67 | * |
||
| 68 | * @return bool |
||
| 69 | */ |
||
| 70 | 1 | public function tick() |
|
| 71 | { |
||
| 72 | 1 | if (!empty($this->queuing)) { |
|
| 73 | 1 | $this->manager->addTask(array_shift($this->queuing)); |
|
|
|
|||
| 74 | } |
||
| 75 | |||
| 76 | 1 | if ($this->manager->tick()) { |
|
| 77 | return true; |
||
| 78 | } |
||
| 79 | |||
| 80 | 1 | if (empty($this->waiting)) { |
|
| 81 | return false; |
||
| 82 | } |
||
| 83 | |||
| 84 | 1 | $this->queuing = [array_shift($this->waiting)]; |
|
| 85 | |||
| 86 | 1 | return true; |
|
| 87 | } |
||
| 88 | |||
| 89 | /** |
||
| 90 | * Passes missing method calls to the decorated manager. |
||
| 91 | * |
||
| 92 | * @param string $method |
||
| 93 | * @param array $parameters |
||
| 94 | * |
||
| 95 | * @return mixed |
||
| 96 | */ |
||
| 97 | public function __call($method, array $parameters) |
||
| 101 | } |
||
| 102 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: