Conditions | 6 |
Paths | 18 |
Total Lines | 30 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
16 | public function init(array $sessions, $executable = null) |
||
17 | { |
||
18 | if ($executable) { |
||
19 | $this->executable = $executable; |
||
20 | } |
||
21 | |||
22 | $this->sessionContainer = new SessionContainer(); |
||
23 | |||
24 | foreach ($sessions as $sessionName => $session) { |
||
25 | |||
26 | try { |
||
27 | $cookieMaker = new CookieMaker($this->executable); |
||
28 | $cookies = $cookieMaker->getCookies($session); |
||
29 | } catch (\Exception $e) { |
||
30 | $fallbackHelper = new FallbackHelper(); |
||
31 | if (!$fallbackHelper->isFallbackServer()) { |
||
32 | $fallbackHelper->doFallback($e->getMessage()); |
||
33 | exit(1); |
||
34 | } |
||
35 | } |
||
36 | |||
37 | $session = new Session(); |
||
38 | |||
39 | foreach ($cookies as $key => $value) { |
||
|
|||
40 | $session->addCookie($key, $value); |
||
41 | } |
||
42 | |||
43 | $this->sessionContainer->addSession($sessionName, $session); |
||
44 | } |
||
45 | } |
||
46 | |||
55 |
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: