| Conditions | 7 |
| Paths | 14 |
| Total Lines | 29 |
| Code Lines | 18 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 11 |
| CRAP Score | 10.6588 |
| Changes | 0 | ||
| 1 | <?php |
||
| 17 | 1 | public function process($uri) |
|
| 18 | {
|
||
| 19 | 1 | list($controller, $method) = $this->getChain($uri); |
|
| 20 | 1 | $className = "Controllers\\".ucfirst($controller); |
|
| 21 | 1 | $class = $this->app->get(Filesystem::class)->completeClassName($className); |
|
| 22 | 1 | if(!class_exists($class)) {
|
|
| 23 | $frameworkClass = $this->app->get(Framework::class)->completeClassName($className); |
||
| 24 | } |
||
| 25 | |||
| 26 | 1 | if(!class_exists($class)) {
|
|
| 27 | if(!class_exists($frameworkClass)) {
|
||
|
|
|||
| 28 | throw new LogicException("No class for $controller $controller, [$class, $frameworkClass]");
|
||
| 29 | } |
||
| 30 | $class = $frameworkClass; |
||
| 31 | } |
||
| 32 | |||
| 33 | 1 | if(!method_exists($class, $method)) {
|
|
| 34 | return "$controller/$method not found"; |
||
| 35 | } |
||
| 36 | |||
| 37 | 1 | $container = $this->app->get(Container::class); |
|
| 38 | 1 | $result = $container->call([$container->get($class), $method]); |
|
| 39 | |||
| 40 | 1 | if(is_array($result) || is_object($result)) {
|
|
| 41 | return json_encode($result); |
||
| 42 | } else {
|
||
| 43 | 1 | return $result; |
|
| 44 | } |
||
| 45 | } |
||
| 46 | |||
| 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: