Passed
Push — master ( 6b8118...1ac76f )
by Darío
01:44
created
src/Mvc/Layout.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -193,8 +193,8 @@  discard block
 block discarded – undo
193 193
     {
194 194
         foreach ($params as $param => $value)
195 195
         {
196
-            if (property_exists(__CLASS__, strtolower($param)) && method_exists($this, 'set'.$param))
197
-                $this->{'set'.$param}($value);
196
+            if (property_exists(__CLASS__, strtolower($param)) && method_exists($this, 'set' . $param))
197
+                $this->{'set' . $param}($value);
198 198
         }
199 199
     }
200 200
 
@@ -218,11 +218,11 @@  discard block
 block discarded – undo
218 218
             $view = "";
219 219
 
220 220
             if (!is_null($controller->getModule()))
221
-                $view .= $controller->getModule()->getModulePath() .'/'. $controller->getModule()->getModuleName();
221
+                $view .= $controller->getModule()->getModulePath() . '/' . $controller->getModule()->getModuleName();
222 222
 
223 223
             $view .=
224
-                    '/'. $controller->getModule()->getModulePath() . '/'. basename(str_replace('\\','/',get_class($controller))) .
225
-                    '/'. $controller->getMethod() . '.phtml';
224
+                    '/' . $controller->getModule()->getModulePath() . '/' . basename(str_replace('\\', '/', get_class($controller))) .
225
+                    '/' . $controller->getMethod() . '.phtml';
226 226
 
227 227
             $this->view = $view;
228 228
         }
Please login to merge, or discard this patch.
Braces   +25 added lines, -18 removed lines patch added patch discarded remove patch
@@ -162,8 +162,9 @@  discard block
 block discarded – undo
162 162
     {
163 163
         $config = $module->getConfig();
164 164
 
165
-        if (!array_key_exists($view, $config["view_manager"]["view_map"]) || !file_exists($config["view_manager"]["view_map"][$view]))
166
-            throw new Exception\ViewNotFoundException("The 'view' template " . $view . " does not exists");
165
+        if (!array_key_exists($view, $config["view_manager"]["view_map"]) || !file_exists($config["view_manager"]["view_map"][$view])) {
166
+                    throw new Exception\ViewNotFoundException("The 'view' template " . $view . " does not exists");
167
+        }
167 168
 
168 169
         $this->view = $config["view_manager"]["view_map"][$view];
169 170
     }
@@ -193,8 +194,9 @@  discard block
 block discarded – undo
193 194
     {
194 195
         foreach ($params as $param => $value)
195 196
         {
196
-            if (property_exists(__CLASS__, strtolower($param)) && method_exists($this, 'set'.$param))
197
-                $this->{'set'.$param}($value);
197
+            if (property_exists(__CLASS__, strtolower($param)) && method_exists($this, 'set'.$param)) {
198
+                            $this->{'set'.$param}($value);
199
+            }
198 200
         }
199 201
     }
200 202
 
@@ -217,8 +219,9 @@  discard block
 block discarded – undo
217 219
         {
218 220
             $view = "";
219 221
 
220
-            if (!is_null($controller->getModule()))
221
-                $view .= $controller->getModule()->getModulePath() .'/'. $controller->getModule()->getModuleName();
222
+            if (!is_null($controller->getModule())) {
223
+                            $view .= $controller->getModule()->getModulePath() .'/'. $controller->getModule()->getModuleName();
224
+            }
222 225
 
223 226
             $view .=
224 227
                     '/'. $controller->getModule()->getModulePath() . '/'. basename(str_replace('\\','/',get_class($controller))) .
@@ -229,25 +232,28 @@  discard block
 block discarded – undo
229 232
 
230 233
         if ($controller->getTerminal())
231 234
         {
232
-            if (file_exists($view))
233
-                include $view;
234
-        }
235
-        else
235
+            if (file_exists($view)) {
236
+                            include $view;
237
+            }
238
+        } else
236 239
         {
237
-            if (!is_null($this->view) && !file_exists($this->view))
238
-                throw new Exception\ViewNotFoundException("The 'view' template " . $this->view . " does not exists");
240
+            if (!is_null($this->view) && !file_exists($this->view)) {
241
+                            throw new Exception\ViewNotFoundException("The 'view' template " . $this->view . " does not exists");
242
+            }
239 243
 
240 244
             $config = $controller->getModule()->getConfig();
241 245
 
242 246
             $layout = $controller->getLayout();
243 247
 
244
-            if (!array_key_exists($controller->getLayout(), $config["view_manager"]["template_map"]))
245
-                throw new Exception\PageNotFoundException("The 'template' " . $layout . " was not defined in module.config.php");
248
+            if (!array_key_exists($controller->getLayout(), $config["view_manager"]["template_map"])) {
249
+                            throw new Exception\PageNotFoundException("The 'template' " . $layout . " was not defined in module.config.php");
250
+            }
246 251
 
247 252
             $template = $config["view_manager"]["template_map"][$controller->getLayout()];
248 253
 
249
-            if (!file_exists($template))
250
-                throw new Exception\PageNotFoundException("The 'template' " . $template . " does not exists");
254
+            if (!file_exists($template)) {
255
+                            throw new Exception\PageNotFoundException("The 'template' " . $template . " does not exists");
256
+            }
251 257
 
252 258
             include $template;
253 259
         }
@@ -276,8 +282,9 @@  discard block
 block discarded – undo
276 282
      */
277 283
     public function content()
278 284
     {
279
-        if (!file_exists($this->view))
280
-            throw new Exception\ViewNotFoundException("The 'view' template " . $this->view . " does not exists");
285
+        if (!file_exists($this->view)) {
286
+                    throw new Exception\ViewNotFoundException("The 'view' template " . $this->view . " does not exists");
287
+        }
281 288
 
282 289
         include $this->view;
283 290
     }
Please login to merge, or discard this patch.
src/Mvc/AbstractController.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -313,7 +313,7 @@
 block discarded – undo
313 313
         if ($_SERVER['REQUEST_METHOD'] != 'JSON')
314 314
             throw new \LogicException("Request method is not JSON");
315 315
 
316
-        $input =  file_get_contents('php://input');
316
+        $input = file_get_contents('php://input');
317 317
         $array = explode("&", $input);
318 318
 
319 319
         $result = [];
Please login to merge, or discard this patch.
Braces   +25 added lines, -18 removed lines patch added patch discarded remove patch
@@ -213,8 +213,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
Please login to merge, or discard this patch.
test/Mvc/ControllerTest.php 1 patch
Braces   +4 added lines, -8 removed lines patch added patch discarded remove patch
@@ -61,12 +61,10 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
         }
Please login to merge, or discard this patch.
src/Mvc/Router.php 1 patch
Braces   +22 added lines, -18 removed lines patch added patch discarded remove patch
@@ -141,8 +141,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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;
Please login to merge, or discard this patch.