| Conditions | 4 |
| Paths | 2 |
| Total Lines | 21 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 11 |
| CRAP Score | 4 |
| Changes | 0 | ||
| 1 | <?php |
||
| 53 | 2 | public function build(): Dispatcher |
|
| 54 | { |
||
| 55 | 2 | $registry = new HandlerRegistry; |
|
| 56 | |||
| 57 | 2 | foreach ($this->handlers as $signal => $handlers) { |
|
| 58 | $handlers = \array_map(function (callable $handler) { |
||
| 59 | 2 | return $this->factory->create($handler); |
|
| 60 | 2 | }, $handlers); |
|
| 61 | |||
| 62 | $registry->add($signal, static function (...$arguments) use ($handlers) { |
||
| 63 | 2 | $promises = []; |
|
| 64 | |||
| 65 | 2 | foreach ($handlers as $handler) { |
|
| 66 | 2 | $promises[] = yield $handler => $arguments; |
|
| 67 | } |
||
| 68 | |||
| 69 | 2 | return \count($promises) === 1 ? \current($promises) : Promise\all($promises); |
|
|
|
|||
| 70 | 2 | }); |
|
| 71 | } |
||
| 72 | |||
| 73 | 2 | return new Dispatcher($registry); |
|
| 74 | } |
||
| 76 |