| Conditions | 4 |
| Paths | 1 |
| Total Lines | 13 |
| Code Lines | 7 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 36 | function stripFoldersNormalizeName(array $folders, $sep = '::') { |
||
| 37 | return function($name) use ($folders, $sep) { |
||
| 38 | foreach ($folders as $folder) { |
||
| 39 | foreach (array_filter($folder['prefixes']) as $prefix) { |
||
| 40 | if (strpos($name, $prefix) === 0) { |
||
| 41 | return $folder['folder'] . $sep . substr($name, strlen($prefix) + 1); |
||
| 42 | } |
||
| 43 | } |
||
| 44 | } |
||
| 45 | |||
| 46 | return $name; |
||
| 47 | }; |
||
| 48 | } |
||
| 49 |
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: