| Conditions | 3 |
| Paths | 3 |
| Total Lines | 18 |
| Code Lines | 10 |
| Lines | 0 |
| Ratio | 0 % |
| 1 | <?php |
||
| 11 | public function provideTestParseAndDump() |
||
| 12 | { |
||
| 13 | $iter = new RecursiveIteratorIterator( |
||
| 14 | new RecursiveDirectoryIterator( |
||
| 15 | __DIR__ . '/../compiling-fixtures' |
||
| 16 | ), |
||
| 17 | RecursiveIteratorIterator::LEAVES_ONLY |
||
| 18 | ); |
||
| 19 | |||
| 20 | foreach ($iter as $file) { |
||
| 21 | if (!$file->isFile()) { |
||
| 22 | continue; |
||
| 23 | } |
||
| 24 | |||
| 25 | $contents = file_get_contents($file); |
||
| 26 | yield $file->getBasename() => explode('----------------------------', $contents); |
||
| 27 | } |
||
| 28 | } |
||
| 29 | |||
| 59 |
If you define a variable conditionally, it can happen that it is not defined for all execution paths.
Let’s take a look at an example:
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.
Available Fixes
Check for existence of the variable explicitly:
Define a default value for the variable:
Add a value for the missing path: