Passed
Push — master ( 1f7fc5...40eec0 )
by Darío
02:01
created
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;
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.
src/Mvc/AbstractController.php 1 patch
Braces   +25 added lines, -18 removed lines patch added patch discarded remove patch
@@ -185,8 +185,9 @@  discard block
 block discarded – undo
185 185
 
186 186
             $fqn_module = "\\" . $module . "\\Module";
187 187
 
188
-            if (!class_exists($fqn_module))
189
-                throw new Exception\ModuleNotFoundException("The module class '$fqn_module' does not exists!");
188
+            if (!class_exists($fqn_module)) {
189
+                            throw new Exception\ModuleNotFoundException("The module class '$fqn_module' does not exists!");
190
+            }
190 191
 
191 192
             $this->module = new $fqn_module($module, $this, $router);
192 193
         }
@@ -201,9 +202,10 @@  discard block
 block discarded – undo
201 202
     {
202 203
         $method = $this->method;
203 204
 
204
-        if (is_null($method))
205
-            # This error is thrown because of 'setMethod' method has not been executed
205
+        if (is_null($method)) {
206
+                    # This error is thrown because of 'setMethod' method has not been executed
206 207
             throw new \LogicException("No method has been setted to execute!");
208
+        }
207 209
 
208 210
         if ($this->allowExecution)
209 211
         {
@@ -213,8 +215,9 @@  discard block
 block discarded – undo
213 215
 
214 216
                 $reflection = new \ReflectionMethod($this, $method);
215 217
 
216
-                if (!$reflection->isPublic())
217
-                    throw new Exception\PrivateMethodExecutionException("The method '$method' is not public in the control class '$class'");
218
+                if (!$reflection->isPublic()) {
219
+                                    throw new Exception\PrivateMethodExecutionException("The method '$method' is not public in the control class '$class'");
220
+                }
218 221
 
219 222
                 # Get the returned value of the method to send to the view
220 223
                 $this->params = $this->$method();
@@ -229,8 +232,7 @@  discard block
 block discarded – undo
229 232
                     $layoutManager = new Layout($layout_params);
230 233
                     $layoutManager->fromController($this);
231 234
                 }
232
-            }
233
-            else
235
+            } else
234 236
             {
235 237
                 $class = __CLASS__;
236 238
                 throw new Exception\MethodNotFoundException("The method '$method' doesn't exists in the control class '$class'");
@@ -277,8 +279,9 @@  discard block
 block discarded – undo
277 279
      */
278 280
     public function getPost()
279 281
     {
280
-        if ($_SERVER['REQUEST_METHOD'] == 'POST' && empty($_POST))
281
-            $_POST = json_decode(file_get_contents('php://input'), true);
282
+        if ($_SERVER['REQUEST_METHOD'] == 'POST' && empty($_POST)) {
283
+                    $_POST = json_decode(file_get_contents('php://input'), true);
284
+        }
282 285
 
283 286
         return (array) $_POST;
284 287
     }
@@ -292,8 +295,9 @@  discard block
 block discarded – undo
292 295
      */
293 296
     public function getJson()
294 297
     {
295
-        if ($_SERVER['REQUEST_METHOD'] != 'JSON')
296
-            throw new \LogicException("Request method is not JSON");
298
+        if ($_SERVER['REQUEST_METHOD'] != 'JSON') {
299
+                    throw new \LogicException("Request method is not JSON");
300
+        }
297 301
 
298 302
         $input =  file_get_contents('php://input');
299 303
         $array = explode("&", $input);
@@ -317,8 +321,9 @@  discard block
 block discarded – undo
317 321
     public function isXmlHttpRequest()
318 322
     {
319 323
         # non standard (HTTP_X_REQUESTED_WITH is not a part of PHP)
320
-        if (isset($_SERVER['HTTP_X_REQUESTED_WITH']))
321
-            return true;
324
+        if (isset($_SERVER['HTTP_X_REQUESTED_WITH'])) {
325
+                    return true;
326
+        }
322 327
         return false;
323 328
     }
324 329
 
@@ -329,8 +334,9 @@  discard block
 block discarded – undo
329 334
      */
330 335
     public function isPost()
331 336
     {
332
-        if ($_SERVER["REQUEST_METHOD"] == "POST")
333
-            return true;
337
+        if ($_SERVER["REQUEST_METHOD"] == "POST") {
338
+                    return true;
339
+        }
334 340
         return false;
335 341
     }
336 342
 
@@ -341,8 +347,9 @@  discard block
 block discarded – undo
341 347
      */
342 348
     public function isGet()
343 349
     {
344
-        if ($_SERVER["REQUEST_METHOD"] == "GET")
345
-            return true;
350
+        if ($_SERVER["REQUEST_METHOD"] == "GET") {
351
+                    return true;
352
+        }
346 353
         return false;
347 354
     }
348 355
 }
349 356
\ No newline at end of file
Please login to merge, or discard this patch.
src/Mvc/Layout.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -174,8 +174,8 @@  discard block
 block discarded – undo
174 174
     {
175 175
         foreach ($params as $param => $value)
176 176
         {
177
-            if (property_exists(__CLASS__, strtolower($param)) && method_exists($this, 'set'.$param))
178
-                $this->{'set'.$param}($value);
177
+            if (property_exists(__CLASS__, strtolower($param)) && method_exists($this, 'set' . $param))
178
+                $this->{'set' . $param}($value);
179 179
         }
180 180
     }
181 181
 
@@ -198,9 +198,9 @@  discard block
 block discarded – undo
198 198
 
199 199
         if ($controller->getShowView())
200 200
             $this->view =
201
-                $controller->getModule()->getModulePath() .'/'. $controller->getModule()->getModuleName() .'/'.
202
-                $controller->getModule()->getViewPath()                .'/'.
203
-                basename(str_replace('\\','/',get_class($controller))) .'/'.
201
+                $controller->getModule()->getModulePath() . '/' . $controller->getModule()->getModuleName() . '/' .
202
+                $controller->getModule()->getViewPath() . '/' .
203
+                basename(str_replace('\\', '/', get_class($controller))) . '/' .
204 204
                 $controller->getMethod() . '.phtml';
205 205
 
206 206
         if ($controller->getTerminal())
Please login to merge, or discard this patch.
Braces   +28 added lines, -20 removed lines patch added patch discarded remove patch
@@ -155,8 +155,9 @@  discard block
 block discarded – undo
155 155
     {
156 156
         $config = $module->getConfig();
157 157
 
158
-        if (!array_key_exists($view, $config["view_manager"]["view_map"]) || !file_exists($config["view_manager"]["view_map"][$view]))
159
-            throw new Exception\ViewNotFoundException("The 'view' template " . $view . " does not exists");
158
+        if (!array_key_exists($view, $config["view_manager"]["view_map"]) || !file_exists($config["view_manager"]["view_map"][$view])) {
159
+                    throw new Exception\ViewNotFoundException("The 'view' template " . $view . " does not exists");
160
+        }
160 161
 
161 162
         $this->view = $config["view_manager"]["view_map"][$view];
162 163
     }
@@ -174,8 +175,9 @@  discard block
 block discarded – undo
174 175
     {
175 176
         foreach ($params as $param => $value)
176 177
         {
177
-            if (property_exists(__CLASS__, strtolower($param)) && method_exists($this, 'set'.$param))
178
-                $this->{'set'.$param}($value);
178
+            if (property_exists(__CLASS__, strtolower($param)) && method_exists($this, 'set'.$param)) {
179
+                            $this->{'set'.$param}($value);
180
+            }
179 181
         }
180 182
     }
181 183
 
@@ -193,37 +195,42 @@  discard block
 block discarded – undo
193 195
         $this->setParams($controller->getParams());
194 196
         $this->controller = $controller;
195 197
 
196
-        if (is_null($controller->getModule()))
197
-            throw new \RuntimeException("No module instance found in controller '" . get_class($controller) . "'");
198
+        if (is_null($controller->getModule())) {
199
+                    throw new \RuntimeException("No module instance found in controller '" . get_class($controller) . "'");
200
+        }
198 201
 
199
-        if ($controller->getShowView())
200
-            $this->view =
202
+        if ($controller->getShowView()) {
203
+                    $this->view =
201 204
                 $controller->getModule()->getModulePath() .'/'. $controller->getModule()->getModuleName() .'/'.
202 205
                 $controller->getModule()->getViewPath()                .'/'.
203 206
                 basename(str_replace('\\','/',get_class($controller))) .'/'.
204 207
                 $controller->getMethod() . '.phtml';
208
+        }
205 209
 
206 210
         if ($controller->getTerminal())
207 211
         {
208
-            if (file_exists($this->view))
209
-                include $this->view;
210
-        }
211
-        else
212
+            if (file_exists($this->view)) {
213
+                            include $this->view;
214
+            }
215
+        } else
212 216
         {
213
-            if (!is_null($this->view) && !file_exists($this->view))
214
-                throw new Exception\ViewNotFoundException("The 'view' template " . $this->view . " does not exists");
217
+            if (!is_null($this->view) && !file_exists($this->view)) {
218
+                            throw new Exception\ViewNotFoundException("The 'view' template " . $this->view . " does not exists");
219
+            }
215 220
 
216 221
             $config = $controller->getModule()->getConfig();
217 222
 
218 223
             $layout = $controller->getLayout();
219 224
 
220
-            if (!array_key_exists($controller->getLayout(), $config["view_manager"]["template_map"]))
221
-                throw new Exception\PageNotFoundException("The 'template' " . $layout . " was not defined in module.config.php");
225
+            if (!array_key_exists($controller->getLayout(), $config["view_manager"]["template_map"])) {
226
+                            throw new Exception\PageNotFoundException("The 'template' " . $layout . " was not defined in module.config.php");
227
+            }
222 228
 
223 229
             $template = $config["view_manager"]["template_map"][$controller->getLayout()];
224 230
 
225
-            if (!file_exists($template))
226
-                throw new Exception\PageNotFoundException("The 'template' " . $template . " does not exists");
231
+            if (!file_exists($template)) {
232
+                            throw new Exception\PageNotFoundException("The 'template' " . $template . " does not exists");
233
+            }
227 234
 
228 235
             include $template;
229 236
         }
