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