Conditions | 4 |
Paths | 4 |
Total Lines | 16 |
Code Lines | 8 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
16 | public static function fromFilePath(string $filePath) : self |
||
17 | { |
||
18 | if (false === $fileContent = @file_get_contents($filePath)) { |
||
19 | if (!file_exists($filePath)) { |
||
20 | throw new \RuntimeException("File not found: $filePath"); |
||
21 | } |
||
22 | |||
23 | throw new \RuntimeException("Failed to open file: $filePath"); |
||
24 | } |
||
25 | |||
26 | if (null === $data = json_decode($fileContent, true)) { |
||
27 | throw new \RuntimeException("File does not contain valid JSON: $filePath"); |
||
28 | } |
||
29 | |||
30 | return self::fromArray($data); |
||
31 | } |
||
32 | |||
63 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.