Lines
100.00%
4 / 4
Methods
100.00%
1 / 1
Classes
100.00%
1 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| readSecretFile | 100.00% | 4 / 4 | 100.00% | 1 / 1 | 4 | ||
| 10 | final readonly class SecretFileReader | |
| 11 | { | |
| 12 | private const string TRAILING_LINE_BREAK = '/\r?\n\z/'; | |
| 13 | ||
| 14 | /** @throws ConfigurationException */ | |
| 15 | public function readSecretFile(string $variable, string $path): string | |
| 16 | { | |
| 17 | $contents = is_file($path) && is_readable($path) ? file_get_contents($path) : false; | |
| 18 | ||
| 19 | if ($contents === false) { | |
| 20 | throw ConfigurationException::createForReason(ConfigurationError::EnvironmentSecretFileUnreadable, variable: $variable, path: $path); | |
| 21 | } | |
| 22 | ||
| 23 | return preg_replace(self::TRAILING_LINE_BREAK, '', $contents, 1) ?? $contents; | |
| 24 | } | |
| 25 | } |