1 | <?php |
||
20 | class FirebaseResponce |
||
21 | { |
||
22 | |||
23 | /** |
||
24 | * Data from Firebase |
||
25 | * |
||
26 | * @var array $firebaseData |
||
27 | */ |
||
28 | protected $firebaseData; |
||
29 | |||
30 | /** |
||
31 | * Type of operation |
||
32 | * |
||
33 | * @var string $operation |
||
34 | */ |
||
35 | protected $operation; |
||
36 | |||
37 | /** |
||
38 | * Http server code |
||
39 | * |
||
40 | * @var integer $status |
||
41 | */ |
||
42 | protected $status; |
||
43 | |||
44 | /** |
||
45 | * Format to array the responce |
||
46 | * |
||
47 | * @return array $firebaseData |
||
48 | */ |
||
49 | public function getFirebaseData(): array |
||
53 | |||
54 | /** |
||
55 | * Type of Operation |
||
56 | * |
||
57 | * @return string $operation |
||
58 | */ |
||
59 | public function getOperation(): string |
||
63 | |||
64 | /** |
||
65 | * Status from http server |
||
66 | * |
||
67 | * @return integer $status |
||
68 | */ |
||
69 | public function getStatus(): int |
||
73 | |||
74 | /** |
||
75 | * Set data from firebase api |
||
76 | * |
||
77 | * @param array $firebaseData |
||
78 | */ |
||
79 | protected function setFirebaseData($firebaseData) |
||
83 | |||
84 | /** |
||
85 | * Set type of operation |
||
86 | * |
||
87 | * @param string $operation |
||
88 | */ |
||
89 | protected function setOperation($operation) |
||
93 | |||
94 | /** |
||
95 | * Set status responce |
||
96 | * |
||
97 | * @param integer $status |
||
98 | */ |
||
99 | protected function setStatus($status) |
||
103 | |||
104 | /** |
||
105 | * Method for validate data arrives in _costruct. |
||
106 | * If all data was correct skip function without returns. |
||
107 | * |
||
108 | * @throws \Exception |
||
109 | */ |
||
110 | protected function validateResponce() |
||
125 | |||
126 | /** |
||
127 | * Validate type of data receved |
||
128 | * |
||
129 | * @throws \Exception |
||
130 | */ |
||
131 | private function validateOperation() |
||
140 | |||
141 | /** |
||
142 | * Validate type of data receved |
||
143 | * |
||
144 | * @throws \Exception |
||
145 | */ |
||
146 | private function validateStatus() |
||
155 | |||
156 | /** |
||
157 | * Validate type of data receved |
||
158 | * |
||
159 | * @throws \Exception |
||
160 | */ |
||
161 | private function validateData() |
||
168 | |||
169 | /** |
||
170 | * Validate type of json receved |
||
171 | * |
||
172 | * @return string |
||
173 | */ |
||
174 | protected function validateJson():string |
||
193 | } |
||
194 |
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: