| Conditions | 4 |
| Paths | 3 |
| Total Lines | 19 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 7 |
| CRAP Score | 4.7691 |
| Changes | 0 | ||
| 1 | <?php |
||
| 22 | 2 | public function resolve(DefinitionInterface $definition) |
|
| 23 | { |
||
| 24 | 2 | if (!$definition instanceof FactoryDefinition) { |
|
| 25 | $actualType = gettype($definition); |
||
| 26 | $expectedType = FactoryDefinition::class; |
||
| 27 | |||
| 28 | throw new InvalidArgumentException("Argument \$definition must be $expectedType, $actualType given"); |
||
| 29 | } |
||
| 30 | |||
| 31 | 2 | $factoryClass = $definition->getFactoryClass(); |
|
| 32 | 2 | $factoryInterface = FactoryInterface::class; |
|
| 33 | 2 | $interfaces = class_implements($factoryClass); |
|
| 34 | |||
| 35 | 2 | if (empty($interfaces) || !in_array($factoryInterface, $interfaces, true)) { |
|
| 36 | throw new ContainerException("$factoryClass must implement $factoryInterface"); |
||
| 37 | } |
||
| 38 | |||
| 39 | 2 | return (new $factoryClass)($this->getContainer()); |
|
| 40 | } |
||
| 41 | } |
||
| 42 |