Conditions | 3 |
Paths | 1 |
Total Lines | 18 |
Code Lines | 9 |
Lines | 0 |
Ratio | 0 % |
Tests | 12 |
CRAP Score | 3 |
Changes | 3 | ||
Bugs | 2 | Features | 0 |
1 | <?php |
||
26 | 15 | public function __construct(array $routes) |
|
27 | { |
||
28 | 15 | $this->routes = array(); |
|
29 | |||
30 | 15 | $this->dispatcher = FastRoute\simpleDispatcher(function (RouteCollector $collector) use ($routes) { |
|
31 | 15 | foreach ($routes as $route) { |
|
32 | 12 | if (!$route instanceof RouteInterface) { |
|
33 | 3 | throw new \InvalidArgumentException('Routes array must contain only RouteInterface objects'); |
|
34 | } |
||
35 | |||
36 | 9 | $key = spl_object_hash($route); |
|
37 | |||
38 | 9 | $this->routes[$key] = $route; |
|
39 | |||
40 | 9 | $collector->addRoute($route->getMethods(), $route->getPattern(), $key); |
|
41 | 12 | } |
|
42 | 15 | }); |
|
43 | 12 | } |
|
44 | |||
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: