Total Complexity | 5 |
Total Lines | 32 |
Duplicated Lines | 0 % |
Coverage | 21.43% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
13 | final class ContainerRegistry implements HandlerRegistryInterface |
||
14 | { |
||
15 | private ContainerInterface $container; |
||
16 | private Inflector $inflector; |
||
17 | |||
18 | 2 | public function __construct(ContainerInterface $container) |
|
19 | { |
||
20 | 2 | $this->container = $container; |
|
21 | 2 | $this->inflector = (new InflectorFactory())->build(); |
|
22 | } |
||
23 | |||
24 | public function getHandler(string $jobType): HandlerInterface |
||
25 | { |
||
26 | try { |
||
27 | $handler = $this->container->get($this->className($jobType)); |
||
28 | } catch (ContainerException $e) { |
||
29 | throw new JobException($e->getMessage(), $e->getCode(), $e); |
||
30 | } |
||
31 | |||
32 | if (!$handler instanceof HandlerInterface) { |
||
33 | throw new JobException("Unable to resolve job handler for `{$jobType}`"); |
||
34 | } |
||
35 | |||
36 | return $handler; |
||
37 | } |
||
38 | |||
39 | private function className(string $jobType): string |
||
45 | } |
||
46 | } |
||
47 |