| Conditions | 4 |
| Paths | 4 |
| Total Lines | 18 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 12 |
| CRAP Score | 4 |
| Changes | 2 | ||
| Bugs | 1 | Features | 0 |
| 1 | <?php |
||
| 48 | 12 | public function match($method, $uri) |
|
| 49 | { |
||
| 50 | 12 | $routeInfo = $this->dispatcher->dispatch($method, $uri); |
|
| 51 | |||
| 52 | 12 | switch ($routeInfo[0]) { |
|
| 53 | 12 | case Dispatcher::FOUND: |
|
| 54 | 6 | $result = new Result($this->routes[$routeInfo[1]], $routeInfo[2]); |
|
| 55 | 6 | break; |
|
| 56 | |||
| 57 | 6 | case Dispatcher::METHOD_NOT_ALLOWED: |
|
| 58 | 3 | throw new MethodNotAllowedException($method, $routeInfo[1]); |
|
| 59 | |||
| 60 | 3 | case Dispatcher::NOT_FOUND: |
|
| 61 | 3 | throw new NotFoundException($uri); |
|
| 62 | 6 | } |
|
| 63 | |||
| 64 | 6 | return $result; |
|
|
|
|||
| 65 | } |
||
| 66 | } |
||
| 67 |
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: