@@ -61,12 +61,10 @@ discard block |
||
61 | 61 | try { |
62 | 62 | $ctrl->setMethod('doSomething'); |
63 | 63 | $ctrl->execute(); |
64 | - } |
|
65 | - catch (\Exception $e) |
|
64 | + } catch (\Exception $e) |
|
66 | 65 | { |
67 | 66 | $errorObject = ($e instanceof PrivateMethodExecutionException); |
68 | - } |
|
69 | - finally |
|
67 | + } finally |
|
70 | 68 | { |
71 | 69 | $this->assertTrue($errorObject, $e->getMessage()); |
72 | 70 | } |
@@ -86,12 +84,10 @@ discard block |
||
86 | 84 | try { |
87 | 85 | $ctrl->setMethod('notFound'); |
88 | 86 | $ctrl->execute(); |
89 | - } |
|
90 | - catch (\Exception $e) |
|
87 | + } catch (\Exception $e) |
|
91 | 88 | { |
92 | 89 | $errorObject = ($e instanceof MethodNotFoundException); |
93 | - } |
|
94 | - finally |
|
90 | + } finally |
|
95 | 91 | { |
96 | 92 | $this->assertTrue($errorObject, $e->getMessage()); |
97 | 93 | } |
@@ -141,8 +141,9 @@ discard block |
||
141 | 141 | */ |
142 | 142 | public function __construct(Array $routes = []) |
143 | 143 | { |
144 | - if (count($routes)) |
|
145 | - $this->routes = $routes; |
|
144 | + if (count($routes)) { |
|
145 | + $this->routes = $routes; |
|
146 | + } |
|
146 | 147 | |
147 | 148 | $this->zendRouter = new \Zend\Router\SimpleRouteStack(); |
148 | 149 | } |
@@ -176,8 +177,9 @@ discard block |
||
176 | 177 | $module = (is_null($this->identifiers["module"]) || empty($this->identifiers["module"])) |
177 | 178 | ? $this->routes["defaults"]["module"] : $this->identifiers["module"]; |
178 | 179 | |
179 | - if (!array_key_exists($module, $this->routes)) |
|
180 | - throw new Exception\ModuleNotFoundException("The key '$module' does not exists in routes!"); |
|
180 | + if (!array_key_exists($module, $this->routes)) { |
|
181 | + throw new Exception\ModuleNotFoundException("The key '$module' does not exists in routes!"); |
|
182 | + } |
|
181 | 183 | |
182 | 184 | $controller = (is_null($this->identifiers["controller"]) || empty($this->identifiers["controller"])) |
183 | 185 | ? $this->routes[$module]["controller"] : $this->identifiers["controller"]; |
@@ -191,8 +193,7 @@ discard block |
||
191 | 193 | { |
192 | 194 | try { |
193 | 195 | $this->controller = new $fqn_controller($view, $this->basePath); |
194 | - } |
|
195 | - catch (Exception\MethodNotFoundException | Exception\PrivateMethodExecutionException $e) |
|
196 | + } catch (Exception\MethodNotFoundException | Exception\PrivateMethodExecutionException $e) |
|
196 | 197 | { |
197 | 198 | # change context, in terms of Router MethodNotFoundException or |
198 | 199 | # PrivateMethodExecutionException is a PageNotfoundException |
@@ -208,9 +209,9 @@ discard block |
||
208 | 209 | $this->controller->getModule()->setViewPath('source/view'); |
209 | 210 | |
210 | 211 | $this->controller->execute(); |
212 | + } else { |
|
213 | + throw new Exception\ControllerNotFoundException("The control class '$fqn_controller' does not exists!"); |
|
211 | 214 | } |
212 | - else |
|
213 | - throw new Exception\ControllerNotFoundException("The control class '$fqn_controller' does not exists!"); |
|
214 | 215 | } |
215 | 216 | |
216 | 217 | /** |
@@ -227,8 +228,9 @@ discard block |
||
227 | 228 | $key = array_keys($route); |
228 | 229 | $key = array_shift($key); |
229 | 230 | |
230 | - if (array_key_exists($key, $this->routes)) |
|
231 | - throw new \LogicException("The key '$key' was already defined as route"); |
|
231 | + if (array_key_exists($key, $this->routes)) { |
|
232 | + throw new \LogicException("The key '$key' was already defined as route"); |
|
233 | + } |
|
232 | 234 | |
233 | 235 | $this->routes = array_merge($this->routes, $route); |
234 | 236 | } |
@@ -269,10 +271,11 @@ discard block |
||
269 | 271 | $i = 1; |
270 | 272 | foreach ($params as $item) |
271 | 273 | { |
272 | - if ($i % 2 != 0) |
|
273 | - $vars[] = $item; |
|
274 | - else |
|
275 | - $values[] = $item; |
|
274 | + if ($i % 2 != 0) { |
|
275 | + $vars[] = $item; |
|
276 | + } else { |
|
277 | + $values[] = $item; |
|
278 | + } |
|
276 | 279 | $i++; |
277 | 280 | } |
278 | 281 | |
@@ -282,10 +285,11 @@ discard block |
||
282 | 285 | |
283 | 286 | for ($i = 0; $i < $vars_count; $i++) |
284 | 287 | { |
285 | - if (array_key_exists($i, $values)) |
|
286 | - $result[$vars[$i]] = $values[$i]; |
|
287 | - else |
|
288 | - $result[$vars[$i]] = ''; |
|
288 | + if (array_key_exists($i, $values)) { |
|
289 | + $result[$vars[$i]] = $values[$i]; |
|
290 | + } else { |
|
291 | + $result[$vars[$i]] = ''; |
|
292 | + } |
|
289 | 293 | } |
290 | 294 | |
291 | 295 | return $result; |
@@ -213,8 +213,9 @@ discard block |
||
213 | 213 | |
214 | 214 | $fqn_module = "\\" . $module . "\\Module"; |
215 | 215 | |
216 | - if (!class_exists($fqn_module)) |
|
217 | - throw new Exception\ModuleNotFoundException("The module class '$fqn_module' does not exists!"); |
|
216 | + if (!class_exists($fqn_module)) { |
|
217 | + throw new Exception\ModuleNotFoundException("The module class '$fqn_module' does not exists!"); |
|
218 | + } |
|
218 | 219 | |
219 | 220 | $this->module = new $fqn_module($module, $this); |
220 | 221 | } |
@@ -229,9 +230,10 @@ discard block |
||
229 | 230 | { |
230 | 231 | $method = $this->method; |
231 | 232 | |
232 | - if (is_null($method)) |
|
233 | - # This error is thrown because of 'setMethod' method has not been executed |
|
233 | + if (is_null($method)) { |
|
234 | + # This error is thrown because of 'setMethod' method has not been executed |
|
234 | 235 | throw new \LogicException("No method has been setted to execute!"); |
236 | + } |
|
235 | 237 | |
236 | 238 | if ($this->allowExecution) |
237 | 239 | { |
@@ -241,8 +243,9 @@ discard block |
||
241 | 243 | |
242 | 244 | $reflection = new \ReflectionMethod($this, $method); |
243 | 245 | |
244 | - if (!$reflection->isPublic()) |
|
245 | - throw new Exception\PrivateMethodExecutionException("The method '$method' is not public in the control class '$class'"); |
|
246 | + if (!$reflection->isPublic()) { |
|
247 | + throw new Exception\PrivateMethodExecutionException("The method '$method' is not public in the control class '$class'"); |
|
248 | + } |
|
246 | 249 | |
247 | 250 | # Get the returned value of the method to send to the view |
248 | 251 | $this->params = $this->$method(); |
@@ -257,8 +260,7 @@ discard block |
||
257 | 260 | $layoutManager = new Layout($layout_params); |
258 | 261 | $layoutManager->fromController($this); |
259 | 262 | } |
260 | - } |
|
261 | - else |
|
263 | + } else |
|
262 | 264 | { |
263 | 265 | $class = __CLASS__; |
264 | 266 | throw new Exception\MethodNotFoundException("The method '$method' doesn't exists in the control class '$class'"); |
@@ -305,8 +307,9 @@ discard block |
||
305 | 307 | */ |
306 | 308 | public function getPost() |
307 | 309 | { |
308 | - if ($_SERVER['REQUEST_METHOD'] == 'POST' && empty($_POST)) |
|
309 | - $_POST = json_decode(file_get_contents('php://input'), true); |
|
310 | + if ($_SERVER['REQUEST_METHOD'] == 'POST' && empty($_POST)) { |
|
311 | + $_POST = json_decode(file_get_contents('php://input'), true); |
|
312 | + } |
|
310 | 313 | |
311 | 314 | return (array) $_POST; |
312 | 315 | } |
@@ -320,8 +323,9 @@ discard block |
||
320 | 323 | */ |
321 | 324 | public function getJson() |
322 | 325 | { |
323 | - if ($_SERVER['REQUEST_METHOD'] != 'JSON') |
|
324 | - throw new \LogicException("Request method is not JSON"); |
|
326 | + if ($_SERVER['REQUEST_METHOD'] != 'JSON') { |
|
327 | + throw new \LogicException("Request method is not JSON"); |
|
328 | + } |
|
325 | 329 | |
326 | 330 | $input = file_get_contents('php://input'); |
327 | 331 | $array = explode("&", $input); |
@@ -345,8 +349,9 @@ discard block |
||
345 | 349 | public function isXmlHttpRequest() |
346 | 350 | { |
347 | 351 | # non standard (HTTP_X_REQUESTED_WITH is not a part of PHP) |
348 | - if (isset($_SERVER['HTTP_X_REQUESTED_WITH'])) |
|
349 | - return true; |
|
352 | + if (isset($_SERVER['HTTP_X_REQUESTED_WITH'])) { |
|
353 | + return true; |
|
354 | + } |
|
350 | 355 | return false; |
351 | 356 | } |
352 | 357 | |
@@ -357,8 +362,9 @@ discard block |
||
357 | 362 | */ |
358 | 363 | public function isPost() |
359 | 364 | { |
360 | - if ($_SERVER["REQUEST_METHOD"] == "POST") |
|
361 | - return true; |
|
365 | + if ($_SERVER["REQUEST_METHOD"] == "POST") { |
|
366 | + return true; |
|
367 | + } |
|
362 | 368 | return false; |
363 | 369 | } |
364 | 370 | |
@@ -369,8 +375,9 @@ discard block |
||
369 | 375 | */ |
370 | 376 | public function isGet() |
371 | 377 | { |
372 | - if ($_SERVER["REQUEST_METHOD"] == "GET") |
|
373 | - return true; |
|
378 | + if ($_SERVER["REQUEST_METHOD"] == "GET") { |
|
379 | + return true; |
|
380 | + } |
|
374 | 381 | return false; |
375 | 382 | } |
376 | 383 | } |
377 | 384 | \ No newline at end of file |