| Conditions | 1 |
| Paths | 2 |
| Total Lines | 17 |
| Code Lines | 7 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 7 | public function process(HTTPRequest $request, callable $delegate) |
||
| 8 | { |
||
| 9 | try { |
||
| 10 | // Start session and execute |
||
| 11 | $request->getSession()->init(); |
||
| 12 | |||
| 13 | // Generate output |
||
| 14 | $response = $delegate($request); |
||
| 15 | |||
| 16 | // Save session data, even if there was an exception. |
||
| 17 | // Note that save() will start/resume the session if required. |
||
| 18 | } finally { |
||
| 19 | $request->getSession()->save(); |
||
| 20 | } |
||
| 21 | |||
| 22 | return $response; |
||
|
|
|||
| 23 | } |
||
| 24 | } |
||
| 25 |
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: