Test Failed
Push — master ( 81e3a2...ed0ed2 )
by Joe
13:45
created
src/Mysqli/Db.php 1 patch
Braces   +24 added lines, -48 removed lines patch added patch discarded remove patch
@@ -17,8 +17,7 @@  discard block
 block discarded – undo
17 17
  *
18 18
  * @access public
19 19
  */
20
-class Db extends Generic implements Db_Interface
21
-{
20
+class Db extends Generic implements Db_Interface {
22 21
     /**
23 22
      * @var string
24 23
      */
@@ -30,8 +29,7 @@  discard block
 block discarded – undo
30 29
      * @param string $database the name of the database to use
31 30
      * @return void
32 31
      */
33
-    public function useDb($database)
34
-    {
32
+    public function useDb($database) {
35 33
         $this->selectDb($database);
36 34
     }
37 35
 
@@ -41,8 +39,7 @@  discard block
 block discarded – undo
41 39
      * @param string $database the name of the database to use
42 40
      * @return void
43 41
      */
44
-    public function selectDb($database)
45
-    {
42
+    public function selectDb($database) {
46 43
         $this->connect();
47 44
         mysqli_select_db($this->linkId, $database);
48 45
     }
@@ -57,8 +54,7 @@  discard block
 block discarded – undo
57 54
      * @param string $password
58 55
      * @return int|\mysqli
59 56
      */
60
-    public function connect($database = '', $host = '', $user = '', $password = '', $port = '')
61
-    {
57
+    public function connect($database = '', $host = '', $user = '', $password = '', $port = '') {
62 58
         /* Handle defaults */
63 59
         if ($database == '') {
64 60
             $database = $this->database;
@@ -105,8 +101,7 @@  discard block
 block discarded – undo
105 101
      * Db::disconnect()
106 102
      * @return bool
107 103
      */
108
-    public function disconnect()
109
-    {
104
+    public function disconnect() {
110 105
         $return = !is_int($this->linkId) && method_exists($this->linkId, 'close') ? $this->linkId->close() : false;
111 106
         $this->linkId = 0;
112 107
         return $return;
@@ -116,8 +111,7 @@  discard block
 block discarded – undo
116 111
      * @param $string
117 112
      * @return string
118 113
      */
119
-    public function real_escape($string = '')
120
-    {
114
+    public function real_escape($string = '') {
121 115
         if ((!is_resource($this->linkId) || $this->linkId == 0) && !$this->connect()) {
122 116
             return $this->escape($string);
123 117
         }
@@ -128,8 +122,7 @@  discard block
 block discarded – undo
128 122
      * discard the query result
129 123
      * @return void
130 124
      */
131
-    public function free()
132
-    {
125
+    public function free() {
133 126
         if (is_resource($this->queryId)) {
134 127
             @mysqli_free_result($this->queryId);
135 128
         }
@@ -147,8 +140,7 @@  discard block
 block discarded – undo
147 140
      * @param string $file optionally pass __FILE__ calling the query for logging
148 141
      * @return mixed FALSE if no rows, if a single row it returns that, if multiple it returns an array of rows, associative responses only
149 142
      */
150
-    public function queryReturn($query, $line = '', $file = '')
151
-    {
143
+    public function queryReturn($query, $line = '', $file = '') {
152 144
         $this->query($query, $line, $file);
153 145
         if ($this->num_rows() == 0) {
154 146
             return false;
@@ -174,8 +166,7 @@  discard block
 block discarded – undo
174 166
      * @param string $file optionally pass __FILE__ calling the query for logging
175 167
      * @return mixed FALSE if no rows, if a single row it returns that, if multiple it returns an array of rows, associative responses only
176 168
      */
177
-    public function qr($query, $line = '', $file = '')
178
-    {
169
+    public function qr($query, $line = '', $file = '') {
179 170
         return $this->queryReturn($query, $line, $file);
180 171
     }
181 172
 
@@ -187,8 +178,7 @@  discard block
 block discarded – undo
187 178
      * @param string $line
188 179
      * @param string $file
189 180
      */
190
-    public function prepare($query, $line = '', $file = '')
191
-    {
181
+    public function prepare($query, $line = '', $file = '') {
192 182
         if (!$this->connect()) {
193 183
             return 0;
194 184
         }
@@ -213,8 +203,7 @@  discard block
 block discarded – undo
213 203
      * @param bool $log
214 204
      * @return mixed 0 if no query or query id handler, safe to ignore this return
215 205
      */
216
-    public function query($queryString, $line = '', $file = '', $log = false)
217
-    {
206
+    public function query($queryString, $line = '', $file = '', $log = false) {
218 207
         /* No empty queries, please, since PHP4 chokes on them. */
219 208
         /* The empty query string is passed on from the constructor,
220 209
         * when calling the class without a query, e.g. in situations
@@ -306,8 +295,7 @@  discard block
 block discarded – undo
306 295
     /**
307 296
      * @return array|null|object
308 297
      */
309
-    public function fetchObject()
310
-    {
298
+    public function fetchObject() {
311 299
         $this->Record = @mysqli_fetch_object($this->queryId);
312 300
         return $this->Record;
313 301
     }
@@ -320,8 +308,7 @@  discard block
 block discarded – undo
320 308
      * @param mixed $resultType
321 309
      * @return bool
322 310
      */
323
-    public function next_record($resultType = MYSQLI_BOTH)
324
-    {
311
+    public function next_record($resultType = MYSQLI_BOTH) {
325 312
         if ($this->queryId === false) {
326 313
             $this->haltmsg('next_record called with no query pending.');
327 314
             return 0;
@@ -345,8 +332,7 @@  discard block
 block discarded – undo
345 332
      * @param integer $pos the row numbe starting at 0 to switch to
346 333
      * @return bool whetherit was successfu or not.
347 334
      */
348
-    public function seek($pos = 0)
349
-    {
335
+    public function seek($pos = 0) {
350 336
         $status = @mysqli_data_seek($this->queryId, $pos);
351 337
         if ($status) {
352 338
             $this->Row = $pos;
@@ -366,8 +352,7 @@  discard block
 block discarded – undo
366 352
      *
367 353
      * @return bool
368 354
      */
369
-    public function transactionBegin()
370
-    {
355
+    public function transactionBegin() {
371 356
         if (version_compare(PHP_VERSION, '5.5.0') < 0) {
372 357
             return true;
373 358
         }
@@ -382,8 +367,7 @@  discard block
 block discarded – undo
382 367
      *
383 368
      * @return bool
384 369
      */
385
-    public function transactionCommit()
386
-    {
370
+    public function transactionCommit() {
387 371
         if (version_compare(PHP_VERSION, '5.5.0') < 0 || $this->linkId === 0) {
388 372
             return true;
389 373
         }
@@ -395,8 +379,7 @@  discard block
 block discarded – undo
395 379
      *
396 380
      * @return bool
397 381
      */
398
-    public function transactionAbort()
399
-    {
382
+    public function transactionAbort() {
400 383
         if (version_compare(PHP_VERSION, '5.5.0') < 0 || $this->linkId === 0) {
401 384
             return true;
402 385
         }
@@ -412,8 +395,7 @@  discard block
 block discarded – undo
412 395
      * @param string $field
413 396
      * @return int|string
414 397
      */
415
-    public function getLastInsertId($table, $field)
416
-    {
398
+    public function getLastInsertId($table, $field) {
417 399
         if (!isset($table) || $table == '' || !isset($field) || $field == '') {
418 400
             return -1;
419 401
         }
@@ -429,8 +411,7 @@  discard block
 block discarded – undo
429 411
      * @param string $mode
430 412
      * @return bool|int|\mysqli_result
431 413
      */
432
-    public function lock($table, $mode = 'write')
433
-    {
414
+    public function lock($table, $mode = 'write') {
434 415
         $this->connect();
435 416
         $query = 'lock tables ';
436 417
         if (is_array($table)) {
@@ -458,8 +439,7 @@  discard block
 block discarded – undo
458 439
      * @param bool $haltOnError optional, defaults to TRUE, whether or not to halt on error
459 440
      * @return bool|int|\mysqli_result
460 441
      */
461
-    public function unlock($haltOnError = true)
462
-    {
442
+    public function unlock($haltOnError = true) {
463 443
         $this->connect();
464 444
 
465 445
         $res = @mysqli_query($this->linkId, 'unlock tables');
@@ -476,8 +456,7 @@  discard block
 block discarded – undo
476 456
      * Db::affectedRows()
477 457
      * @return int
478 458
      */
479
-    public function affectedRows()
480
-    {
459
+    public function affectedRows() {
481 460
         return @mysqli_affected_rows($this->linkId);
482 461
     }
483 462
 
@@ -485,8 +464,7 @@  discard block
 block discarded – undo
485 464
      * Db::num_rows()
486 465
      * @return int
487 466
      */
488
-    public function num_rows()
489
-    {
467
+    public function num_rows() {
490 468
         return @mysqli_num_rows($this->queryId);
491 469
     }
492 470
 
@@ -494,8 +472,7 @@  discard block
 block discarded – undo
494 472
      * Db::num_fields()
495 473
      * @return int
496 474
      */
497
-    public function num_fields()
498
-    {
475
+    public function num_fields() {
499 476
         return @mysqli_num_fields($this->queryId);
500 477
     }
501 478
 
@@ -504,8 +481,7 @@  discard block
 block discarded – undo
504 481
      *
505 482
      * @return array
506 483
      */
507
-    public function tableNames()
508
-    {
484
+    public function tableNames() {
509 485
         $return = [];
510 486
         $this->query('SHOW TABLES');
511 487
         $i = 0;
Please login to merge, or discard this patch.
src/Generic.php 1 patch
Braces   +20 added lines, -40 removed lines patch added patch discarded remove patch
@@ -12,8 +12,7 @@  discard block
 block discarded – undo
12 12
 /**
13 13
  * Class Generic
14 14
  */
15
-abstract class Generic
16
-{
15
+abstract class Generic {
17 16
     /* public: connection parameters */
18 17
     public $host = 'localhost';
19 18
     public $database = '';
@@ -73,8 +72,7 @@  discard block
 block discarded – undo
73 72
      * @param string $query Optional query to perform immediately
74 73
      * @param string $port optional port for the connection
75 74
      */
76
-    public function __construct($database = '', $user = '', $password = '', $host = 'localhost', $query = '', $port = '')
77
-    {
75
+    public function __construct($database = '', $user = '', $password = '', $host = 'localhost', $query = '', $port = '') {
78 76
         $this->database = $database;
79 77
         $this->user = $user;
80 78
         $this->password = $password;
@@ -92,24 +90,21 @@  discard block
 block discarded – undo
92 90
      * @param string $file
93 91
      * @return void
94 92
      */
95
-    public function log($message, $line = '', $file = '', $level = 'info')
96
-    {
93
+    public function log($message, $line = '', $file = '', $level = 'info') {
97 94
         error_log('SQL Query '.$line.' '.$file.' '.$message);
98 95
     }
99 96
 
100 97
     /**
101 98
      * @return int|object
102 99
      */
103
-    public function linkId()
104
-    {
100
+    public function linkId() {
105 101
         return $this->linkId;
106 102
     }
107 103
 
108 104
     /**
109 105
      * @return int|object
110 106
      */
111
-    public function queryId()
112
-    {
107
+    public function queryId() {
113 108
         return $this->queryId;
114 109
     }
115 110
 
@@ -117,8 +112,7 @@  discard block
 block discarded – undo
117 112
      * @param $string
118 113
      * @return string
119 114
      */
120
-    public function real_escape($string = '')
121
-    {
115
+    public function real_escape($string = '') {
122 116
         if ((!is_resource($this->linkId) || $this->linkId == 0) && !$this->connect()) {
123 117
             return $this->escape($string);
124 118
         }
@@ -129,8 +123,7 @@  discard block
 block discarded – undo
129 123
      * @param $string
130 124
      * @return string
131 125
      */
132
-    public function escape($string = '')
133
-    {
126
+    public function escape($string = '') {
134 127
         //if (function_exists('mysql_escape_string'))
135 128
         //return mysql_escape_string($string);
136 129
         return str_replace(['\\', "\0", "\n", "\r", "'", '"', "\x1a"], ['\\\\', '\\0', '\\n', '\\r', "\\'", '\\"', '\\Z'], $string);
@@ -140,8 +133,7 @@  discard block
 block discarded – undo
140 133
      * @param mixed $str
141 134
      * @return string
142 135
      */
143
-    public function dbAddslashes($str = '')
144
-    {
136
+    public function dbAddslashes($str = '') {
145 137
         if (!isset($str) || $str == '') {
146 138
             return '';
147 139
         }
@@ -153,8 +145,7 @@  discard block
 block discarded – undo
153 145
      * @param mixed $epoch
154 146
      * @return bool|string
155 147
      */
156
-    public function toTimestamp($epoch)
157
-    {
148
+    public function toTimestamp($epoch) {
158 149
         return date('Y-m-d H:i:s', is_float($epoch) ? intval($epoch) : $epoch);
159 150
     }
160 151
 
@@ -163,8 +154,7 @@  discard block
 block discarded – undo
163 154
      * @param mixed $timestamp
164 155
      * @return bool|int|mixed
165 156
      */
166
-    public function fromTimestamp($timestamp)
167
-    {
157
+    public function fromTimestamp($timestamp) {
168 158
         if (preg_match('/([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})/', $timestamp, $parts)) {
169 159
             $time = mktime($parts[4], $parts[5], $parts[6], $parts[2], $parts[3], $parts[1]);
170 160
         } elseif (preg_match('/([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/', $timestamp, $parts)) {
@@ -190,8 +180,7 @@  discard block
 block discarded – undo
190 180
      * @param string $file
191 181
      * @return mixed
192 182
      */
193
-    public function limitQuery($queryString, $numRows = '', $offset = 0, $line = '', $file = '')
194
-    {
183
+    public function limitQuery($queryString, $numRows = '', $offset = 0, $line = '', $file = '') {
195 184
         if (!$numRows) {
196 185
             $numRows = $this->maxMatches;
197 186
         }
@@ -218,8 +207,7 @@  discard block
 block discarded – undo
218 207
      * @param string $file optionally pass __FILE__ calling the query for logging
219 208
      * @return mixed FALSE if no rows, if a single row it returns that, if multiple it returns an array of rows, associative responses only
220 209
      */
221
-    public function qr($query, $line = '', $file = '')
222
-    {
210
+    public function qr($query, $line = '', $file = '') {
223 211
         return $this->queryReturn($query, $line, $file);
224 212
     }
225 213
 
@@ -230,8 +218,7 @@  discard block
 block discarded – undo
230 218
      * @param string $stripSlashes
231 219
      * @return string
232 220
      */
233
-    public function f($name, $stripSlashes = '')
234
-    {
221
+    public function f($name, $stripSlashes = '') {
235 222
         if (is_null($this->Record)) {
236 223
             return null;
237 224
         } elseif ($stripSlashes || ($this->autoStripslashes && !$stripSlashes)) {
@@ -249,8 +236,7 @@  discard block
 block discarded – undo
249 236
      * @param string $file
250 237
      * @return void
251 238
      */
252
-    public function halt($msg, $line = '', $file = '')
253
-    {
239
+    public function halt($msg, $line = '', $file = '') {
254 240
         $this->unlock(false);
255 241
         /* Just in case there is a table currently locked */
256 242
 
@@ -277,8 +263,7 @@  discard block
 block discarded – undo
277 263
      * @param string $file
278 264
      * @return mixed|void
279 265
      */
280
-    public function logBackTrace($msg, $line = '', $file = '')
281
-    {
266
+    public function logBackTrace($msg, $line = '', $file = '') {
282 267
         $backtrace = (function_exists('debug_backtrace') ? debug_backtrace() : []);
283 268
         $this->log(
284 269
             ('' !== getenv('REQUEST_URI') ? ' '.getenv('REQUEST_URI') : '').
@@ -309,8 +294,7 @@  discard block
 block discarded – undo
309 294
         }
310 295
     }
311 296
 
312
-    public function emailError($queryString, $error, $line, $file)
313
-    {
297
+    public function emailError($queryString, $error, $line, $file) {
314 298
         $subject = php_uname('n').' MySQLi Error '.$queryString;
315 299
         if (class_exists('\\TFSmarty')) {
316 300
             $smarty = new \TFSmarty();
@@ -339,8 +323,7 @@  discard block
 block discarded – undo
339 323
      * @param string $file
340 324
      * @return mixed|void
341 325
      */
342
-    public function haltmsg($msg, $line = '', $file = '')
343
-    {
326
+    public function haltmsg($msg, $line = '', $file = '') {
344 327
         $email = "DB Error {$msg} {$file}:{$line}";
345 328
         if (class_exists('\\MyAdmin\Mail')) {
346 329
             \MyAdmin\Mail::failsafeMail($email, $email, ['[email protected]', '[email protected]']);
@@ -357,8 +340,7 @@  discard block
 block discarded – undo
357 340
     /**
358 341
      * @return array
359 342
      */
360
-    public function indexNames()
361
-    {
343
+    public function indexNames() {
362 344
         return [];
363 345
     }
364 346
 
@@ -370,8 +352,7 @@  discard block
 block discarded – undo
370 352
      * @param string|int $line Line Number
371 353
      * @param string $file File Name
372 354
      */
373
-    public function addLog($statement, $time, $line = '', $file = '')
374
-    {
355
+    public function addLog($statement, $time, $line = '', $file = '') {
375 356
         $query = [
376 357
             'statement' => $statement,
377 358
             'time' => $time * 1000
@@ -393,8 +374,7 @@  discard block
 block discarded – undo
393 374
      * Return logged queries.
394 375
      * @return array Logged queries
395 376
      */
396
-    public function getLog()
397
-    {
377
+    public function getLog() {
398 378
         return $this->log;
399 379
     }
400 380
 }
Please login to merge, or discard this patch.