Passed
Branch master (f0e7b7)
by Darío
02:39 queued 11s
created
src/Exception/Storage.php 1 patch
Braces   +9 added lines, -6 removed lines patch added patch discarded remove patch
@@ -76,17 +76,20 @@
 block discarded – undo
76 76
             "object"  => serialize($exception)
77 77
         ];
78 78
 
79
-        if (!function_exists('mb_detect_encoding'))
80
-            throw new \RuntimeException("mbstring library is not installed!");
79
+        if (!function_exists('mb_detect_encoding')) {
80
+                    throw new \RuntimeException("mbstring library is not installed!");
81
+        }
81 82
 
82 83
         /*
83 84
          * Encodes to UTF8 all messages. It ensures JSON encoding.
84 85
          */
85
-        if (!mb_detect_encoding($data[$id]["message"], 'UTF-8', true))
86
-            $data[$id]["message"] = utf8_encode($data[$id]["message"]);
86
+        if (!mb_detect_encoding($data[$id]["message"], 'UTF-8', true)) {
87
+                    $data[$id]["message"] = utf8_encode($data[$id]["message"]);
88
+        }
87 89
 
88
-        if (!mb_detect_encoding($data[$id]["object"], 'UTF-8', true))
89
-            $data[$id]["object"] = utf8_decode($data[$id]["object"]);
90
+        if (!mb_detect_encoding($data[$id]["object"], 'UTF-8', true)) {
91
+                    $data[$id]["object"] = utf8_decode($data[$id]["object"]);
92
+        }
90 93
 
91 94
         if (($encoded_data = json_encode($data)) === false)
92 95
         {
Please login to merge, or discard this patch.
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/Entity.php 1 patch
Braces   +5 added lines, -4 removed lines patch added patch discarded remove patch
@@ -109,11 +109,12 @@
 block discarded – undo
109 109
             {
110 110
                 $this->$prop = $value;
111 111
 
112
-                if (!in_array($prop, $this->changedFields))
113
-                    $this->changedFields[] = $prop;
112
+                if (!in_array($prop, $this->changedFields)) {
113
+                                    $this->changedFields[] = $prop;
114
+                }
115
+            } else {
116
+                            throw new \LogicException("The property '$prop' does not exists in the class '$class'");
114 117
             }
115
-            else
116
-                throw new \LogicException("The property '$prop' does not exists in the class '$class'");
117 118
         }
118 119
     }
119 120
 
Please login to merge, or discard this patch.
src/Db/Driver/AbstractDriver.php 1 patch
Braces   +29 added lines, -20 removed lines patch added patch discarded remove patch
@@ -209,8 +209,9 @@  discard block
 block discarded – undo
209 209
      */
210 210
     public function getArrayResult()
211 211
     {
212
-        if ($this->arrayResult)
213
-            return $this->arrayResult;
212
+        if ($this->arrayResult) {
213
+                    return $this->arrayResult;
214
+        }
214 215
 
215 216
         return $this->toArray();
216 217
     }
@@ -298,8 +299,9 @@  discard block
 block discarded – undo
298 299
     {
299 300
         foreach ($options as $option => $value)
300 301
         {
301
-            if (property_exists(__CLASS__, strtolower($option)) && method_exists($this, 'set'.$option))
302
-                $this->{'set'.$option}($value);
302
+            if (property_exists(__CLASS__, strtolower($option)) && method_exists($this, 'set'.$option)) {
303
+                            $this->{'set'.$option}($value);
304
+            }
303 305
         }
304 306
     }
305 307
 
@@ -343,8 +345,9 @@  discard block
 block discarded – undo
343 345
      */
344 346
     public function reconnect()
