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