1 | <?php |
||
22 | class Render implements HandlerInterface |
||
23 | { |
||
24 | /** |
||
25 | * Known handled content types. |
||
26 | * |
||
27 | * @var array |
||
28 | */ |
||
29 | protected $knownContentTypes = [ |
||
30 | 'application/json', |
||
31 | 'application/xml', |
||
32 | 'text/xml', |
||
33 | 'text/html', |
||
34 | ]; |
||
35 | |||
36 | /** |
||
37 | * {@inheritdoc} |
||
38 | */ |
||
39 | public function __invoke(ServerRequestInterface $request, ResponseInterface $response, Watcher $watcher) |
||
70 | |||
71 | /** |
||
72 | * Render HTML maintenance message. |
||
73 | * |
||
74 | * @param \Janitor\Watcher $watcher |
||
75 | * |
||
76 | * @return string |
||
77 | */ |
||
78 | protected function renderHtml(Watcher $watcher) |
||
93 | |||
94 | /** |
||
95 | * Render JSON maintenance message. |
||
96 | * |
||
97 | * @param \Janitor\Watcher $watcher |
||
98 | * |
||
99 | * @return string |
||
100 | */ |
||
101 | protected function renderJson(Watcher $watcher) |
||
105 | |||
106 | /** |
||
107 | * Render XML maintenance message. |
||
108 | * |
||
109 | * @param \Janitor\Watcher $watcher |
||
110 | * |
||
111 | * @return string |
||
112 | */ |
||
113 | protected function renderXml(Watcher $watcher) |
||
120 | |||
121 | /** |
||
122 | * Retrieve custom maintenance message. |
||
123 | * |
||
124 | * @param \Janitor\Watcher $watcher |
||
125 | * |
||
126 | * @return string |
||
127 | */ |
||
128 | protected function getMaintenanceMessage(Watcher $watcher) |
||
139 | |||
140 | /** |
||
141 | * Determine content type using Accept header. |
||
142 | * |
||
143 | * @param \Psr\Http\Message\ServerRequestInterface $request |
||
144 | * |
||
145 | * @return string |
||
146 | */ |
||
147 | private function determineContentType(ServerRequestInterface $request) |
||
156 | } |
||
157 |
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: