Passed
Push — master ( 8f50d0...6b8118 )
by Darío
01:40
created
src/Mvc/AbstractModule.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
      */
169 169
     public function getConfig()
170 170
     {
171
-        return include($this->modulePath .'/' . $this->getModuleName() . '/config/module.config.php');
171
+        return include($this->modulePath . '/' . $this->getModuleName() . '/config/module.config.php');
172 172
     }
173 173
 
174 174
     /**
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
         $nm = explode('\\', $name);
184 184
         $module = array_shift($nm);
185 185
 
186
-        $class = $this->modulePath ."/". $module . "/source/" . implode("/", $nm) . ".php";
186
+        $class = $this->modulePath . "/" . $module . "/source/" . implode("/", $nm) . ".php";
187 187
 
188 188
         if (file_exists($class))
189 189
             include $class;
Please login to merge, or discard this patch.
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -185,7 +185,8 @@
 block discarded – undo
185 185
 
186 186
         $class = $this->modulePath ."/". $module . "/source/" . implode("/", $nm) . ".php";
187 187
 
188
-        if (file_exists($class))
189
-            include $class;
188
+        if (file_exists($class)) {
189
+                    include $class;
190
+        }
190 191
     }
191 192
 }
192 193
\ 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
@@ -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/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 $e)
196
+            } catch (Exception\MethodNotFoundException $e)
196 197
             {
197 198
                 # change context, in terms of Router MethodNotFoundException is a PageNotfoundException
198 199
                 throw new Exception\PageNotFoundException($e->getMessage(), $e->getCode(), $e);
@@ -207,9 +208,9 @@  discard block
 block discarded – undo
207 208
             $this->controller->getModule()->setViewPath('source/view');
208 209
 
209 210
             $this->controller->execute();
211
+        } else {
212
+                    throw new Exception\ControllerNotFoundException("The control class '$fqn_controller' does not exists!");
210 213
         }
211
-        else
212
-            throw new Exception\ControllerNotFoundException("The control class '$fqn_controller' does not exists!");
213 214
     }
214 215
 
215 216
     /**
@@ -226,8 +227,9 @@  discard block
 block discarded – undo
226 227
         $key = array_keys($route);
227 228
         $key = array_shift($key);
228 229
 
229
-        if (array_key_exists($key, $this->routes))
230
-            throw new \LogicException("The key '$key' was already defined as route");
230
+        if (array_key_exists($key, $this->routes)) {
231
+                    throw new \LogicException("The key '$key' was already defined as route");
232
+        }
231 233
 
232 234
         $this->routes = array_merge($this->routes, $route);
233 235
     }
@@ -268,10 +270,11 @@  discard block
 block discarded – undo
268 270
         $i = 1;
269 271
         foreach ($params as $item)
270 272
         {
271
-            if ($i % 2 != 0)
272
-                $vars[] = $item;
273
-            else
274
-                $values[] = $item;
273
+            if ($i % 2 != 0) {
274
+                            $vars[] = $item;
275
+            } else {
276
+                            $values[] = $item;
277
+            }
275 278
             $i++;
276 279
         }
277 280
 
@@ -281,10 +284,11 @@  discard block
 block discarded – undo
281 284
 
282 285
         for ($i = 0; $i < $vars_count; $i++)
283 286
         {
284
-            if (array_key_exists($i, $values))
285
-                $result[$vars[$i]] = $values[$i];
286
-            else
287
-                $result[$vars[$i]] = '';
287
+            if (array_key_exists($i, $values)) {
288
+                            $result[$vars[$i]] = $values[$i];
289
+            } else {
290
+                            $result[$vars[$i]] = '';
291
+            }
288 292
         }
289 293
 
290 294
         return $result;
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->initExecution)
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\MethodNotFoundException("The method '$method' is not public in the control class '$class'");
246
+                if (!$reflection->isPublic()) {
247
+                                    throw new Exception\MethodNotFoundException("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'");
@@ -295,8 +297,9 @@  discard block
 block discarded – undo
295 297
      */
296 298
     public function getPost()
297 299
     {
298
-        if ($_SERVER['REQUEST_METHOD'] == 'POST' && empty($_POST))
299
-            $_POST = json_decode(file_get_contents('php://input'), true);
300
+        if ($_SERVER['REQUEST_METHOD'] == 'POST' && empty($_POST)) {
301
+                    $_POST = json_decode(file_get_contents('php://input'), true);
302
+        }
300 303
 
301 304
         return (array) $_POST;
302 305
     }
