Passed
Push — master ( d12975...4562cc )
by Darío
02:14
created
src/Mvc/Router.php 1 patch
Braces   +11 added lines, -8 removed lines patch added patch discarded remove patch
@@ -145,8 +145,9 @@  discard block
 block discarded – undo
145 145
         $module = (is_null($this->identifiers["module"]) || empty($this->identifiers["module"]))
146 146
                     ? $this->routes["defaults"]["module"] : $this->identifiers["module"];
147 147
 
148
-        if (!array_key_exists($module, $this->routes))
149
-            throw new Exception\ModuleNotFoundException("The key '$module' does not exists in routes!");
148
+        if (!array_key_exists($module, $this->routes)) {
149
+                    throw new Exception\ModuleNotFoundException("The key '$module' does not exists in routes!");
150
+        }
150 151
 
151 152
         $controller = (is_null($this->identifiers["controller"]) || empty($this->identifiers["controller"]))
152 153
                     ? $this->routes[$module]["controller"] : $this->identifiers["controller"];
@@ -156,10 +157,11 @@  discard block
 block discarded – undo
156 157
 
157 158
         $fqn_controller = '\\' . $module . "\Controller\\" . $controller;
158 159
 
159
-        if (class_exists($fqn_controller))
160
-            $this->controller = new $fqn_controller($module, $view, $this->basePath);
161
-        else
162
-            throw new Exception\ControllerNotFoundException("The control class '$fqn_controller' does not exists!");
160
+        if (class_exists($fqn_controller)) {
161
+                    $this->controller = new $fqn_controller($module, $view, $this->basePath);
162
+        } else {
163
+                    throw new Exception\ControllerNotFoundException("The control class '$fqn_controller' does not exists!");
164
+        }
163 165
     }
164 166
 
165 167
     /**
@@ -176,8 +178,9 @@  discard block
 block discarded – undo
176 178
         $key = array_keys($route);
177 179
         $key = array_shift($key);
178 180
 
179
-        if (array_key_exists($key, $this->routes))
180
-            throw new \LogicException("The key '$key' was already defined as route");
181
+        if (array_key_exists($key, $this->routes)) {
182
+                    throw new \LogicException("The key '$key' was already defined as route");
183
+        }
181 184
 
182 185
         $this->routes = array_merge($this->routes, $route);
183 186
     }
Please login to merge, or discard this patch.
src/Mvc/Application.php 1 patch
Braces   +9 added lines, -8 removed lines patch added patch discarded remove patch
@@ -58,8 +58,9 @@  discard block
 block discarded – undo
58 58
     public function prepare()
59 59
     {
60 60
         # start sessions
61
-        if (!isset($_SESSION))
62
-            session_start();
61
+        if (!isset($_SESSION)) {
62
+                    session_start();
63
+        }
63 64
     }
64 65
 
65 66
     /**
@@ -91,8 +92,7 @@  discard block
 block discarded – undo
91 92
 
92 93
             // Best way to view all possible errors
93 94
             error_reporting(-1);
94
-        }
95
-        else {
95
+        } else {
96 96
             ini_set('display_errors', 0);
97 97
             error_reporting(-1);
98 98
         }
@@ -132,14 +132,15 @@  discard block
 block discarded – undo
132 132
                  *  This instruction include each module declared in application.config.php
133 133
                  *  Each module has an autoloader to load its classes (controllers and models)
134 134
                  */
135
-                if (file_exists("module/".$module."/Module.php"))
136
-                    include("module/".$module."/Module.php");
135
+                if (file_exists("module/".$module."/Module.php")) {
136
+                                    include("module/".$module."/Module.php");
137
+                }
137 138
 
138 139
                 spl_autoload_register($module . "\Module::loader");
139 140
             }
141
+        } else {
142
+                    throw new \RuntimeException("The application must have at least one module");
140 143
         }
141
-        else
142
-            throw new \RuntimeException("The application must have at least one module");
143 144
     }
144 145
 
