| Conditions | 5 |
| Paths | 4 |
| Total Lines | 15 |
| Code Lines | 8 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 24 | public function inArray($values, $args, $do, $strict = false) |
||
| 25 | { |
||
| 26 | if (!is_callable($do)) { |
||
| 27 | throw new \InvalidArgumentException('Third argument must be a callable'); |
||
| 28 | } |
||
| 29 | |||
| 30 | foreach ($values as $single) { |
||
| 31 | $result = $do($single, $args); |
||
| 32 | if ($strict && !$result) { |
||
| 33 | break; |
||
| 34 | } |
||
| 35 | } |
||
| 36 | |||
| 37 | return $result; |
||
|
|
|||
| 38 | } |
||
| 39 | |||
| 56 |
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: