Passed
Push — master ( af24c2...27a562 )
by kill
04:32
created
core/Model.php 2 patches
Doc Comments   +8 added lines, -9 removed lines patch added patch discarded remove patch
@@ -76,7 +76,6 @@  discard block
 block discarded – undo
76 76
     private $_with = Array();
77 77
 
78 78
     /**
79
-     * @param array $data Data to preload on object creation
80 79
      */
81 80
     public function __construct() {
82 81
         $this->db = app('db')->connect($this->dbConn);
@@ -207,7 +206,7 @@  discard block
 block discarded – undo
207 206
     /**
208 207
      * Save or Update object
209 208
      *
210
-     * @return mixed insert id or false in case of failure
209
+     * @return boolean insert id or false in case of failure
211 210
      */
212 211
     public function save($data = null) {
213 212
         if ($this->isNew)
@@ -216,7 +215,7 @@  discard block
 block discarded – undo
216 215
     }
217 216
 
218 217
     /**
219
-     * @return mixed insert id or false in case of failure
218
+     * @return boolean insert id or false in case of failure
220 219
      */
221 220
     public function insert() {
222 221
         if (!empty ($this->timestamps) && in_array("createdAt", $this->timestamps))
@@ -362,7 +361,7 @@  discard block
 block discarded – undo
362 361
     /**
363 362
      * Delete method. Works only if object primaryKey is defined
364 363
      *
365
-     * @return boolean Indicates success. 0 or 1.
364
+     * @return null|boolean Indicates success. 0 or 1.
366 365
      */
367 366
     public function delete() {
368 367
         if (empty ($this->data[$this->primaryKey]))
@@ -522,7 +521,7 @@  discard block
 block discarded – undo
522 521
      * @param string $joinType SQL join type: LEFT, RIGHT,  INNER, OUTER
523 522
      * @param string $primaryKey SQL join On Second primaryKey
524 523
      *
525
-     * @return dbObject
524
+     * @return Model
526 525
      */
527 526
     private function join($objectName, $key = null, $joinType = 'LEFT', $primaryKey = null) {
528 527
         $joinObj = new $objectName;
@@ -571,7 +570,7 @@  discard block
 block discarded – undo
571 570
     /**
572 571
      * Helper function to create dbObject with Json return type
573 572
      *
574
-     * @return dbObject
573
+     * @return Model
575 574
      */
576 575
     private function JsonBuilder() {
577 576
         $this->returnType = 'Json';
@@ -585,7 +584,7 @@  discard block
 block discarded – undo
585 584
     /**
586 585
      * Helper function to create dbObject with Array return type
587 586
      *
588
-     * @return dbObject
587
+     * @return Model
589 588
      */
590 589
     private function ArrayBuilder() {
591 590
         $this->returnType = 'Array';
@@ -596,7 +595,7 @@  discard block
 block discarded – undo
596 595
      * Helper function to create dbObject with Object return type.
597 596
      * Added for consistency. Works same way as new $objname ()
598 597
      *
599
-     * @return dbObject
598
+     * @return Model
600 599
      */
601 600
     private function ObjectBuilder() {
602 601
         $this->returnType = 'Object';
@@ -651,7 +650,7 @@  discard block
 block discarded – undo
651 650
      * @access public
652 651
      * @param string $objectName Object Name
653 652
      *
654
-     * @return dbObject
653
+     * @return null|Model
655 654
      */
656 655
     private function with($objectName) {
657 656
         if (!property_exists($this, 'relations') && !isset ($this->relations[$name]))
Please login to merge, or discard this patch.
Braces   +183 added lines, -125 removed lines patch added patch discarded remove patch
@@ -101,8 +101,9 @@  discard block
 block discarded – undo
101 101
      */
102 102
     public static function table($tableName) {
103 103
         $tableName = preg_replace("/[^-a-z0-9_]+/i", '', $tableName);
104
-        if (!class_exists($tableName))
105
-            eval ("class $tableName extends dbObject {}");
104
+        if (!class_exists($tableName)) {
105
+                    eval ("class $tableName extends dbObject {}");
106
+        }
106 107
         return new $tableName ();
107 108
     }
108 109
 
@@ -119,23 +120,26 @@  discard block
 block discarded – undo
119 120
     public static function __callStatic($method, $arg) {
120 121
         $obj = new static;
121 122
         $result = call_user_func_array(array($obj, $method), $arg);
122
-        if (method_exists($obj, $method))
123
-            return $result;
123
+        if (method_exists($obj, $method)) {
124
+                    return $result;
125
+        }
124 126
         return $obj;
125 127
     }
126 128
 
127 129
     public static function autoload($path = null) {
128
-        if ($path)
129
-            static::$modelPath = $path . "/";
130
-        else
131
-            static::$modelPath = __DIR__ . "/models/";
130
+        if ($path) {
131
+                    static::$modelPath = $path . "/";
132
+        } else {
133
+                    static::$modelPath = __DIR__ . "/models/";
134
+        }
132 135
         spl_autoload_register("dbObject::dbObjectAutoload");
133 136
     }
134 137
 
135 138
     private static function dbObjectAutoload($classname) {
136 139
         $filename = static::$modelPath . $classname . ".php";
137
-        if (file_exists($filename))
138
-            include($filename);
140
+        if (file_exists($filename)) {
141
+                    include($filename);
142
+        }
139 143
     }
140 144
 
141 145
     /**
@@ -146,11 +150,13 @@  discard block
 block discarded – undo
146 150
      * @return mixed
147 151
      */
148 152
     public function __get($name) {
149
-        if (property_exists($this, 'hidden') && array_search($name, $this->hidden) !== false)
150
-            return null;
153
+        if (property_exists($this, 'hidden') && array_search($name, $this->hidden) !== false) {
154
+                    return null;
155
+        }
151 156
 
152
-        if (isset ($this->data[$name]) && $this->data[$name] instanceof dbObject)
153
-            return $this->data[$name];
157
+        if (isset ($this->data[$name]) && $this->data[$name] instanceof dbObject) {
158
+                    return $this->data[$name];
159
+        }
154 160
 
155 161
         if (property_exists($this, 'relations') && isset ($this->relations[$name])) {
156 162
             $relationType = strtolower($this->relations[$name][0]);
@@ -173,11 +179,13 @@  discard block
 block discarded – undo
173 179
             }
174 180
         }
175 181
 
176
-        if (isset ($this->data[$name]))
177
-            return $this->data[$name];
182
+        if (isset ($this->data[$name])) {
183
+                    return $this->data[$name];
184
+        }
178 185
 
179
-        if (property_exists($this->db, $name))
180
-            return $this->db->$name;
186
+        if (property_exists($this->db, $name)) {
187
+                    return $this->db->$name;
188
+        }
181 189
     }
182 190
 
183 191
     /**
@@ -186,18 +194,21 @@  discard block
 block discarded – undo
186 194
      * @return mixed
187 195
      */
188 196
     public function __set($name, $value) {
189
-        if (property_exists($this, 'hidden') && array_search($name, $this->hidden) !== false)
190
-            return;
197
+        if (property_exists($this, 'hidden') && array_search($name, $this->hidden) !== false) {
198
+                    return;
199
+        }
191 200
 
192 201
         $this->data[$name] = $value;
193 202
     }
194 203
 
195 204
     public function __isset($name) {
196
-        if (isset ($this->data[$name]))
197
-            return isset ($this->data[$name]);
205
+        if (isset ($this->data[$name])) {
206
+                    return isset ($this->data[$name]);
207
+        }
198 208
 
199
-        if (property_exists($this->db, $name))
200
-            return isset ($this->db->$name);
209
+        if (property_exists($this->db, $name)) {
210
+                    return isset ($this->db->$name);
211
+        }
201 212
     }
202 213
 
203 214
     public function __unset($name) {
@@ -210,8 +221,9 @@  discard block
 block discarded – undo
210 221
      * @return mixed insert id or false in case of failure
211 222
      */
212 223
     public function save($data = null) {
213
-        if ($this->isNew)
214
-            return $this->insert();
224
+        if ($this->isNew) {
225
+                    return $this->insert();
226
+        }
215 227
         return $this->update($data);
216 228
     }
217 229
 
@@ -219,15 +231,18 @@  discard block
 block discarded – undo
219 231
      * @return mixed insert id or false in case of failure
220 232
      */
221 233
     public function insert() {
222
-        if (!empty ($this->timestamps) && in_array("createdAt", $this->timestamps))
223
-            $this->createdAt = date("Y-m-d H:i:s");
234
+        if (!empty ($this->timestamps) && in_array("createdAt", $this->timestamps)) {
235
+                    $this->createdAt = date("Y-m-d H:i:s");
236
+        }
224 237
         $sqlData = $this->prepareData();
225
-        if (!$this->validate($sqlData))
226
-            return false;
238
+        if (!$this->validate($sqlData)) {
239
+                    return false;
240
+        }
227 241
 
228 242
         $id = $this->db->insert($this->dbTable, $sqlData);
229
-        if (!empty ($this->primaryKey) && empty ($this->data[$this->primaryKey]))
230
-            $this->data[$this->primaryKey] = $id;
243
+        if (!empty ($this->primaryKey) && empty ($this->data[$this->primaryKey])) {
244
+                    $this->data[$this->primaryKey] = $id;
245
+        }
231 246
         $this->isNew = false;
232 247
 
233 248
         return $id;
@@ -236,38 +251,44 @@  discard block
 block discarded – undo
236 251
     private function prepareData() {
237 252
         $this->errors = Array();
238 253
         $sqlData = Array();
239
-        if (count($this->data) == 0)
240
-            return Array();
254
+        if (count($this->data) == 0) {
255
+                    return Array();
256
+        }
241 257
 
242
-        if (method_exists($this, "preLoad"))
243
-            $this->preLoad($this->data);
258
+        if (method_exists($this, "preLoad")) {
259
+                    $this->preLoad($this->data);
260
+        }
244 261
 
245
-        if (!$this->dbFields)
246
-            return $this->data;
262
+        if (!$this->dbFields) {
263
+                    return $this->data;
264
+        }
247 265
 
248 266
         foreach ($this->data as $key => &$value) {
249 267
             if ($value instanceof dbObject && $value->isNew == true) {
250 268
                 $id = $value->save();
251
-                if ($id)
252
-                    $value = $id;
253
-                else
254
-                    $this->errors = array_merge($this->errors, $value->errors);
269
+                if ($id) {
270
+                                    $value = $id;
271
+                } else {
272
+                                    $this->errors = array_merge($this->errors, $value->errors);
273
+                }
255 274
             }
256 275
 
257
-            if (!in_array($key, array_keys($this->dbFields)))
258
-                continue;
276
+            if (!in_array($key, array_keys($this->dbFields))) {
277
+                            continue;
278
+            }
259 279
 
260 280
             if (!is_array($value)) {
261 281
                 $sqlData[$key] = $value;
262 282
                 continue;
263 283
             }
264 284
 
265
-            if (isset ($this->jsonFields) && in_array($key, $this->jsonFields))
266
-                $sqlData[$key] = json_encode($value);
267
-            else if (isset ($this->arrayFields) && in_array($key, $this->arrayFields))
268
-                $sqlData[$key] = implode("|", $value);
269
-            else
270
-                $sqlData[$key] = $value;
285
+            if (isset ($this->jsonFields) && in_array($key, $this->jsonFields)) {
286
+                            $sqlData[$key] = json_encode($value);
287
+            } else if (isset ($this->arrayFields) && in_array($key, $this->arrayFields)) {
288
+                            $sqlData[$key] = implode("|", $value);
289
+            } else {
290
+                            $sqlData[$key] = $value;
291
+            }
271 292
         }
272 293
         return $sqlData;
273 294
     }
@@ -276,31 +297,37 @@  discard block
 block discarded – undo
276 297
      * @param array $data
277 298
      */
278 299
     private function validate($data) {
279
-        if (!$this->dbFields)
280
-            return true;
300
+        if (!$this->dbFields) {
301
+                    return true;
302
+        }
281 303
 
282 304
         foreach ($this->dbFields as $key => $desc) {
283 305
             $type = null;
284 306
             $required = false;
285
-            if (isset ($data[$key]))
286
-                $value = $data[$key];
287
-            else
288
-                $value = null;
307
+            if (isset ($data[$key])) {
308
+                            $value = $data[$key];
309
+            } else {
310
+                            $value = null;
311
+            }
289 312
 
290
-            if (is_array($value))
291
-                continue;
313
+            if (is_array($value)) {
314
+                            continue;
315
+            }
292 316
 
293
-            if (isset ($desc[0]))
294
-                $type = $desc[0];
295
-            if (isset ($desc[1]) && ($desc[1] == 'required'))
296
-                $required = true;
317
+            if (isset ($desc[0])) {
318
+                            $type = $desc[0];
319
+            }
320
+            if (isset ($desc[1]) && ($desc[1] == 'required')) {
321
+                            $required = true;
322
+            }
297 323
 
298 324
             if ($required && strlen($value) == 0) {
299 325
                 $this->errors[] = Array($this->dbTable . "." . $key => "is required");
300 326
                 continue;
301 327
             }
302
-            if ($value == null)
303
-                continue;
328
+            if ($value == null) {
329
+                            continue;
330
+            }
304 331
 
305 332
             switch ($type) {
306 333
                 case "text";
@@ -322,8 +349,9 @@  discard block
 block discarded – undo
322 349
                     $regexp = $type;
323 350
                     break;
324 351
             }
325
-            if (!$regexp)
326
-                continue;
352
+            if (!$regexp) {
353
+                            continue;
354
+            }
327 355
 
328 356
             if (!preg_match($regexp, $value)) {
329 357
                 $this->errors[] = Array($this->dbTable . "." . $key => "$type validation failed");
@@ -337,23 +365,28 @@  discard block
 block discarded – undo
337 365
      * @param array $data Optional update data to apply to the object
338 366
      */
339 367
     public function update($data = null) {
340
-        if (empty ($this->dbFields))
341
-            return false;
368
+        if (empty ($this->dbFields)) {
369
+                    return false;
370
+        }
342 371
 
343
-        if (empty ($this->data[$this->primaryKey]))
344
-            return false;
372
+        if (empty ($this->data[$this->primaryKey])) {
373
+                    return false;
374
+        }
345 375
 
346 376
         if ($data) {
347
-            foreach ($data as $k => $v)
348
-                $this->$k = $v;
377
+            foreach ($data as $k => $v) {
378
+                            $this->$k = $v;
379
+            }
349 380
         }
350 381
 
351
-        if (!empty ($this->timestamps) && in_array("updatedAt", $this->timestamps))
352
-            $this->updatedAt = date("Y-m-d H:i:s");
382
+        if (!empty ($this->timestamps) && in_array("updatedAt", $this->timestamps)) {
383
+                    $this->updatedAt = date("Y-m-d H:i:s");
384
+        }
353 385
 
354 386
         $sqlData = $this->prepareData();
355
-        if (!$this->validate($sqlData))
356
-            return false;
387
+        if (!$this->validate($sqlData)) {
388
+                    return false;
389
+        }
357 390
 
358 391
         $this->db->where($this->primaryKey, $this->data[$this->primaryKey]);
359 392
         return $this->db->update($this->dbTable, $sqlData);
@@ -365,8 +398,9 @@  discard block
 block discarded – undo
365 398
      * @return boolean Indicates success. 0 or 1.
366 399
      */
367 400
     public function delete() {
368
-        if (empty ($this->data[$this->primaryKey]))
369
-            return false;
401
+        if (empty ($this->data[$this->primaryKey])) {
402
+                    return false;
403
+        }
370 404
 
371 405
         $this->db->where($this->primaryKey, $this->data[$this->primaryKey]);
372 406
         return $this->db->delete($this->dbTable);
@@ -381,8 +415,9 @@  discard block
 block discarded – undo
381 415
      * @return mixed
382 416
      */
383 417
     public function __call($method, $arg) {
384
-        if (method_exists($this, $method))
385
-            return call_user_func_array(array($this, $method), $arg);
418
+        if (method_exists($this, $method)) {
419
+                    return call_user_func_array(array($this, $method), $arg);
420
+        }
386 421
         return call_user_func_array(array($this->db, $method), $arg);;
387 422
     }
388 423
 
@@ -413,8 +448,9 @@  discard block
 block discarded – undo
413 448
         $data = $this->data;
414 449
         $this->processAllWith($data);
415 450
         foreach ($data as &$d) {
416
-            if ($d instanceof dbObject)
417
-                $d = $d->data;
451
+            if ($d instanceof dbObject) {
452
+                            $d = $d->data;
453
+            }
418 454
         }
419 455
         return $data;
420 456
     }
@@ -425,8 +461,9 @@  discard block
 block discarded – undo
425 461
      * @param array $data
426 462
      */
427 463
     private function processAllWith(&$data, $shouldReset = true) {
428
-        if (count($this->_with) == 0)
429
-            return;
464
+        if (count($this->_with) == 0) {
465
+                    return;
466
+        }
430 467
 
431 468
         foreach ($this->_with as $name => $opts) {
432 469
             $relationType = strtolower($opts[0]);
@@ -453,11 +490,13 @@  discard block
 block discarded – undo
453 490
                     }
454 491
                 }
455 492
                 unset ($data[$table]);
456
-            } else
457
-                $data[$name] = $this->$name;
493
+            } else {
494
+                            $data[$name] = $this->$name;
495
+            }
496
+        }
497
+        if ($shouldReset) {
498
+                    $this->_with = Array();
458 499
         }
459
-        if ($shouldReset)
460
-            $this->_with = Array();
461 500
     }
462 501
 
463 502
     /**
@@ -474,8 +513,9 @@  discard block
 block discarded – undo
474 513
         $objects = Array();
475 514
         $this->processHasOneWith();
476 515
         $results = $this->db->ArrayBuilder()->get($this->dbTable, $limit, $fields);
477
-        if ($this->db->count == 0)
478
-            return null;
516
+        if ($this->db->count == 0) {
517
+                    return null;
518
+        }
479 519
 
480 520
         foreach ($results as &$r) {
481 521
             $this->processArrays($r);
@@ -488,24 +528,28 @@  discard block
 block discarded – undo
488 528
             }
489 529
         }
490 530
         $this->_with = Array();
491
-        if ($this->returnType == 'Object')
492
-            return $objects;
531
+        if ($this->returnType == 'Object') {
532
+                    return $objects;
533
+        }
493 534
 
494
-        if ($this->returnType == 'Json')
495
-            return json_encode($results);
535
+        if ($this->returnType == 'Json') {
536
+                    return json_encode($results);
537
+        }
496 538
 
497 539
         return $results;
498 540
     }
499 541
 
500 542
     private function processHasOneWith() {
501
-        if (count($this->_with) == 0)
502
-            return;
543
+        if (count($this->_with) == 0) {
544
+                    return;
545
+        }
503 546
         foreach ($this->_with as $name => $opts) {
504 547
             $relationType = strtolower($opts[0]);
505 548
             $modelName = $opts[1];
506 549
             $key = null;
507
-            if (isset ($opts[2]))
508
-                $key = $opts[2];
550
+            if (isset ($opts[2])) {
551
+                            $key = $opts[2];
552
+            }
509 553
             if ($relationType == 'hasone') {
510 554
                 $this->db->setQueryOption("MYSQLI_NESTJOIN");
511 555
                 $this->join($modelName, $key);
@@ -526,16 +570,19 @@  discard block
 block discarded – undo
526 570
      */
527 571
     private function join($objectName, $key = null, $joinType = 'LEFT', $primaryKey = null) {
528 572
         $joinObj = new $objectName;
529
-        if (!$key)
530
-            $key = $objectName . "id";
573
+        if (!$key) {
574
+                    $key = $objectName . "id";
575
+        }
531 576
 
532
-        if (!$primaryKey)
533
-            $primaryKey = $this->db->getPrefix() . $joinObj->dbTable . "." . $joinObj->primaryKey;
577
+        if (!$primaryKey) {
578
+                    $primaryKey = $this->db->getPrefix() . $joinObj->dbTable . "." . $joinObj->primaryKey;
579
+        }
534 580
 
535
-        if (!strchr($key, '.'))
536
-            $joinStr = $this->db->getPrefix() . $this->dbTable . ".{$key} = " . $primaryKey;
537
-        else
538
-            $joinStr = $this->db->getPrefix() . "{$key} = " . $primaryKey;
581
+        if (!strchr($key, '.')) {
582
+                    $joinStr = $this->db->getPrefix() . $this->dbTable . ".{$key} = " . $primaryKey;
583
+        } else {
584
+                    $joinStr = $this->db->getPrefix() . "{$key} = " . $primaryKey;
585
+        }
539 586
 
540 587
         $this->db->join($joinObj->dbTable, $joinStr, $joinType);
541 588
         return $this;
@@ -546,13 +593,15 @@  discard block
 block discarded – undo
546 593
      */
547 594
     private function processArrays(&$data) {
548 595
         if (isset ($this->jsonFields) && is_array($this->jsonFields)) {
549
-            foreach ($this->jsonFields as $key)
550
-                $data[$key] = json_decode($data[$key]);
596
+            foreach ($this->jsonFields as $key) {
597
+                            $data[$key] = json_decode($data[$key]);
598
+            }
551 599
         }
552 600
 
553 601
         if (isset ($this->arrayFields) && is_array($this->arrayFields)) {
554
-            foreach ($this->arrayFields as $key)
555
-                $data[$key] = explode("|", $data[$key]);
602
+            foreach ($this->arrayFields as $key) {
603
+                            $data[$key] = explode("|", $data[$key]);
604
+            }
556 605
         }
557 606
     }
558 607
 
@@ -563,8 +612,9 @@  discard block
 block discarded – undo
563 612
      */
564 613
     protected function count() {
565 614
         $res = $this->db->ArrayBuilder()->getValue($this->dbTable, "count(*)");
566
-        if (!$res)
567
-            return 0;
615
+        if (!$res) {
616
+                    return 0;
617
+        }
568 618
         return $res;
569 619
     }
570 620
 
@@ -628,16 +678,19 @@  discard block
 block discarded – undo
628 678
     protected function getOne($fields = null) {
629 679
         $this->processHasOneWith();
630 680
         $results = $this->db->ArrayBuilder()->getOne($this->dbTable, $fields);
631
-        if ($this->db->count == 0)
632
-            return null;
681
+        if ($this->db->count == 0) {
682
+                    return null;
683
+        }
633 684
 
634 685
         $this->processArrays($results);
635 686
         $this->data = $results;
636 687
         $this->processAllWith($results);
637
-        if ($this->returnType == 'Json')
638
-            return json_encode($results);
639
-        if ($this->returnType == 'Array')
640
-            return $results;
688
+        if ($this->returnType == 'Json') {
689
+                    return json_encode($results);
690
+        }
691
+        if ($this->returnType == 'Array') {
692
+                    return $results;
693
+        }
641 694
 
642 695
         $item = new static ($results);
643 696
         $item->isNew = false;
@@ -654,8 +707,9 @@  discard block
 block discarded – undo
654 707
      * @return dbObject
655 708
      */
656 709
     private function with($objectName) {
657
-        if (!property_exists($this, 'relations') && !isset ($this->relations[$name]))
658
-            die ("No relation with name $objectName found");
710
+        if (!property_exists($this, 'relations') && !isset ($this->relations[$name])) {
711
+                    die ("No relation with name $objectName found");
712
+        }
659 713
 
660 714
         $this->_with[$objectName] = $this->relations[$objectName];
661 715
 
@@ -682,7 +736,9 @@  discard block
 block discarded – undo
682 736
         $this->db->pageLimit = self::$pageLimit;
683 737
         $res = $this->db->paginate($this->dbTable, $page, $fields);
684 738
         self::$totalPages = $this->db->totalPages;
685
-        if ($this->db->count == 0) return null;
739
+        if ($this->db->count == 0) {
740
+            return null;
741
+        }
686 742
 
687 743
         foreach ($res as &$r) {
688 744
             $this->processArrays($r);
@@ -695,11 +751,13 @@  discard block
 block discarded – undo
695 751
             }
696 752
         }
697 753
         $this->_with = Array();
698
-        if ($this->returnType == 'Object')
699
-            return $objects;
754
+        if ($this->returnType == 'Object') {
755
+                    return $objects;
756
+        }
700 757
 
701
-        if ($this->returnType == 'Json')
702
-            return json_encode($res);
758
+        if ($this->returnType == 'Json') {
759
+                    return json_encode($res);
760
+        }
703 761
 
704 762
         return $res;
705 763
     }
Please login to merge, or discard this patch.
core/Mysql.php 2 patches
Doc Comments   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
      *
256 256
      * @param string $subQueryAlias
257 257
      *
258
-     * @return MysqliDb
258
+     * @return Mysql
259 259
      */
260 260
     public static function subQuery($subQueryAlias = "") {
261 261
         return new self(array('host' => $subQueryAlias, 'isSubQuery' => true));
@@ -277,7 +277,7 @@  discard block
 block discarded – undo
277 277
     /**
278 278
      * Helper function to create dbObject with JSON return type
279 279
      *
280
-     * @return MysqliDb
280
+     * @return Mysql
281 281
      */
282 282
     public function jsonBuilder() {
283 283
         $this->returnType = 'json';
@@ -287,7 +287,7 @@  discard block
 block discarded – undo
287 287
     /**
288 288
      * Helper function to create dbObject with object return type.
289 289
      *
290
-     * @return MysqliDb
290
+     * @return Mysql
291 291
      */
292 292
     public function objectBuilder() {
293 293
         $this->returnType = 'object';
@@ -350,7 +350,7 @@  discard block
 block discarded – undo
350 350
      * Method attempts to prepare the SQL query
351 351
      * and throws an error if there was a problem.
352 352
      *
353
-     * @return mysqli_stmt
353
+     * @return \mysqli_stmt
354 354
      */
355 355
     protected function _prepareQuery() {
356 356
         if (!$stmt = $this->mysqli()->prepare($this->_query)) {
@@ -539,7 +539,7 @@  discard block
 block discarded – undo
539 539
      * This helper method takes care of prepared statements' "bind_result method
540 540
      * , when the number of variables to pass is unknown.
541 541
      *
542
-     * @param mysqli_stmt $stmt Equal to the prepared statement object.
542
+     * @param \mysqli_stmt $stmt Equal to the prepared statement object.
543 543
      *
544 544
      * @return array The results of the SQL fetch.
545 545
      */
@@ -702,7 +702,7 @@  discard block
 block discarded – undo
702 702
      *                               or only $count
703 703
      * @param array $tableData Should contain an array of data for updating the database.
704 704
      *
705
-     * @return mysqli_stmt Returns the $stmt object.
705
+     * @return null|\mysqli_stmt Returns the $stmt object.
706 706
      */
707 707
     protected function _buildQuery($numRows = null, $tableData = null) {
708 708
         // $this->_buildJoinOld();
@@ -1211,7 +1211,7 @@  discard block
 block discarded – undo
1211 1211
      *
1212 1212
      * @param string $tableName The name of the database table to work with.
1213 1213
      *
1214
-     * @return array Contains the returned rows from the select query.
1214
+     * @return boolean Contains the returned rows from the select query.
1215 1215
      */
1216 1216
     public function has($tableName) {
1217 1217
         $this->getOne($tableName, '1');
@@ -1311,7 +1311,7 @@  discard block
 block discarded – undo
1311 1311
      * @param int|array $numRows Array to define SQL limit in format Array ($count, $offset)
1312 1312
      *                               or only $count
1313 1313
      *
1314
-     * @return bool Indicates success. 0 or 1.
1314
+     * @return null|boolean Indicates success. 0 or 1.
1315 1315
      */
1316 1316
     public function delete($numRows = null) {
1317 1317
         if ($this->isSubQuery) {
@@ -1342,7 +1342,7 @@  discard block
 block discarded – undo
1342 1342
      * @param array $updateColumns Variable with values
1343 1343
      * @param string $lastInsertId Variable value
1344 1344
      *
1345
-     * @return MysqliDb
1345
+     * @return Mysql
1346 1346
      */
1347 1347
     public function onDuplicate($updateColumns, $lastInsertId = null) {
1348 1348
         $this->_lastInsertId = $lastInsertId;
@@ -1359,7 +1359,7 @@  discard block
 block discarded – undo
1359 1359
      * @param mixed $whereValue The value of the database field.
1360 1360
      * @param string $operator Comparison operator. Default is =
1361 1361
      *
1362
-     * @return MysqliDb
1362
+     * @return Mysql
1363 1363
      */
1364 1364
     public function orWhere($whereProp, $whereValue = 'DBNULL', $operator = '=') {
1365 1365
         return $this->where($whereProp, $whereValue, $operator, 'OR');
@@ -1375,7 +1375,7 @@  discard block
 block discarded – undo
1375 1375
      * @param string $operator Comparison operator. Default is =
1376 1376
      * @param string $cond Condition of where statement (OR, AND)
1377 1377
      *
1378
-     * @return MysqliDb
1378
+     * @return Mysql
1379 1379
      */
1380 1380
     public function where($whereProp, $whereValue = 'DBNULL', $operator = '=', $cond = 'AND') {
1381 1381
         // forkaround for an old operation api
@@ -1401,7 +1401,7 @@  discard block
 block discarded – undo
1401 1401
      * @param mixed $havingValue The value of the database field.
1402 1402
      * @param string $operator Comparison operator. Default is =
1403 1403
      *
1404
-     * @return MysqliDb
1404
+     * @return Mysql
1405 1405
      */
1406 1406
     public function orHaving($havingProp, $havingValue = null, $operator = null) {
1407 1407
         return $this->having($havingProp, $havingValue, $operator, 'OR');
@@ -1416,7 +1416,7 @@  discard block
 block discarded – undo
1416 1416
      * @param mixed $havingValue The value of the database field.
1417 1417
      * @param string $operator Comparison operator. Default is =
1418 1418
      *
1419
-     * @return MysqliDb
1419
+     * @return Mysql
1420 1420
      */
1421 1421
 
1422 1422
     public function having($havingProp, $havingValue = 'DBNULL', $operator = '=', $cond = 'AND') {
@@ -1444,7 +1444,7 @@  discard block
 block discarded – undo
1444 1444
      * @param string $joinType 'LEFT', 'INNER' etc.
1445 1445
      *
1446 1446
      * @throws Exception
1447
-     * @return MysqliDb
1447
+     * @return Mysql
1448 1448
      */
1449 1449
     public function join($joinTable, $joinCondition, $joinType = '') {
1450 1450
         $allowedTypes = array('LEFT', 'RIGHT', 'OUTER', 'INNER', 'LEFT OUTER', 'RIGHT OUTER');
@@ -1529,7 +1529,7 @@  discard block
 block discarded – undo
1529 1529
      * This method does not escape strings by default so make sure you'll never use it in production.
1530 1530
      *
1531 1531
      * @author Jonas Barascu
1532
-     * @param [[Type]] $query [[Description]]
1532
+     * @param string $query [[Description]]
1533 1533
      */
1534 1534
     private function queryUnprepared($query) {
1535 1535
         // Execute query
@@ -1603,11 +1603,11 @@  discard block
 block discarded – undo
1603 1603
      * @uses $MySqliDb->orderBy('id', 'desc')->orderBy('name', 'desc');
1604 1604
      *
1605 1605
      * @param string $orderByField The name of the database field.
1606
-     * @param string $orderByDirection Order direction.
1606
+     * @param string $orderbyDirection Order direction.
1607 1607
      * @param array $customFields Fieldset for ORDER BY FIELD() ordering
1608 1608
      *
1609 1609
      * @throws Exception
1610
-     * @return MysqliDb
1610
+     * @return Mysql
1611 1611
      */
1612 1612
     public function orderBy($orderByField, $orderbyDirection = "DESC", $customFields = null) {
1613 1613
         $allowedDirection = Array("ASC", "DESC");
@@ -1643,7 +1643,7 @@  discard block
 block discarded – undo
1643 1643
      *
1644 1644
      * @param string $groupByField The name of the database field.
1645 1645
      *
1646
-     * @return MysqliDb
1646
+     * @return Mysql
1647 1647
      */
1648 1648
     public function groupBy($groupByField) {
1649 1649
         $groupByField = preg_replace("/[^-a-z0-9\.\(\),_\*]+/i", '', $groupByField);
@@ -1659,7 +1659,7 @@  discard block
 block discarded – undo
1659 1659
      * @param  string $method The table lock method. Can be READ or WRITE.
1660 1660
      *
1661 1661
      * @throws Exception
1662
-     * @return MysqliDb
1662
+     * @return Mysql
1663 1663
      */
1664 1664
     public function setLockMethod($method) {
1665 1665
         // Switch the uppercase string
@@ -1806,7 +1806,7 @@  discard block
 block discarded – undo
1806 1806
      *
1807 1807
      * @param string $prefix Contains a tableprefix
1808 1808
      *
1809
-     * @return MysqliDb
1809
+     * @return Mysql
1810 1810
      */
1811 1811
     public function setPrefix($prefix = '') {
1812 1812
         $this->prefix = $prefix;
@@ -2016,7 +2016,7 @@  discard block
 block discarded – undo
2016 2016
      * @param bool $enabled Enable execution time tracking
2017 2017
      * @param string $stripPrefix Prefix to strip from the path in exec log
2018 2018
      *
2019
-     * @return MysqliDb
2019
+     * @return Mysql
2020 2020
      */
2021 2021
     public function setTrace($enabled, $stripPrefix = null) {
2022 2022
         $this->traceEnabled = $enabled;
@@ -2053,7 +2053,7 @@  discard block
 block discarded – undo
2053 2053
      *
2054 2054
      * @param string $idField field name to use for a mapped element key
2055 2055
      *
2056
-     * @return MysqliDb
2056
+     * @return Mysql
2057 2057
      */
2058 2058
     public function map($idField) {
2059 2059
         $this->_mapKey = $idField;
@@ -2069,7 +2069,7 @@  discard block
 block discarded – undo
2069 2069
      * @param string $whereProp The name of the database field.
2070 2070
      * @param mixed $whereValue The value of the database field.
2071 2071
      *
2072
-     * @return dbWrapper
2072
+     * @return Mysql
2073 2073
      */
2074 2074
     public function joinOrWhere($whereJoin, $whereProp, $whereValue = 'DBNULL', $operator = '=', $cond = 'AND') {
2075 2075
         return $this->joinWhere($whereJoin, $whereProp, $whereValue, $operator, 'OR');
@@ -2084,7 +2084,7 @@  discard block
 block discarded – undo
2084 2084
      * @param string $whereProp The name of the database field.
2085 2085
      * @param mixed $whereValue The value of the database field.
2086 2086
      *
2087
-     * @return dbWrapper
2087
+     * @return Mysql
2088 2088
      */
2089 2089
     public function joinWhere($whereJoin, $whereProp, $whereValue = 'DBNULL', $operator = '=', $cond = 'AND') {
2090 2090
         $this->_joinAnd[$whereJoin][] = Array($cond, $whereProp, $operator, $whereValue);
@@ -2160,7 +2160,7 @@  discard block
 block discarded – undo
2160 2160
      * Helper function to create dbObject with array return type
2161 2161
      * Added for consistency as thats default output type
2162 2162
      *
2163
-     * @return MysqliDb
2163
+     * @return Mysql
2164 2164
      */
2165 2165
     public function arrayBuilder() {
2166 2166
         $this->returnType = 'array';
@@ -2241,7 +2241,7 @@  discard block
 block discarded – undo
2241 2241
     /**
2242 2242
      * Function to enable SQL_CALC_FOUND_ROWS in the get queries
2243 2243
      *
2244
-     * @return MysqliDb
2244
+     * @return Mysql
2245 2245
      */
2246 2246
     public function withTotalCount() {
2247 2247
         $this->setQueryOption('SQL_CALC_FOUND_ROWS');
@@ -2253,10 +2253,10 @@  discard block
 block discarded – undo
2253 2253
      *
2254 2254
      * @uses $MySqliDb->setQueryOption('name');
2255 2255
      *
2256
-     * @param string|array $options The optons name of the query.
2256
+     * @param string $options The optons name of the query.
2257 2257
      *
2258 2258
      * @throws Exception
2259
-     * @return MysqliDb
2259
+     * @return Mysql
2260 2260
      */
2261 2261
     public function setQueryOption($options) {
2262 2262
         $allowedOptions = Array('ALL', 'DISTINCT', 'DISTINCTROW', 'HIGH_PRIORITY', 'STRAIGHT_JOIN', 'SQL_SMALL_RESULT',
Please login to merge, or discard this patch.
Braces   +27 added lines, -20 removed lines patch added patch discarded remove patch
@@ -268,8 +268,9 @@  discard block
 block discarded – undo
268 268
      * @return void
269 269
      */
270 270
     public function disconnect() {
271
-        if (!$this->_mysqli)
272
-            return;
271
+        if (!$this->_mysqli) {
272
+                    return;
273
+        }
273 274
         $this->_mysqli->close();
274 275
         $this->_mysqli = null;
275 276
     }
@@ -556,8 +557,9 @@  discard block
 block discarded – undo
556 557
 
557 558
         // if $meta is false yet sqlstate is true, there's no sql error but the query is
558 559
         // most likely an update/insert/delete which doesn't produce any results
559
-        if (!$meta && $stmt->sqlstate)
560
-            return array();
560
+        if (!$meta && $stmt->sqlstate) {
561
+                    return array();
562
+        }
561 563
 
562 564
         $row = array();
563 565
         while ($field = $meta->fetch_field()) {
@@ -743,16 +745,18 @@  discard block
 block discarded – undo
743 745
      * Abstraction method that will build an JOIN part of the query
744 746
      */
745 747
     protected function _buildJoin() {
746
-        if (empty ($this->_join))
747
-            return;
748
+        if (empty ($this->_join)) {
749
+                    return;
750
+        }
748 751
 
749 752
         foreach ($this->_join as $data) {
750 753
             list ($joinType, $joinTable, $joinCondition) = $data;
751 754
 
752
-            if (is_object($joinTable))
753
-                $joinStr = $this->_buildPair("", $joinTable);
754
-            else
755
-                $joinStr = $joinTable;
755
+            if (is_object($joinTable)) {
756
+                            $joinStr = $this->_buildPair("", $joinTable);
757
+            } else {
758
+                            $joinStr = $joinTable;
759
+            }
756 760
 
757 761
             $this->_query .= " " . $joinType . " JOIN " . $joinStr . " on " . $joinCondition;
758 762
 
@@ -840,12 +844,13 @@  discard block
 block discarded – undo
840 844
                 $this->_query .= $operator . $this->_buildPair("", $val);
841 845
                 break;
842 846
             default:
843
-                if (is_array($val))
844
-                    $this->_bindParams($val);
845
-                else if ($val === null)
846
-                    $this->_query .= $operator . " NULL";
847
-                else if ($val != 'DBNULL' || $val == '0')
848
-                    $this->_query .= $this->_buildPair($operator, $val);
847
+                if (is_array($val)) {
848
+                                    $this->_bindParams($val);
849
+                } else if ($val === null) {
850
+                                    $this->_query .= $operator . " NULL";
851
+                } else if ($val != 'DBNULL' || $val == '0') {
852
+                                    $this->_query .= $this->_buildPair($operator, $val);
853
+                }
849 854
         }
850 855
     }
851 856
 
@@ -862,8 +867,9 @@  discard block
 block discarded – undo
862 867
         $isInsert = preg_match('/^[INSERT|REPLACE]/', $this->_query);
863 868
         $dataColumns = array_keys($tableData);
864 869
         if ($isInsert) {
865
-            if (isset ($dataColumns[0]))
866
-                $this->_query .= ' (`' . implode($dataColumns, '`, `') . '`) ';
870
+            if (isset ($dataColumns[0])) {
871
+                            $this->_query .= ' (`' . implode($dataColumns, '`, `') . '`) ';
872
+            }
867 873
             $this->_query .= ' VALUES (';
868 874
         } else {
869 875
             $this->_query .= " SET ";
@@ -2038,8 +2044,9 @@  discard block
 block discarded – undo
2038 2044
             return false;
2039 2045
         }
2040 2046
 
2041
-        foreach ($tables as $i => $value)
2042
-            $tables[$i] = $this->prefix . $value;
2047
+        foreach ($tables as $i => $value) {
2048
+                    $tables[$i] = $this->prefix . $value;
2049
+        }
2043 2050
         $this->where('table_schema', $this->db);
2044 2051
         $this->where('table_name', $tables, 'in');
2045 2052
         $this->get('information_schema.tables', $count);
Please login to merge, or discard this patch.
core/App.php 1 patch
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -34,8 +34,7 @@
 block discarded – undo
34 34
         try{
35 35
             $dotEnv = new Dotenv($this->basePath);
36 36
             $dotEnv->load();
37
-        }
38
-        catch (\Dotenv\Exception\InvalidPathException $e){
37
+        } catch (\Dotenv\Exception\InvalidPathException $e){
39 38
 
40 39
         }
41 40
         date_default_timezone_set(env('APP_TIMEZONE', 'Asia/Shanghai'));
Please login to merge, or discard this patch.