@@ -252,8 +259,9 @@  discard block
 block discarded – undo
252 259
      */
253 260
     public function content()
254 261
     {
255
-        if (!file_exists($this->view))
256
-            throw new Exception\ViewNotFoundException("The 'view' template " . $this->view . " does not exists");
262
+        if (!file_exists($this->view)) {
263
+                    throw new Exception\ViewNotFoundException("The 'view' template " . $this->view . " does not exists");
264
+        }
257 265
 
258 266
         include $this->view;
259 267
     }
Please login to merge, or discard this patch.
src/Mvc/AbstractModule.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
     public function getConfig()
199 199
     {
200 200
         return include(
201
-            $this->router->getBasePath() .'/'. $this->modulePath .'/' . $this->getModuleName() . '/config/module.config.php'
201
+            $this->router->getBasePath() . '/' . $this->modulePath . '/' . $this->getModuleName() . '/config/module.config.php'
202 202
         );
203 203
     }
204 204
 
@@ -214,7 +214,7 @@  discard block
 block discarded – undo
214 214
         $nm = explode('\\', $name);
215 215
         $module = array_shift($nm);
216 216
 
217
-        $class = $this->router->getBasePath() .'/'. $this->modulePath ."/". $module . "/source/" . implode("/", $nm) . ".php";
217
+        $class = $this->router->getBasePath() . '/' . $this->modulePath . "/" . $module . "/source/" . implode("/", $nm) . ".php";
218 218
 
219 219
         if (file_exists($class))
220 220
             include $class;
Please login to merge, or discard this patch.
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -216,7 +216,8 @@
 block discarded – undo
216 216
 
217 217
         $class = $this->router->getBasePath() .'/'. $this->modulePath ."/". $module . "/source/" . implode("/", $nm) . ".php";
218 218
 
219
-        if (file_exists($class))
220
-            include $class;
219
+        if (file_exists($class)) {
220
+                    include $class;
221
+        }
221 222
     }
222 223
 }
223 224
\ No newline at end of file
Please login to merge, or discard this patch.