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