1 | <?php |
||
31 | class Parser extends AbstractParser |
||
32 | { |
||
33 | /** |
||
34 | * The Env key parser |
||
35 | * |
||
36 | * @var \M1\Env\Parser\KeyParser $key_parser |
||
37 | */ |
||
38 | private $key_parser; |
||
39 | |||
40 | /** |
||
41 | * The Env value parser |
||
42 | * |
||
43 | * @var \M1\Env\Parser\ValueParser $value_parser |
||
44 | */ |
||
45 | private $value_parser; |
||
46 | |||
47 | /** |
||
48 | * The parser constructor |
||
49 | * |
||
50 | * @param string $file The .env to parse |
||
51 | * @param bool $origin_exception Whether or not to throw ParseException in the .env |
||
52 | */ |
||
53 | 45 | public function __construct($file, $origin_exception = false) |
|
60 | |||
61 | /** |
||
62 | * Opens the .env, parses it then returns the contents |
||
63 | * |
||
64 | * @return array The .env contents |
||
65 | */ |
||
66 | 45 | public function parse() |
|
72 | |||
73 | /** |
||
74 | * Parses the .env line by line |
||
75 | * |
||
76 | * @param array $raw_content The raw content of the file |
||
77 | * |
||
78 | * @throws \M1\Env\Exception\ParseException If the file does not have a key=value structure |
||
79 | * |
||
80 | * @return array The .env contents |
||
81 | */ |
||
82 | 45 | public function parseContent(array $raw_content) |
|
103 | |||
104 | /** |
||
105 | * Parses a line of the .env |
||
106 | * |
||
107 | * @param string $raw_line The raw content of the line |
||
108 | * @param int $line_num The line number of the line |
||
109 | * @param array $lines The parsed lines |
||
110 | * |
||
111 | * @return array The parsed lines |
||
112 | */ |
||
113 | 39 | private function parseLine($raw_line, $line_num, $lines) |
|
127 | |||
128 | /** |
||
129 | * Gets the key = value items from the line |
||
130 | * |
||
131 | * @param string $raw_line The raw content of the line |
||
132 | * @param int $line_num The line number of the line |
||
133 | * |
||
134 | * @throws \M1\Env\Exception\ParseException If the line does not have a key=value structure |
||
135 | * |
||
136 | * @return array The parsed lines |
||
137 | */ |
||
138 | 39 | private function parseKeyValue($raw_line, $line_num) |
|
154 | } |
||
155 |
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.