hanneskod /
readme-tester
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace hanneskod\readmetester\Config; |
||
| 6 | |||
| 7 | use Symfony\Component\Yaml\Yaml; |
||
| 8 | use Symfony\Component\Yaml\Exception\ParseException; |
||
| 9 | |||
| 10 | final class YamlRepository implements RepositoryInterface |
||
| 11 | { |
||
| 12 | private string $filename; |
||
| 13 | |||
| 14 | public function __construct(string $filename) |
||
| 15 | { |
||
| 16 | $this->filename = $filename; |
||
| 17 | } |
||
| 18 | |||
| 19 | public function getConfigs(): array |
||
| 20 | { |
||
| 21 | if (!is_file($this->filename) || !is_readable($this->filename)) { |
||
| 22 | throw new \RuntimeException("Unable to read configs from {$this->filename}"); |
||
| 23 | } |
||
| 24 | |||
| 25 | try { |
||
| 26 | return Yaml::parseFile($this->filename); |
||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 27 | } catch (ParseException $exception) { |
||
| 28 | throw new \RuntimeException("Unable to parse '{$this->filename}': {$exception->getMessage()}"); |
||
| 29 | } |
||
| 30 | } |
||
| 31 | |||
| 32 | public function getRepositoryName(): string |
||
| 33 | { |
||
| 34 | return $this->filename; |
||
| 35 | } |
||
| 36 | } |
||
| 37 |