Total Complexity | 5 |
Total Lines | 44 |
Duplicated Lines | 0 % |
Coverage | 0% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
12 | class ContainerAwareResolver implements ResolverInterface |
||
13 | { |
||
14 | /** |
||
15 | * @var ContainerInterface $container |
||
16 | */ |
||
17 | protected $container; |
||
18 | |||
19 | public function __construct(ContainerInterface $container) |
||
20 | { |
||
21 | $this->container = $container; |
||
22 | } |
||
23 | |||
24 | /** |
||
25 | * @inheritDoc |
||
26 | */ |
||
27 | public function resolve(string $className): RepositoryInterface |
||
28 | { |
||
29 | try { |
||
30 | $resolved = $this->container->get($className); |
||
31 | |||
32 | if (! ($resolved instanceof RepositoryInterface)) { |
||
33 | $class = get_class($resolved); |
||
34 | |||
35 | $message = $class . ' does not implements RepositoryInterface. Refer to documentation'; |
||
|
|||
36 | $this->fail('Container must return '); |
||
37 | } |
||
38 | } catch (ContainerExceptionInterface $exception) { |
||
39 | $this->fail($exception->getMessage()); |
||
40 | } |
||
41 | } |
||
42 | |||
43 | /** |
||
44 | * fail. |
||
45 | * |
||
46 | * @access protected |
||
47 | * @param string $className |
||
48 | * @return void |
||
49 | */ |
||
50 | protected function fail(string $className, string $message = ''): void |
||
56 | } |
||
57 | } |
||
58 |