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