| Conditions | 5 |
| Paths | 4 |
| Total Lines | 16 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 9 |
| CRAP Score | 6.6 |
| Changes | 0 | ||
| 1 | <?php declare(strict_types = 1); |
||
| 20 | 4 | public function createFromFile($filename): ConfigContract |
|
| 21 | { |
||
| 22 | 4 | if (!is_file($filename) || !is_readable($filename)) { |
|
| 23 | 1 | throw new \InvalidArgumentException(sprintf('File "%s" does not exist or is not readable', $filename)); |
|
| 24 | } |
||
| 25 | |||
| 26 | 3 | $extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION)); |
|
| 27 | switch ($extension) { |
||
| 28 | 3 | case 'php': |
|
| 29 | 1 | return new Config(include $filename); |
|
| 30 | 2 | case 'json': |
|
| 31 | 1 | return (new Json())->parse(file_get_contents($filename)); |
|
| 32 | default: |
||
| 33 | 1 | throw new \RuntimeException(sprintf('Unknown config format "%s"', $extension)); |
|
| 34 | } |
||
| 35 | } |
||
| 36 | |||
| 37 | } |