145 146
     /**
Please login to merge, or discard this patch.
src/Mvc/AbstractionModule.php 1 patch
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -80,7 +80,8 @@
 block discarded – undo
80 80
 
81 81
         $class = "module/" . $module . "/source/" . implode("/", $nm) . ".php";
82 82
 
83
-        if (file_exists($class))
84
-            include $class;
83
+        if (file_exists($class)) {
84
+                    include $class;
85
+        }
85 86
     }
86 87
 }
87 88
\ No newline at end of file
Please login to merge, or discard this patch.
src/Db/Driver/MySQL.php 1 patch
Braces   +46 added lines, -35 removed lines patch added patch discarded remove patch
@@ -24,15 +24,17 @@  discard block
 block discarded – undo
24 24
      */
25 25
     public function __construct($options)
26 26
     {
27
-        if (!array_key_exists("dbchar", $options))
28
-            $options["dbchar"] = "utf8";
27
+        if (!array_key_exists("dbchar", $options)) {
28
+                    $options["dbchar"] = "utf8";
29
+        }
29 30
 
30 31
         parent::__construct($options);
31 32
 
32 33
         $auto_connect = array_key_exists('auto_connect', $options) ? $options["auto_connect"] : true;
33 34
 
34
-        if ($auto_connect)
35
-            $this->connect();
35
+        if ($auto_connect) {
36
+                    $this->connect();
37
+        }
36 38
     }
37 39
 
38 40
     /**
@@ -45,13 +47,15 @@  discard block
 block discarded – undo
45 47
      */
46 48
     public function connect()
47 49
     {
48
-        if (!extension_loaded('mysqli'))
49
-            throw new \RuntimeException("The Mysqli extension is not loaded");
50
+        if (!extension_loaded('mysqli')) {
51
+                    throw new \RuntimeException("The Mysqli extension is not loaded");
52
+        }
50 53
 
51
-        if (!is_null($this->dbport) && !empty($this->dbport))
52
-            $this->dbconn = @new \mysqli($this->dbhost, $this->dbuser, $this->dbpass, $this->dbname, $this->dbport);
53
-        else
54
-            $this->dbconn = @new \mysqli($this->dbhost, $this->dbuser, $this->dbpass, $this->dbname);
54
+        if (!is_null($this->dbport) && !empty($this->dbport)) {
55
+                    $this->dbconn = @new \mysqli($this->dbhost, $this->dbuser, $this->dbpass, $this->dbname, $this->dbport);
56
+        } else {
57
+                    $this->dbconn = @new \mysqli($this->dbhost, $this->dbuser, $this->dbpass, $this->dbname);
58
+        }
55 59
 
56 60
         if ($this->dbconn->connect_errno)
57 61
         {
@@ -61,9 +65,9 @@  discard block
 block discarded – undo
61 65
              * the warning message "Property access is not allowed yet".
62 66
              */
63 67
             throw new Exception\ConnectionException(mysqli_connect_error(), mysqli_connect_errno());
68
+        } else {
69
+                    $this->dbconn->set_charset($this->dbchar);
64 70
         }
65
-        else
66
-            $this->dbconn->set_charset($this->dbchar);
67 71
 
68 72
         return $this->dbconn;
69 73
     }
@@ -106,13 +110,15 @@  discard block
 block discarded – undo
106 110
 
107 111
             for ($i = 0; $i < $n_params; $i++)
108 112
             {
109
-                if (is_string($param_values[$i]))
110
-                    $bind_types .= 's';
111
-                else if(is_float($param_values[$i]))
112
-                    $bind_types .= 'd';
113
+                if (is_string($param_values[$i])) {
114
+                                    $bind_types .= 's';
115
+                } else if(is_float($param_values[$i])) {
116
+                                    $bind_types .= 'd';
117
+                }
113 118
                 # [POSSIBLE BUG] - To Future revision (What about non-string and non-decimal types ?)
114
-                else
115
-                    $bind_types .= 's';
119
+                else {
120
+                                    $bind_types .= 's';
121
+                }
116 122
 
117 123
                 $bind_values[] = '$param_values[' . $i . ']';
118 124
             }
@@ -133,12 +139,12 @@  discard block
 block discarded – undo
133 139
                      * It is useful to prevent rollback transactions on insert statements because
134 140
                      * insert statement do not free results.
135 141
                      */
136
-                    if ($res)
137
-                        $this->result = $res;
142
+                    if ($res) {
143
+                                            $this->result = $res;
144
+                    }
138 145
                 }
139 146
             }
