| Conditions | 5 |
| Paths | 5 |
| Total Lines | 30 |
| Code Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 20 |
| CRAP Score | 5 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 23 | 8 | public function create(array $eventListeners): ListenerCollection |
|
| 24 | { |
||
| 25 | 8 | $listenerCollection = new ListenerCollection(); |
|
| 26 | |||
| 27 | 8 | foreach ($eventListeners as $eventName => $listeners) { |
|
| 28 | 6 | if (!is_string($eventName)) { |
|
| 29 | 1 | throw new InvalidEventConfigurationFormatException( |
|
| 30 | 1 | 'Incorrect event listener format. Format with event name must be used.' |
|
| 31 | 1 | ); |
|
| 32 | } |
||
| 33 | |||
| 34 | 5 | if (!is_iterable($listeners)) { |
|
| 35 | 1 | $type = get_debug_type($listeners); |
|
| 36 | |||
| 37 | 1 | throw new InvalidEventConfigurationFormatException( |
|
| 38 | 1 | "Event listeners for $eventName must be an iterable, $type given." |
|
| 39 | 1 | ); |
|
| 40 | } |
||
| 41 | |||
| 42 | 4 | foreach ($listeners as $callable) { |
|
| 43 | 4 | $listener = |
|
| 44 | 4 | fn (object $event): mixed => $this->injector->invoke( |
|
| 45 | 4 | $this->callableFactory->create($callable), |
|
| 46 | 4 | [$event] |
|
| 47 | 4 | ); |
|
| 48 | 4 | $listenerCollection = $listenerCollection->add($listener, $eventName); |
|
| 49 | } |
||
| 50 | } |
||
| 51 | |||
| 52 | 6 | return $listenerCollection; |
|
| 53 | } |
||
| 55 |