@@ -310,8 +313,9 @@  discard block
 block discarded – undo
310 313
      */
311 314
     public function getJson()
312 315
     {
313
-        if ($_SERVER['REQUEST_METHOD'] != 'JSON')
314
-            throw new \LogicException("Request method is not JSON");
316
+        if ($_SERVER['REQUEST_METHOD'] != 'JSON') {
317
+                    throw new \LogicException("Request method is not JSON");
318
+        }
315 319
 
316 320
         $input =  file_get_contents('php://input');
317 321
         $array = explode("&", $input);
@@ -335,8 +339,9 @@  discard block
 block discarded – undo
335 339
     public function isXmlHttpRequest()
336 340
     {
337 341
         # non standard (HTTP_X_REQUESTED_WITH is not a part of PHP)
338
-        if (isset($_SERVER['HTTP_X_REQUESTED_WITH']))
339
-            return true;
342
+        if (isset($_SERVER['HTTP_X_REQUESTED_WITH'])) {
343
+                    return true;
344
+        }
340 345
         return false;
341 346
     }
342 347
 
@@ -347,8 +352,9 @@  discard block
 block discarded – undo
347 352
      */
348 353
     public function isPost()
349 354
     {
350
-        if ($_SERVER["REQUEST_METHOD"] == "POST")
351
-            return true;
355
+        if ($_SERVER["REQUEST_METHOD"] == "POST") {
356
+                    return true;
357
+        }
352 358
         return false;
353 359
     }
354 360
 
@@ -359,8 +365,9 @@  discard block
 block discarded – undo
359 365
      */
360 366
     public function isGet()
361 367
     {
362
-        if ($_SERVER["REQUEST_METHOD"] == "GET")
363
-            return true;
368
+        if ($_SERVER["REQUEST_METHOD"] == "GET") {
369
+                    return true;
370
+        }
364 371
         return false;
365 372
     }
366 373
 }
367 374
\ No newline at end of file
Please login to merge, or discard this patch.
src/Mvc/Application.php 1 patch
Braces   +43 added lines, -32 removed lines patch added patch discarded remove patch
@@ -92,19 +92,23 @@  discard block
 block discarded – undo
92 92
     public function __construct(Array $config)
