| Total Complexity | 7 |
| Total Lines | 38 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 7 | class ListenerCollection implements ListenerCollectionInterface |
||
| 8 | { |
||
| 9 | private PriorityQueue $listeners; |
||
| 10 | |||
| 11 | private int $queueOrder = PHP_INT_MAX; |
||
| 12 | |||
| 13 | public function __construct(iterable $listeners = []) |
||
| 14 | { |
||
| 15 | $this->listeners = new PriorityQueue(); |
||
| 16 | |||
| 17 | if (!empty($listeners)) { |
||
| 18 | $this->addListeners($listeners); |
||
| 19 | } |
||
| 20 | } |
||
| 21 | |||
| 22 | public function addListeners(iterable $listeners, int $priority = 1): void |
||
| 23 | { |
||
| 24 | foreach ($listeners as $listener) { |
||
| 25 | $this->addListener($listener, $priority); |
||
| 26 | } |
||
| 27 | } |
||
| 28 | |||
| 29 | public function addListener(callable $listener, int $priority = 1): void |
||
| 30 | 10 | { |
|
| 31 | $this->listeners->insert($listener, [$priority, $this->queueOrder--]); |
||
| 32 | 10 | } |
|
| 33 | |||
| 34 | 10 | public function getIterator(): \Traversable |
|
| 35 | 1 | { |
|
| 36 | $iterator = clone $this->listeners; |
||
| 37 | $iterator->rewind(); |
||
| 38 | |||
| 39 | return $iterator; |
||
| 40 | } |
||
| 41 | |||
| 42 | public function count(): int |
||
| 45 | 7 | } |
|
| 46 | } |
||
| 47 |