| Conditions | 5 |
| Paths | 5 |
| Total Lines | 29 |
| Code Lines | 15 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 19 | public function getPart(string $parentClass, string $name): Document\AbstractPart |
||
| 20 | { |
||
| 21 | /** @var class-string<Document\AbstractPart> $className */ |
||
| 22 | $className = $parentClass . '\\' . $name; |
||
| 23 | try { |
||
| 24 | $reflection = new ReflectionClass($className); |
||
| 25 | } catch (ReflectionException) { |
||
| 26 | throw new DomainException('Entity does not exists: ' . $name); |
||
| 27 | } |
||
| 28 | |||
| 29 | if (!$reflection->isInstantiable()) { |
||
| 30 | throw new DomainException('Entity cannot be initialized: ' . $name); |
||
| 31 | } |
||
| 32 | |||
| 33 | try { |
||
| 34 | $instance = $reflection->newInstance( |
||
| 35 | $this->dependenciesFactory, |
||
| 36 | ); |
||
| 37 | // @codeCoverageIgnoreStart |
||
| 38 | } catch (ReflectionException) { |
||
| 39 | throw new DomainException('Entity initialization failed: ' . $name); |
||
| 40 | } |
||
| 41 | // @codeCoverageIgnoreEnd |
||
| 42 | |||
| 43 | if (!is_a($instance, Document\AbstractPart::class)) { |
||
| 44 | throw new DomainException('Entity is not an instance of AbstractPart: ' . $name); |
||
| 45 | } |
||
| 46 | |||
| 47 | return $instance; |
||
| 48 | } |
||
| 50 |