93 93
     {
94 94
         # start sessions
95
-        if (!isset($_SESSION))
96
-            session_start();
95
+        if (!isset($_SESSION)) {
96
+                    session_start();
97
+        }
97 98
 
98
-        if (!array_key_exists('environment', $config))
99
-            throw new \InvalidArgumentException("The 'environment' key was not defined");
99
+        if (!array_key_exists('environment', $config)) {
100
+                    throw new \InvalidArgumentException("The 'environment' key was not defined");
101
+        }
100 102
 
101
-        if (!array_key_exists('dev_mode', $config['environment']))
102
-            throw new \InvalidArgumentException("The 'dev_mode' key was not defined");
103
+        if (!array_key_exists('dev_mode', $config['environment'])) {
104
+                    throw new \InvalidArgumentException("The 'dev_mode' key was not defined");
105
+        }
103 106
 
104 107
         $this->devMode = $config["environment"]["dev_mode"];
105 108
 
106
-        if (!array_key_exists('modules', $config))
107
-            throw new \InvalidArgumentException("The 'modules' key was not defined");
109
+        if (!array_key_exists('modules', $config)) {
110
+                    throw new \InvalidArgumentException("The 'modules' key was not defined");
111
+        }
108 112
 
109 113
         $this->modules = $config["modules"];
110 114
 
@@ -118,8 +122,7 @@  discard block
 block discarded – undo
118 122
         {
119 123
             ini_set('display_errors', 1);
120 124
             error_reporting(-1);
121
-        }
122
-        else
125
+        } else
123 126
         {
124 127
             ini_set('display_errors', 0);
125 128
             error_reporting(0);
@@ -128,26 +131,30 @@  discard block
 block discarded – undo
128 131
         # register autoloading functions for each module
129 132
         $this->autoload($this->modules);
130 133
 
131
-        if (!array_key_exists('router', $config))
132
-            throw new \InvalidArgumentException("The 'router' key was not defined");
134
+        if (!array_key_exists('router', $config)) {
135
+                    throw new \InvalidArgumentException("The 'router' key was not defined");
136
+        }
133 137
 
134
-        if (!array_key_exists('routes', $config["router"]))
135
-            throw new \InvalidArgumentException("The 'routes' key was not defined");
138
+        if (!array_key_exists('routes', $config["router"])) {
139
+                    throw new \InvalidArgumentException("The 'routes' key was not defined");
140
+        }
136 141
 
137 142
         $this->router = new Router($config["router"]["routes"]);
138 143
 
139
-        if (!array_key_exists('base_path', $config['environment']))
140
-            throw new \InvalidArgumentException("The 'base_path' key was not defined");
144
+        if (!array_key_exists('base_path', $config['environment'])) {
145
+                    throw new \InvalidArgumentException("The 'base_path' key was not defined");
146
+        }
141 147
 
142 148
         $this->router->setBasePath($config["environment"]["base_path"]);
143 149
 
144 150
         # load routes from config
145 151
         foreach ($config["router"]["routes"] as $name => $route)
146 152
         {
147
-            if ($route instanceof \Zend\Router\Http\RouteInterface)
148
-                $this->getRouter()->addZendRoute($name, $route);
149
-            else
150
-                $this->getRouter()->addRoute($route);
153
+            if ($route instanceof \Zend\Router\Http\RouteInterface) {
154
+                            $this->getRouter()->addZendRoute($name, $route);
155
+            } else {
156
+                            $this->getRouter()->addRoute($route);
157
+            }
151 158
         }
152 159
 
153 160
         # load routes from each module
@@ -157,11 +164,13 @@  discard block
 block discarded – undo
157 164
             {
158 165
                 $module_config_file = require($this->modulePath . "/$module/config/module.config.php");
159 166
 
160
-                if (!array_key_exists('router', $module_config_file))
161
-                    throw new \RuntimeException("The 'router' key was not defined in the config file for module '$module'");
167
+                if (!array_key_exists('router', $module_config_file)) {
168
+                                    throw new \RuntimeException("The 'router' key was not defined in the config file for module '$module'");
169
+                }
162 170
 
163
-                if (!array_key_exists('routes', $module_config_file["router"]))
164
-                    throw new \RuntimeException("The 'routes' key was not defined in the config file for module '$module'");
171
+                if (!array_key_exists('routes', $module_config_file["router"])) {
172
+                                    throw new \RuntimeException("The 'routes' key was not defined in the config file for module '$module'");
173
+                }
165 174
 
166 175
                 $this->getRouter()->addRoute($module_config_file["router"]["routes"]);
167 176
             }
@@ -190,14 +199,15 @@  discard block
 block discarded – undo
190 199
                  *  This instruction includes each module declared.
191 200
                  *  Each module has an autoloader to load its classes (controllers and models)
192 201
                  */
193
-                if (file_exists($this->modulePath ."/". $module."/Module.php"))
194
-                    include($this->modulePath ."/". $module."/Module.php");
202
+                if (file_exists($this->modulePath ."/". $module."/Module.php")) {
203
+                                    include($this->modulePath ."/". $module."/Module.php");
204
+                }
195 205
 
196 206
                 spl_autoload_register($module . "\Module::loader");
197 207
             }
208
+        } else {
209
+                    throw new \RuntimeException("The application must have at least one module");
198 210
         }
199
-        else
200
-            throw new \RuntimeException("The application must have at least one module");
201 211
     }
202 212
 
203 213
     /**
@@ -219,8 +229,9 @@  discard block
 block discarded – undo
219 229
         $uri .= !empty($controller) ? '/' . $controller : "";
220 230
         $uri .= !empty($view)       ? '/' . $view : "";
221 231
 
222
-        if (empty($uri))
223
-            $uri = "/";
232
+        if (empty($uri)) {
233
+                    $uri = "/";
234
+        }
224 235
 
225 236
         $request->setUri($uri);
226 237
 
@@ -236,9 +247,9 @@  discard block
 block discarded – undo
236 247
             $view       = $params["action"];
237 248
 
238 249
             $this->router->setIdentifiers($module, $controller, $view);
250
+        } else {
251
+                    $this->router->setIdentifiers($module, $controller, $view);
239 252
         }
240
-        else
241
-            $this->router->setIdentifiers($module, $controller, $view);
242 253
 
243 254
         $this->router->run();
244 255
     }
Please login to merge, or discard this patch.