140
-        }
141
-        else
147
+        } else
142 148
         {
143 149
             $prev_error_handler = set_error_handler(['\Drone\Error\ErrorHandler', 'errorControlOperator'], E_ALL);
144 150
 
@@ -154,17 +160,21 @@  discard block
 block discarded – undo
154 160
             throw new Exception\InvalidQueryException($this->dbconn->error, $this->dbconn->errno);
155 161
         }
156 162
 
157
-        if (is_object($this->result) && property_exists($this->result, 'num_rows'))
158
-            $this->numRows = $this->result->num_rows;
163
+        if (is_object($this->result) && property_exists($this->result, 'num_rows')) {
164
+                    $this->numRows = $this->result->num_rows;
165
+        }
159 166
 
160
-        if (is_object($this->result) && property_exists($this->result, 'field_count'))
161
-            $this->numFields = $this->result->field_count;
167
+        if (is_object($this->result) && property_exists($this->result, 'field_count')) {
168
+                    $this->numFields = $this->result->field_count;
169
+        }
162 170
 
163
-        if (is_object($this->result) && property_exists($this->result, 'affected_rows'))
164
-            $this->rowsAffected = $this->result->affected_rows;
171
+        if (is_object($this->result) && property_exists($this->result, 'affected_rows')) {
172
+                    $this->rowsAffected = $this->result->affected_rows;
173
+        }
165 174
 
166
-        if ($this->transac_mode)
167
-            $this->transac_result = is_null($this->transac_result) ? $this->result: $this->transac_result && $this->result;
175
+        if ($this->transac_mode) {
176
+                    $this->transac_result = is_null($this->transac_result) ? $this->result: $this->transac_result && $this->result;
177
+        }
168 178
 
169 179
         return $this->result;
170 180
     }
@@ -220,9 +230,8 @@  discard block
 block discarded – undo
220 230
             {
221 231
                 $data[] = $row;
222 232
             }
223
-        }
224
-        else
225
-            /*
233
+        } else {
234
+                    /*
226 235
              * "This kind of exception should lead directly to a fix in your code"
227 236
              * So much production tests tell us this error is throwed because developers
228 237
              * execute toArray() before execute().
@@ -230,6 +239,7 @@  discard block
 block discarded – undo
230 239
              * Ref: http://php.net/manual/en/class.logicexception.php
231 240
              */
232 241
             throw new \LogicException('There are not data in the buffer!');
242
+        }
233 243
 
234 244
         $this->arrayResult = $data;
235 245
 
@@ -244,7 +254,8 @@  discard block
 block discarded – undo
244 254
     public function __destruct()
245 255
     {
246 256
         # prevent "Property access is not allowed yet" with @ on failure connections
247
-        if ($this->dbconn !== false && !is_null($this->dbconn))
248
-            @$this->dbconn->close();
257
+        if ($this->dbconn !== false && !is_null($this->dbconn)) {
258
+                    @$this->dbconn->close();
259
+        }
249 260
     }
250 261
 }
251 262
\ No newline at end of file
Please login to merge, or discard this patch.
src/Db/Driver/DriverAdapter.php 1 patch
Braces   +8 added lines, -7 removed lines patch added patch discarded remove patch
@@ -85,13 +85,14 @@  discard block
 block discarded – undo
85 85
             "Sqlsrv" => "Drone\Db\Driver\SQLServer",
86 86
         ];
87 87
 
88
-        if (gettype($connection_identifier) == 'array')
89
-            $connection_array = $connection_identifier;
90
-        else
88
+        if (gettype($connection_identifier) == 'array') {
89
+                    $connection_array = $connection_identifier;
90
+        } else
91 91
         {
92 92
             # Take connection parameters from configuration file
93
-            if (!file_exists("config/database.config.php"))
94
-                throw new \RuntimeException("config/data.base.config.php is missing!");
93
+            if (!file_exists("config/database.config.php")) {
94
+                            throw new \RuntimeException("config/data.base.config.php is missing!");
95
+            }
95 96
 
96 97
             $dbsettings = include("config/database.config.php");
97 98
             $connection_array = $dbsettings[$connection_identifier];
@@ -106,8 +107,8 @@  discard block
 block discarded – undo
106 107
 
107 108
             $this->driverName = $drv;
108 109
             $this->db = new $driver[$drv]($connection_array);
110
+        } else {
111
+                    throw new \RuntimeException("The Database driver does not exists");
109 112
         }
