Conditions | 2 |
Paths | 2 |
Total Lines | 10 |
Code Lines | 6 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 6 |
Changes | 0 |
1 | <?php |
||
44 | public static function getNewFileName($view, $path, $prepend = ' '){ |
||
45 | $fileNum = 1; |
||
46 | |||
47 | while ($view->file_exists($path)){ |
||
48 | $fileNum += 1; |
||
49 | $path = preg_replace('/(\.|' . $prepend . '\(\d+\)\.)([^.]*)$/', $prepend . '(' . $fileNum . ').$2', $path); |
||
50 | }; |
||
51 | |||
52 | return $path; |
||
53 | } |
||
54 | } |
||
55 |
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: