| Conditions | 5 |
| Paths | 5 |
| Total Lines | 29 |
| Code Lines | 14 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 14 |
| CRAP Score | 5 |
| Changes | 0 | ||
| 1 | <?php |
||
| 19 | 4 | public function get(string $type, array $options) |
|
| 20 | { |
||
| 21 | 4 | if ($this->container->has($type)) { |
|
| 22 | 1 | return $this->container->get($type); |
|
| 23 | } |
||
| 24 | |||
| 25 | 3 | $className = $this->getFactoryClassName($type); |
|
| 26 | |||
| 27 | 3 | if (!$className) { |
|
| 28 | 1 | throw new InvalidConfigException( |
|
| 29 | 1 | 'Unable to locate a factory by the name of: '.$type |
|
| 30 | ); |
||
| 31 | } |
||
| 32 | |||
| 33 | /** @var FactoryInterface $factory */ |
||
| 34 | 2 | $factory = new $className(); |
|
| 35 | |||
| 36 | 2 | if (!$factory instanceof FactoryInterface) { |
|
| 37 | 1 | throw new InvalidConfigException( |
|
| 38 | 1 | 'Class '.$className.' must be an instance of '.FactoryInterface::class |
|
| 39 | ); |
||
| 40 | } |
||
| 41 | |||
| 42 | 1 | if ($factory instanceof ContainerAwareInterface) { |
|
| 43 | 1 | $factory->setContainer($this->container); |
|
| 44 | } |
||
| 45 | |||
| 46 | 1 | return $factory($options); |
|
| 47 | } |
||
| 48 | |||
| 66 |