| Total Complexity | 3 |
| Total Lines | 32 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 18 | final class FileReader |
||
| 19 | { |
||
| 20 | /** |
||
| 21 | * Returns string containing contents of the file. |
||
| 22 | * |
||
| 23 | * @throws FileAccessException |
||
| 24 | */ |
||
| 25 | public function readFile(FileName $fileName): string |
||
| 26 | { |
||
| 27 | $fileNameAsString = $fileName->getFileName(); |
||
| 28 | |||
| 29 | $fileContents = @file_get_contents($fileNameAsString); |
||
| 30 | if (false === $fileContents) { |
||
| 31 | throw FileAccessException::readFileException($fileName); |
||
| 32 | } |
||
| 33 | |||
| 34 | return $fileContents; |
||
| 35 | } |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Returns array representing the contents of the file. Assumes the file must be JSON. |
||
| 39 | * |
||
| 40 | * @throws FileAccessException |
||
| 41 | * @throws InvalidContentTypeException |
||
| 42 | * |
||
| 43 | * @return array<mixed> |
||
| 44 | */ |
||
| 45 | public function readJsonFile(FileName $fileName): array |
||
| 50 | } |
||
| 51 | } |
||
| 52 |