Total Complexity | 3 |
Total Lines | 19 |
Duplicated Lines | 0 % |
Coverage | 0% |
Changes | 0 |
1 | <?php declare (strict_types=1); |
||
18 | trait ProcessManagerTrait |
||
19 | { |
||
20 | public function handle(EnvelopeInterface $envelope): void |
||
21 | { |
||
22 | $message = $envelope->getMessage(); |
||
23 | $shortName = (new ReflectionClass($message))->getShortName(); |
||
24 | $handlerMethod = 'when'.ucfirst($shortName); |
||
25 | $handler = [$this, $handlerMethod]; |
||
26 | if (!is_callable($handler)) { |
||
27 | throw new RuntimeException( |
||
28 | sprintf("Handler method '%s' is not callable in '%s'.", $handlerMethod, static::class) |
||
29 | ); |
||
30 | } |
||
31 | $handler($message, $envelope->getMetadata()); |
||
32 | } |
||
33 | |||
34 | public function then(CommandInterface $command, MetadataInterface $metadata = null): void |
||
37 | } |
||
38 | } |
||
39 |