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