110
-        else
111
-            throw new \RuntimeException("The Database driver does not exists");
112 113
     }
113 114
 }
114 115
\ No newline at end of file
Please login to merge, or discard this patch.
src/Db/SQLFunction.php 1 patch
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -77,8 +77,9 @@
 block discarded – undo
77 77
 
78 78
         foreach ($arguments as $key => $arg)
79 79
         {
80
-            if (is_string($arg))
81
-                $arguments[$key] = "'$arg'";
80
+            if (is_string($arg)) {
81
+                            $arguments[$key] = "'$arg'";
82
+            }
82 83
         }
83 84
 
84 85
         $arguments = implode(", ", array_values($arguments));
Please login to merge, or discard this patch.
src/Db/TableGateway/AbstractTableGateway.php 1 patch
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -73,7 +73,8 @@
 block discarded – undo
73 73
     {
74 74
         $this->currentDriverIdentifier = $connection_identifier;
75 75
 
76
-        if (!isset(self::$drivers[$connection_identifier]))
77
-            self::$drivers[$connection_identifier] = new DriverAdapter($connection_identifier, $auto_connect);
76
+        if (!isset(self::$drivers[$connection_identifier])) {
77
+                    self::$drivers[$connection_identifier] = new DriverAdapter($connection_identifier, $auto_connect);
78
+        }
78 79
     }
79 80
 }
80 81
\ No newline at end of file
Please login to merge, or discard this patch.
src/Db/TableGateway/EntityAdapter.php 1 patch
Braces   +21 added lines, -16 removed lines patch added patch discarded remove patch
@@ -58,8 +58,9 @@  discard block
 block discarded – undo
