Passed
Push — master ( 9b30b3...3078fb )
by Darío
01:46
created
test/Db/Driver/MySQLTest.php 1 patch
Braces   +9 added lines, -18 removed lines patch added patch discarded remove patch
@@ -84,12 +84,10 @@  discard block
 block discarded – undo
84 84
 
85 85
         try {
86 86
             $conn->disconnect();
87
-        }
88
-        catch (\Exception $e)
87
+        } catch (\Exception $e)
89 88
         {
90 89
             $errorObject = ($e instanceof \LogicException);
91
-        }
92
-        finally
90
+        } finally
93 91
         {
94 92
             $this->assertNotTrue($conn->isConnected());
95 93
             $this->assertTrue($errorObject, $e->getMessage());
@@ -125,12 +123,10 @@  discard block
 block discarded – undo
125 123
 
126 124
         try {
127 125
             $conn->reconnect();
128
-        }
129
-        catch (\Exception $e)
126
+        } catch (\Exception $e)
130 127
         {
131 128
             $errorObject = ($e instanceof \LogicException);
132
-        }
133
-        finally
129
+        } finally
134 130
         {
135 131
             $this->assertTrue($errorObject, $e->getMessage());
136 132
             $this->assertNotTrue($conn->isConnected());
@@ -155,13 +151,11 @@  discard block
 block discarded – undo
155 151
 
156 152
         try {
157 153
             $mysqliObject = $conn->connect();
158
-        }
159
-        catch (\Exception $e)
154
+        } catch (\Exception $e)
160 155
         {
161 156
             $errorObject = ($e instanceof ConnectionException);
162 157
             $message = $e->getMessage();
163
-        }
164
-        finally
158
+        } finally
165 159
         {
166 160
             $this->assertTrue($errorObject, $message);
167 161
             $this->assertNotTrue($conn->isConnected());
@@ -241,13 +235,11 @@  discard block
 block discarded – undo
241 235
         {
242 236
             $sql = "INSERT INTO MYTABLE (DESCRIPTION, WRONG) VALUES ('Hello world!')";
243 237
 	        $result = $conn->execute($sql);
244
-        }
245
-        catch (\Exception $e)
238
+        } catch (\Exception $e)
246 239
         {
247 240
             $errorObject = ($e instanceof InvalidQueryException);
248 241
             $message = $e->getMessage();
249
-        }
250
-        finally
242
+        } finally
251 243
         {
252 244
             $this->assertTrue($errorObject, $message);
253 245
         }
@@ -516,8 +508,7 @@  discard block
 block discarded – undo
516 508
 
517 509
 	        $sql = "INSERT INTO MYTABLE (DESCRIPTION, WRONG) VALUES ('TRANS_SHORTCUT_2')";
518 510
 	        $result = $conn->execute($sql);
519
-        }
520
-        catch (InvalidQueryException $e)
511
+        } catch (InvalidQueryException $e)
521 512
         {
522 513
             $message = $e->getMessage();
523 514
             #·not necessary!
Please login to merge, or discard this patch.
src/Db/Driver/MySQL.php 1 patch
Braces   +45 added lines, -36 removed lines patch added patch discarded remove patch
@@ -31,15 +31,17 @@  discard block
 block discarded – undo
31 31
      */
32 32
     public function __construct($options)
33 33
     {
34
-        if (!array_key_exists("dbchar", $options))
35
-            $options["dbchar"] = "utf8";
34
+        if (!array_key_exists("dbchar", $options)) {
35
+                    $options["dbchar"] = "utf8";
36
+        }
36 37
 
37 38
         parent::__construct($options);
38 39
 
39 40
         $auto_connect = array_key_exists('auto_connect', $options) ? $options["auto_connect"] : true;
40 41
 
41
-        if ($auto_connect)
42
-            $this->connect();
42
+        if ($auto_connect) {
43
+                    $this->connect();
44
+        }
43 45
     }
44 46
 
45 47
     /**
@@ -52,13 +54,15 @@  discard block
 block discarded – undo
52 54
      */
53 55
     public function connect()
54 56
     {
55
-        if (!extension_loaded('mysqli'))
56
-            throw new \RuntimeException("The Mysqli extension is not loaded");
57
+        if (!extension_loaded('mysqli')) {
58
+                    throw new \RuntimeException("The Mysqli extension is not loaded");
59
+        }
57 60
 
58
-        if (!is_null($this->dbport) && !empty($this->dbport))
59
-            $conn = @new \mysqli($this->dbhost, $this->dbuser, $this->dbpass, $this->dbname, $this->dbport);
60
-        else
61
-            $conn = @new \mysqli($this->dbhost, $this->dbuser, $this->dbpass, $this->dbname);
61
+        if (!is_null($this->dbport) && !empty($this->dbport)) {
62
+                    $conn = @new \mysqli($this->dbhost, $this->dbuser, $this->dbpass, $this->dbname, $this->dbport);
63
+        } else {
64
+                    $conn = @new \mysqli($this->dbhost, $this->dbuser, $this->dbpass, $this->dbname);
65
+        }
62 66
 
63 67
         if ($conn->connect_errno)
64 68
         {
@@ -68,8 +72,7 @@  discard block
 block discarded – undo
68 72
              * the warning message "Property access is not allowed yet".
69 73
              */
70 74
             throw new Exception\ConnectionException(mysqli_connect_error(), mysqli_connect_errno());
71
-        }
72
-        else
75
+        } else
73 76
         {
74 77
             $this->dbconn = $conn;
75 78
             $this->dbconn->set_charset($this->dbchar);
@@ -116,13 +119,15 @@  discard block
 block discarded – undo
116 119
 
117 120
             for ($i = 0; $i < $n_params; $i++)
118 121
             {
119
-                if (is_string($param_values[$i]))
120
-                    $bind_types .= 's';
121
-                else if(is_float($param_values[$i]))
122
-                    $bind_types .= 'd';
122
+                if (is_string($param_values[$i])) {
123
+                                    $bind_types .= 's';
124
+                } else if(is_float($param_values[$i])) {
125
+                                    $bind_types .= 'd';
126
+                }
123 127
                 # [POSSIBLE BUG] - To Future revision (What about non-string and non-decimal types ?)
124
-                else
125
-                    $bind_types .= 's';
128
+                else {
129
+                                    $bind_types .= 's';
130
+                }
126 131
 
127 132
                 $bind_values[] = '$param_values[' . $i . ']';
128 133
             }
@@ -143,12 +148,12 @@  discard block
 block discarded – undo
143 148
                      * It is useful to prevent rollback transactions on insert statements because
144 149
                      * insert statement do not free results.
145 150
                      */
146
-                    if ($res)
147
-                        $this->result = $res;
151
+                    if ($res) {
152
+                                            $this->result = $res;
153
+                    }
148 154
                 }
149 155
             }
