| Conditions | 4 |
| Paths | 5 |
| Total Lines | 16 |
| Code Lines | 10 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 10 |
| CRAP Score | 4 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 27 | 173 | public function getInstance(string $path): AMapper |
|
| 28 | { |
||
| 29 | 173 | if (!isset(static::$instances[$path])) { |
|
| 30 | try { |
||
| 31 | /** @var class-string $path */ |
||
| 32 | 35 | $reflex = new ReflectionClass($path); |
|
| 33 | 34 | $instance = $reflex->newInstance(); |
|
| 34 | 1 | } catch (ReflectionException $ex) { |
|
| 35 | 1 | throw new MapperException(sprintf('Wanted class *%s* does not exists!', $path), $ex->getCode(), $ex); |
|
| 36 | } |
||
| 37 | 34 | if (!$instance instanceof AMapper) { |
|
| 38 | 1 | throw new MapperException(sprintf('Defined class *%s* is not instance of AMapper!', $path)); |
|
| 39 | } |
||
| 40 | 33 | static::$instances[$path] = $instance; |
|
| 41 | } |
||
| 42 | 171 | return static::$instances[$path]; |
|
| 43 | } |
||
| 45 |