58 58
     {
59 59
         $result = $this->tableGateway->select($where);
60 60
 
61
-        if (!count($result))
62
-            return $result;
61
+        if (!count($result)) {
62
+                    return $result;
63
+        }
63 64
 
64 65
         $array_result = [];
65 66
 
@@ -69,8 +70,9 @@  discard block
 block discarded – undo
69 70
 
70 71
             foreach ($row as $key => $value)
71 72
             {
72
-                if (is_string($key))
73
-                    $filtered_array[$key] = $value;
73
+                if (is_string($key)) {
74
+                                    $filtered_array[$key] = $value;
75
+                }
74 76
             }
75 77
 
76 78
             $user_entity = get_class($this->tableGateway->getEntity());
@@ -94,10 +96,11 @@  discard block
 block discarded – undo
94 96
      */
95 97
     public function insert($entity)
96 98
     {
97
-        if ($entity instanceof Entity)
98
-            $entity = get_object_vars($entity);
99
-        else if (!is_array($entity))
100
-            throw new \InvalidArgumentException("Invalid type given. Drone\Db\Entity or Array expected");
99
+        if ($entity instanceof Entity) {
100
+                    $entity = get_object_vars($entity);
101
+        } else if (!is_array($entity)) {
102
+                    throw new \InvalidArgumentException("Invalid type given. Drone\Db\Entity or Array expected");
103
+        }
101 104
 
102 105
         $this->parseEntity($entity);
103 106
 
@@ -126,14 +129,15 @@  discard block
 block discarded – undo
126 129
 
127 130
             foreach ($entity as $key => $value)
128 131
             {
129
-                if (in_array($key, $changedFields))
130
-                    $fieldsToModify[$key] = $value;
132
+                if (in_array($key, $changedFields)) {
133
+                                    $fieldsToModify[$key] = $value;
134
+                }
131 135
             }
132 136
 
133 137
             $entity = $fieldsToModify;
138
+        } else if (!is_array($entity)) {
139
+                    throw new \InvalidArgumentException("Invalid type given. Drone\Db\Entity or Array expected");
134 140
         }
135
-        else if (!is_array($entity))
136
-            throw new \InvalidArgumentException("Invalid type given. Drone\Db\Entity or Array expected");
137 141
 
138 142
         $this->parseEntity($entity);
139 143
 
@@ -152,10 +156,11 @@  discard block
 block discarded – undo
152 156
      */
153 157
     public function delete($entity)
154 158
     {
155
-        if ($entity instanceof Entity)
156
-            $entity = get_object_vars($entity);
157
-        else if (!is_array($entity))
158
-            throw new \InvalidArgumentException("Invalid type given. Drone\Db\Entity or Array expected");
159
+        if ($entity instanceof Entity) {
160
+                    $entity = get_object_vars($entity);
161
+        } else if (!is_array($entity)) {
162
+                    throw new \InvalidArgumentException("Invalid type given. Drone\Db\Entity or Array expected");
163
+        }
159 164
 
160 165
         return $this->tableGateway->delete($entity);
161 166
     }
Please login to merge, or discard this patch.
src/Mvc/Layout.php 1 patch
Braces   +22 added lines, -16 removed lines patch added patch discarded remove patch
@@ -133,8 +133,9 @@  discard block
 block discarded – undo
133 133
     {
134 134
         $config = $module->getConfig();
135 135
 
136
-        if (!array_key_exists($view, $config["view_manager"]["view_map"]) || !file_exists($config["view_manager"]["view_map"][$view]))
137
-            throw new Exception\ViewNotFoundException("The 'view' template " . $view . " does not exists");
136
+        if (!array_key_exists($view, $config["view_manager"]["view_map"]) || !file_exists($config["view_manager"]["view_map"][$view])) {
137
+                    throw new Exception\ViewNotFoundException("The 'view' template " . $view . " does not exists");
138
+        }
138 139
 
139 140
         $this->view = $config["view_manager"]["view_map"][$view];
140 141
     }
@@ -164,8 +165,9 @@  discard block
 block discarded – undo
164 165
     {
165 166
         foreach ($params as $param => $value)
166 167
         {
167
-            if (property_exists(__CLASS__, strtolower($param)) && method_exists($this, 'set'.$param))
168
-                $this->{'set'.$param}($value);
168
+            if (property_exists(__CLASS__, strtolower($param)) && method_exists($this, 'set'.$param)) {
169
+                            $this->{'set'.$param}($value);
170
+            }
169 171
         }
170 172
     }
171 173
 
@@ -194,23 +196,26 @@  discard block
 block discarded – undo
194 196
 
195 197
         if ($controller->getTerminal())
196 198
         {
197
-            if (file_exists($view))
198
-                include $view;
199
-        }
200
-        else
199
+            if (file_exists($view)) {
200
+                            include $view;
201
+            }
202
+        } else
201 203
         {
202
-            if (!is_null($this->view) && !file_exists($this->view))
203
-                throw new Exception\ViewNotFoundException("The 'view' template " . $this->view . " does not exists");
204
+            if (!is_null($this->view) && !file_exists($this->view)) {
205
+                            throw new Exception\ViewNotFoundException("The 'view' template " . $this->view . " does not exists");
206
+            }
204 207
 
205 208
             $config = $controller->getModule()->getConfig();
206 209
 
207
-            if (!array_key_exists($controller->getLayout(), $config["view_manager"]["template_map"]))
208
-                throw new Exception\PageNotFoundException("The 'template' " . $template . " was not defined in module.config.php");
210
+            if (!array_key_exists($controller->getLayout(), $config["view_manager"]["template_map"])) {
211
+                            throw new Exception\PageNotFoundException("The 'template' " . $template . " was not defined in module.config.php");
212
+            }
209 213
 
210 214
             $template = $config["view_manager"]["template_map"][$controller->getLayout()];
211 215
 
212
-            if (!file_exists($template))
213
-                throw new Exception\PageNotFoundException("The 'template' " . $template . " does not exists");
216
+            if (!file_exists($template)) {
217
+                            throw new Exception\PageNotFoundException("The 'template' " . $template . " does not exists");
218
+            }
214 219
 
215 220
             include $template;
216 221
         }
@@ -237,8 +242,9 @@  discard block
 block discarded – undo
237 242
      */
238 243
     public function content()
239 244
     {
240
-        if (!file_exists($this->view))
241
-            throw new Exception\ViewNotFoundException("The 'view' template " . $this->view . " does not exists");
245
+        if (!file_exists($this->view)) {
246
+                    throw new Exception\ViewNotFoundException("The 'view' template " . $this->view . " does not exists");
247
+        }
242 248
 
243 249
         include $this->view;
244 250
     }
Please login to merge, or discard this patch.