150
-        }
151
-        else
156
+        } else
152 157
         {
153 158
             $prev_error_handler = set_error_handler(['\Drone\Error\ErrorHandler', 'errorControlOperator'], E_ALL);
154 159
 
@@ -165,20 +170,23 @@  discard block
 block discarded – undo
165 170
         }
166 171
 
167 172
         # identify SELECT, SHOW, DESCRIBE or EXPLAIN queries
168
-        if (is_object($this->result) && property_exists($this->result, 'num_rows'))
169
-            $this->numRows = $this->result->num_rows;
170
-        else
173
+        if (is_object($this->result) && property_exists($this->result, 'num_rows')) {
174
+                    $this->numRows = $this->result->num_rows;
175
+        } else
171 176
         {
172 177
             # affected_rows return the same of num_rows on select statements!
173
-            if (property_exists($this->dbconn, 'affected_rows'))
174
-                $this->rowsAffected = $this->dbconn->affected_rows;
178
+            if (property_exists($this->dbconn, 'affected_rows')) {
179
+                            $this->rowsAffected = $this->dbconn->affected_rows;
180
+            }
175 181
         }
176 182
 
177
-        if (property_exists($this->dbconn, 'field_count'))
178
-            $this->numFields = $this->dbconn->field_count;
183
+        if (property_exists($this->dbconn, 'field_count')) {
184
+                    $this->numFields = $this->dbconn->field_count;
185
+        }
179 186
 
180
-        if ($this->transac_mode)
181
-            $this->transac_result = is_null($this->transac_result) ? $this->result: $this->transac_result && $this->result;
187
+        if ($this->transac_mode) {
188
+                    $this->transac_result = is_null($this->transac_result) ? $this->result: $this->transac_result && $this->result;
189
+        }
182 190
 
183 191
         /*
184 192
          * Because mysqli_query() returns FALSE on failure, a mysqli_result object for SELECT, SHOW, DESCRIBE or EXPLAIN queries,
@@ -247,9 +255,8 @@  discard block
 block discarded – undo
247 255
             {
248 256
                 $data[] = $row;
249 257
             }
250
-        }
251
-        else
252
-            /*
258
+        } else {
259
+                    /*
253 260
              * "This kind of exception should lead directly to a fix in your code"
254 261
              * So much production tests tell us this error is throwed because developers
255 262
              * execute toArray() before execute().
@@ -257,6 +264,7 @@  discard block
 block discarded – undo
257 264
              * Ref: http://php.net/manual/en/class.logicexception.php
258 265
              */
259 266
             throw new \LogicException('There are not data in the buffer!');
267
+        }
260 268
 
261 269
         $this->arrayResult = $data;
262 270
 
@@ -271,7 +279,8 @@  discard block
 block discarded – undo
271 279
     public function __destruct()
272 280
     {
273 281
         # prevent "Property access is not allowed yet" with @ on failure connections
274
-        if ($this->dbconn !== false && !is_null($this->dbconn))
275
-            @$this->dbconn->close();
282
+        if ($this->dbconn !== false && !is_null($this->dbconn)) {
283
+                    @$this->dbconn->close();
284
+        }
276 285
     }
277 286
 }
278 287
\ No newline at end of file
Please login to merge, or discard this patch.