1 | <?php |
||
8 | class RedisUtility implements RedisAwareInterface |
||
9 | { |
||
10 | use RedisAwareTrait; |
||
11 | |||
12 | protected $flag = 'NOT-USED'; |
||
13 | protected $misses = 0; |
||
14 | protected $hits = 0; |
||
15 | |||
16 | /** |
||
17 | * Sets the Redis Missed Flag |
||
18 | * |
||
19 | * @param string $flag |
||
20 | */ |
||
21 | public function setFlag($flag) |
||
25 | |||
26 | /** |
||
27 | * Sets the Redis Missed Flag, which the response class will pull out to send to the headers |
||
28 | * |
||
29 | * @return string |
||
30 | */ |
||
31 | public function getFlag() |
||
35 | |||
36 | /** |
||
37 | * Sets the Redis Missed Flag, which the response class will pull out to send to the headers |
||
38 | * |
||
39 | * @return int |
||
40 | */ |
||
41 | public function getMissCount() |
||
45 | |||
46 | /** |
||
47 | * Sets the Redis Missed Flag, which the response class will pull out to send to the headers |
||
48 | * |
||
49 | * @return int |
||
50 | */ |
||
51 | public function getHitCount() |
||
55 | |||
56 | /** |
||
57 | * Checks redis for a entry and returns it decoded if exists |
||
58 | * |
||
59 | * @param string $store Redis store to pull data from |
||
60 | * @param string $type player|outfit |
||
61 | * @param string $id ID of player or outfit |
||
62 | * @param string $encodeType Flag to change format of data |
||
63 | * |
||
64 | * @return string|boolean |
||
65 | */ |
||
66 | public function checkRedis($store = 'api', $type, $id, $encodeType = 'array') |
||
90 | |||
91 | /** |
||
92 | * Stores the complete information in Redis |
||
93 | * |
||
94 | * @param string $namespace Split between cache and API |
||
95 | * @param string $type |
||
96 | * @param string $id |
||
97 | * @param string $data |
||
98 | * @param integer $time Time in seconds to store data |
||
99 | * |
||
100 | * @throws \Exception |
||
101 | * |
||
102 | * @return boolean |
||
103 | */ |
||
104 | public function storeInRedis($namespace = 'api', $type, $id, $data, $time = 0) |
||
124 | |||
125 | |||
126 | /** |
||
127 | * Sets the missed flag for Redis based on scenario. |
||
128 | * |
||
129 | * @param string $mode |
||
130 | * |
||
131 | * @return void |
||
132 | */ |
||
133 | public function checkFlagScenario(string $mode) |
||
160 | } |
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: