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