345 347
     {
346
-        if (!$this->isConnected())
347
-            throw new \LogicException("Connection was not established");
348
+        if (!$this->isConnected()) {
349
+                    throw new \LogicException("Connection was not established");
350
+        }
348 351
 
349 352
         $this->disconnect();
350 353
         return $this->connect();
@@ -373,8 +376,9 @@  discard block
 block discarded – undo
373 376
      */
374 377
     public function disconnect()
375 378
     {
376
-        if (!$this->isConnected())
377
-            throw new \LogicException("Connection was not established");
379
+        if (!$this->isConnected()) {
380
+                    throw new \LogicException("Connection was not established");
381
+        }
378 382
     }
379 383
 
380 384
     /**
@@ -386,11 +390,13 @@  discard block
 block discarded – undo
386 390
      */
387 391
     public function beginTransaction()
388 392
     {
389
-        if (!$this->isConnected())
390
-            $this->connect();
393
+        if (!$this->isConnected()) {
394
+                    $this->connect();
395
+        }
391 396
 
392
-        if ($this->transac_mode)
393
-            throw new \LogicException($this->standardErrors[Errno::DB_TRANSACTION_STARTED]);
397
+        if ($this->transac_mode) {
398
+                    throw new \LogicException($this->standardErrors[Errno::DB_TRANSACTION_STARTED]);
399
+        }
394 400
 
395 401
         $this->transac_mode = true;
396 402
     }
@@ -404,16 +410,19 @@  discard block
 block discarded – undo
404 410
      */
405 411
     public function endTransaction()
406 412
     {
407
-        if (!$this->transac_mode)
408
-            throw new \LogicException($this->standardErrors[Errno::DB_TRANSACTION_NOT_STARTED]);
413
+        if (!$this->transac_mode) {
414
+                    throw new \LogicException($this->standardErrors[Errno::DB_TRANSACTION_NOT_STARTED]);
415
+        }
409 416
 
410
-        if (is_null($this->transac_result))
411
-            throw new \LogicException($this->standardErrors[Errno::DB_TRANSACTION_EMPTY]);
417
+        if (is_null($this->transac_result)) {
418
+                    throw new \LogicException($this->standardErrors[Errno::DB_TRANSACTION_EMPTY]);
419
+        }
412 420
 
413
-        if ($this->transac_result)
414
-            $this->commit();
415
-        else
416
-            $this->rollback();
421
+        if ($this->transac_result) {
422
+                    $this->commit();
423
+        } else {
424
+                    $this->rollback();
425
+        }
417 426
 
418 427
         $this->result = $this->transac_result;
419 428
 
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/Oracle.php 1 patch
Braces   +25 added lines, -19 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"] = "AL32UTF8";
27
+        if (!array_key_exists("dbchar", $options)) {
28
+                    $options["dbchar"] = "AL32UTF8";
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,8 +47,9 @@  discard block
 block discarded – undo
45 47
      */
46 48
     public function connect()
47 49
     {
48
-        if (!extension_loaded('oci8'))
49
-            throw new \RuntimeException("The Oci8 extension is not loaded");
50
+        if (!extension_loaded('oci8')) {
51
+                    throw new \RuntimeException("The Oci8 extension is not loaded");
52
+        }
50 53
 
51 54
         $connection_string = (is_null($this->dbhost) || empty($this->dbhost))
52 55
             ? $this->dbname
@@ -97,14 +100,15 @@  discard block
 block discarded – undo
97 100
                 ];
98 101
 
99 102
                 $this->error($error["message"]);
103
+            } else {
104
+                            $this->error($error["code"], $error["message"]);
100 105
             }
101
-            else
102
-                $this->error($error["code"], $error["message"]);
103 106
 
104
-            if (array_key_exists("code", $error))
105
-                throw new Exception\InvalidQueryException($error["message"], $error["code"]);
106
-            else
107
-                throw new Exception\InvalidQueryException($error["message"]);
107
+            if (array_key_exists("code", $error)) {
108
+                            throw new Exception\InvalidQueryException($error["message"], $error["code"]);
109
+            } else {
110
+                            throw new Exception\InvalidQueryException($error["message"]);
111
+            }
108 112
         }
109 113
 
110 114
         # Bound variables
@@ -142,8 +146,9 @@  discard block
 block discarded – undo
142 146
         $this->numRows = count($rows);
143 147
         $this->numFields = oci_num_fields($stid);
144 148
 
145
-        if ($this->transac_mode)
146
-            $this->transac_result = is_null($this->transac_result) ? $this->result: $this->transac_result && $this->result;
149
+        if ($this->transac_mode) {
150
+                    $this->transac_result = is_null($this->transac_result) ? $this->result: $this->transac_result && $this->result;
151
+        }
147 152
 
148 153
         return $this->result;
149 154
     }
@@ -190,9 +195,8 @@  discard block
 block discarded – undo
190 195
             {
191 196
                 $data[] = $row;
192 197
             }
193
-        }
194
-        else
195
-            /*
198
+        } else {
199
+                    /*
196 200
              * "This kind of exception should lead directly to a fix in your code"
197 201
              * So much production tests tell us this error is throwed because developers
198 202
              * execute toArray() before execute().
@@ -200,6 +204,7 @@  discard block
 block discarded – undo
200 204
              * Ref: http://php.net/manual/en/class.logicexception.php
201 205
              */
202 206
             throw new \LogicException('There are not data in the buffer!');
207
+        }
203 208
 
204 209
         $this->arrayResult = $data;
205 210
 
@@ -213,7 +218,8 @@  discard block
 block discarded – undo
213 218
      */
214 219
     public function __destruct()
215 220
     {
216
-        if ($this->dbconn)
217
-            oci_close($this->dbconn);
221
+        if ($this->dbconn) {
222
+                    oci_close($this->dbconn);
223
+        }
218 224
     }
219 225
 }
220 226
\ 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.