| Conditions | 5 |
| Paths | 12 |
| Total Lines | 22 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 16 |
| CRAP Score | 5 |
| Changes | 0 | ||
| 1 | <?php |
||
| 47 | 1 | public function getChain($uri) |
|
| 48 | {
|
||
| 49 | 1 | list($clean) = explode('?', $uri);
|
|
| 50 | 1 | $chain = explode('/', $clean);
|
|
| 51 | 1 | foreach($chain as $k => $v) {
|
|
| 52 | 1 | if(!$v) {
|
|
| 53 | 1 | unset($chain[$k]); |
|
| 54 | 1 | } |
|
| 55 | 1 | } |
|
| 56 | |||
| 57 | 1 | $chain = array_values($chain); |
|
| 58 | |||
| 59 | 1 | if(!count($chain)) {
|
|
| 60 | 1 | $chain[] = 'index'; |
|
| 61 | 1 | } |
|
| 62 | |||
| 63 | 1 | if(count($chain) == 1) {
|
|
| 64 | 1 | $chain[] = 'index'; |
|
| 65 | 1 | } |
|
| 66 | |||
| 67 | 1 | return $chain; |
|
| 68 | } |
||
| 69 | } |
||
| 70 |
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: