Conditions | 4 |
Paths | 4 |
Total Lines | 21 |
Code Lines | 12 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
13 | public static function load(string $projectPath): bool |
||
14 | { |
||
15 | $filePath = \sprintf('%sconfig/%s', $projectPath, self::FILENAME); |
||
16 | if (!\is_readable($filePath)) { |
||
17 | throw new ConfigurationException('Environment configuration file is not readable.'); |
||
18 | } |
||
19 | $data = \parse_ini_file( |
||
20 | $filePath, // filename |
||
21 | // true => "multidimensional array, with the section names and settings included" |
||
22 | false, // process_sections |
||
23 | // \INI_SCANNER_TYPED - tries to convert booleans and numeric types |
||
24 | // INI_SCANNER_NORMAL - everything is a string |
||
25 | \INI_SCANNER_TYPED, // scanner_mode |
||
26 | ); |
||
27 | if (!$data) { |
||
|
|||
28 | throw new ConfigurationException('Error loading environment configuration file'); |
||
29 | } |
||
30 | foreach ($data as $key => $value) { |
||
31 | Setting::set($key, $value); |
||
32 | } |
||
33 | return true; |
||
34 | } |
||
36 |
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.