| Total Complexity | 6 |
| Total Lines | 49 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 7 | final class ScanResultFile |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * @var string |
||
| 11 | */ |
||
| 12 | private $path; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * ScanResultFile constructor. |
||
| 16 | * @param string $path |
||
| 17 | * @throws ResultFileNotFoundException |
||
| 18 | */ |
||
| 19 | 4 | public function __construct(string $path) |
|
| 20 | { |
||
| 21 | 4 | $this->ensureResultFile($path); |
|
| 22 | 3 | $this->path = $path; |
|
| 23 | 3 | } |
|
| 24 | |||
| 25 | /** |
||
| 26 | * @return string |
||
| 27 | */ |
||
| 28 | 2 | public function getPath(): string |
|
| 29 | { |
||
| 30 | 2 | return $this->path; |
|
| 31 | } |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @return array |
||
| 35 | * @throws ScanResultParsingException |
||
| 36 | */ |
||
| 37 | 2 | public function getResult(): array |
|
| 38 | { |
||
| 39 | 2 | $content = file_get_contents($this->getPath()); |
|
| 40 | 2 | $json = json_decode($content, true); |
|
| 41 | |||
| 42 | 2 | if (!is_array($json)) { |
|
| 43 | 1 | throw new ScanResultParsingException($this->getPath()); |
|
| 44 | } |
||
| 45 | 1 | return $json; |
|
| 46 | } |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @param string $path |
||
| 50 | * @throws ResultFileNotFoundException |
||
| 51 | */ |
||
| 52 | 4 | private function ensureResultFile(string $path): void |
|
| 56 | } |
||
| 57 | } |
||
| 58 | } |