Passed
Push — master ( 27a562...612a2b )
by kill
03:04
created
core/Mysql.php 1 patch
Doc Comments   +28 added lines, -29 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();
@@ -1209,9 +1209,8 @@  discard block
 block discarded – undo
1209 1209
      * A convenient function that returns TRUE if exists at least an element that
1210 1210
      * satisfy the where condition specified calling the "where" method before this one.
1211 1211
      *
1212
-     * @param string $tableName The name of the database table to work with.
1213 1212
      *
1214
-     * @return array Contains the returned rows from the select query.
1213
+     * @return boolean Contains the returned rows from the select query.
1215 1214
      */
1216 1215
     public function has() {
1217 1216
         $this->getOne($this->tableName, '1');
@@ -1311,7 +1310,7 @@  discard block
 block discarded – undo
1311 1310
      * @param int|array $numRows Array to define SQL limit in format Array ($count, $offset)
1312 1311
      *                               or only $count
1313 1312
      *
1314
-     * @return bool Indicates success. 0 or 1.
1313
+     * @return null|boolean Indicates success. 0 or 1.
1315 1314
      */
1316 1315
     public function delete($numRows = null) {
1317 1316
         if ($this->isSubQuery) {
@@ -1342,7 +1341,7 @@  discard block
 block discarded – undo
1342 1341
      * @param array $updateColumns Variable with values
1343 1342
      * @param string $lastInsertId Variable value
1344 1343
      *
1345
-     * @return MysqliDb
1344
+     * @return Mysql
1346 1345
      */
1347 1346
     public function onDuplicate($updateColumns, $lastInsertId = null) {
1348 1347
         $this->_lastInsertId = $lastInsertId;
@@ -1359,7 +1358,7 @@  discard block
 block discarded – undo
1359 1358
      * @param mixed $whereValue The value of the database field.
1360 1359
      * @param string $operator Comparison operator. Default is =
1361 1360
      *
1362
-     * @return MysqliDb
1361
+     * @return Mysql
1363 1362
      */
1364 1363
     public function orWhere($whereProp, $whereValue = 'DBNULL', $operator = '=') {
1365 1364
         return $this->where($whereProp, $whereValue, $operator, 'OR');
@@ -1375,7 +1374,7 @@  discard block
 block discarded – undo
1375 1374
      * @param string $operator Comparison operator. Default is =
1376 1375
      * @param string $cond Condition of where statement (OR, AND)
1377 1376
      *
1378
-     * @return MysqliDb
1377
+     * @return Mysql
1379 1378
      */
1380 1379
     public function where($whereProp, $whereValue = 'DBNULL', $operator = '=', $cond = 'AND') {
1381 1380
         // forkaround for an old operation api
@@ -1401,7 +1400,7 @@  discard block
 block discarded – undo
1401 1400
      * @param mixed $havingValue The value of the database field.
1402 1401
      * @param string $operator Comparison operator. Default is =
1403 1402
      *
1404
-     * @return MysqliDb
1403
+     * @return Mysql
1405 1404
      */
1406 1405
     public function orHaving($havingProp, $havingValue = null, $operator = null) {
1407 1406
         return $this->having($havingProp, $havingValue, $operator, 'OR');
@@ -1416,7 +1415,7 @@  discard block
 block discarded – undo
1416 1415
      * @param mixed $havingValue The value of the database field.
1417 1416
      * @param string $operator Comparison operator. Default is =
1418 1417
      *
1419
-     * @return MysqliDb
1418
+     * @return Mysql
1420 1419
      */
1421 1420
 
1422 1421
     public function having($havingProp, $havingValue = 'DBNULL', $operator = '=', $cond = 'AND') {
@@ -1444,7 +1443,7 @@  discard block
 block discarded – undo
1444 1443
      * @param string $joinType 'LEFT', 'INNER' etc.
1445 1444
      *
1446 1445
      * @throws Exception
1447
-     * @return MysqliDb
1446
+     * @return Mysql
1448 1447
      */
1449 1448
     public function join($joinTable, $joinCondition, $joinType = '') {
1450 1449
         $allowedTypes = array('LEFT', 'RIGHT', 'OUTER', 'INNER', 'LEFT OUTER', 'RIGHT OUTER');
@@ -1529,7 +1528,7 @@  discard block
 block discarded – undo
1529 1528
      * This method does not escape strings by default so make sure you'll never use it in production.
1530 1529
      *
1531 1530
      * @author Jonas Barascu
1532
-     * @param [[Type]] $query [[Description]]
1531
+     * @param string $query [[Description]]
1533 1532
      */
1534 1533
     private function queryUnprepared($query) {
1535 1534
         // Execute query
@@ -1603,11 +1602,11 @@  discard block
 block discarded – undo
1603 1602
      * @uses $MySqliDb->orderBy('id', 'desc')->orderBy('name', 'desc');
1604 1603
      *
1605 1604
      * @param string $orderByField The name of the database field.
1606
-     * @param string $orderByDirection Order direction.
1605
+     * @param string $orderbyDirection Order direction.
1607 1606
      * @param array $customFields Fieldset for ORDER BY FIELD() ordering
1608 1607
      *
1609 1608
      * @throws Exception
1610
-     * @return MysqliDb
1609
+     * @return Mysql
1611 1610
      */
1612 1611
     public function orderBy($orderByField, $orderbyDirection = "DESC", $customFields = null) {
1613 1612
         $allowedDirection = Array("ASC", "DESC");
@@ -1643,7 +1642,7 @@  discard block
 block discarded – undo
1643 1642
      *
1644 1643
      * @param string $groupByField The name of the database field.
1645 1644
      *
1646
-     * @return MysqliDb
1645
+     * @return Mysql
1647 1646
      */
1648 1647
     public function groupBy($groupByField) {
1649 1648
         $groupByField = preg_replace("/[^-a-z0-9\.\(\),_\*]+/i", '', $groupByField);
@@ -1659,7 +1658,7 @@  discard block
 block discarded – undo
1659 1658
      * @param  string $method The table lock method. Can be READ or WRITE.
1660 1659
      *
1661 1660
      * @throws Exception
1662
-     * @return MysqliDb
1661
+     * @return Mysql
1663 1662
      */
1664 1663
     public function setLockMethod($method) {
1665 1664
         // Switch the uppercase string
@@ -1806,7 +1805,7 @@  discard block
 block discarded – undo
1806 1805
      *
1807 1806
      * @param string $prefix Contains a tableprefix
1808 1807
      *
1809
-     * @return MysqliDb
1808
+     * @return Mysql
1810 1809
      */
1811 1810
     public function setPrefix($prefix = '') {
1812 1811
         $this->prefix = $prefix;
@@ -2016,7 +2015,7 @@  discard block
 block discarded – undo
2016 2015
      * @param bool $enabled Enable execution time tracking
2017 2016
      * @param string $stripPrefix Prefix to strip from the path in exec log
2018 2017
      *
2019
-     * @return MysqliDb
2018
+     * @return Mysql
2020 2019
      */
2021 2020
     public function setTrace($enabled, $stripPrefix = null) {
2022 2021
         $this->traceEnabled = $enabled;
@@ -2053,7 +2052,7 @@  discard block
 block discarded – undo
2053 2052
      *
2054 2053
      * @param string $idField field name to use for a mapped element key
2055 2054
      *
2056
-     * @return MysqliDb
2055
+     * @return Mysql
2057 2056
      */
2058 2057
     public function map($idField) {
2059 2058
         $this->_mapKey = $idField;
@@ -2069,7 +2068,7 @@  discard block
 block discarded – undo
2069 2068
      * @param string $whereProp The name of the database field.
2070 2069
      * @param mixed $whereValue The value of the database field.
2071 2070
      *
2072
-     * @return dbWrapper
2071
+     * @return Mysql
2073 2072
      */
2074 2073
     public function joinOrWhere($whereJoin, $whereProp, $whereValue = 'DBNULL', $operator = '=', $cond = 'AND') {
2075 2074
         return $this->joinWhere($whereJoin, $whereProp, $whereValue, $operator, 'OR');
@@ -2084,7 +2083,7 @@  discard block
 block discarded – undo
2084 2083
      * @param string $whereProp The name of the database field.
2085 2084
      * @param mixed $whereValue The value of the database field.
2086 2085
      *
2087
-     * @return dbWrapper
2086
+     * @return Mysql
2088 2087
      */
2089 2088
     public function joinWhere($whereJoin, $whereProp, $whereValue = 'DBNULL', $operator = '=', $cond = 'AND') {
2090 2089
         $this->_joinAnd[$whereJoin][] = Array($cond, $whereProp, $operator, $whereValue);
@@ -2160,7 +2159,7 @@  discard block
 block discarded – undo
2160 2159
      * Helper function to create dbObject with array return type
2161 2160
      * Added for consistency as thats default output type
2162 2161
      *
2163
-     * @return MysqliDb
2162
+     * @return Mysql
2164 2163
      */
2165 2164
     public function arrayBuilder() {
2166 2165
         $this->returnType = 'array';
@@ -2241,7 +2240,7 @@  discard block
 block discarded – undo
2241 2240
     /**
2242 2241
      * Function to enable SQL_CALC_FOUND_ROWS in the get queries
2243 2242
      *
2244
-     * @return MysqliDb
2243
+     * @return Mysql
2245 2244
      */
2246 2245
     public function withTotalCount() {
2247 2246
         $this->setQueryOption('SQL_CALC_FOUND_ROWS');
@@ -2253,10 +2252,10 @@  discard block
 block discarded – undo
2253 2252
      *
2254 2253
      * @uses $MySqliDb->setQueryOption('name');
2255 2254
      *
2256
-     * @param string|array $options The optons name of the query.
2255
+     * @param string $options The optons name of the query.
2257 2256
      *
2258 2257
      * @throws Exception
2259
-     * @return MysqliDb
2258
+     * @return Mysql
2260 2259
      */
2261 2260
     public function setQueryOption($options) {
2262 2261
         $allowedOptions = Array('ALL', 'DISTINCT', 'DISTINCTROW', 'HIGH_PRIORITY', 'STRAIGHT_JOIN', 'SQL_SMALL_RESULT',
Please login to merge, or discard this patch.
core/Model.php 2 patches
Spacing   +127 added lines, -127 removed lines patch added patch discarded remove patch
@@ -9,13 +9,13 @@  discard block
 block discarded – undo
9 9
      *
10 10
      * @var int
11 11
      */
12
-    public static $pageLimit = 20;
12
+    public static $pageLimit=20;
13 13
     /**
14 14
      * Variable that holds total pages count of last paginate() query
15 15
      *
16 16
      * @var int
17 17
      */
18
-    public static $totalPages = 0;
18
+    public static $totalPages=0;
19 19
     /**
20 20
      * Models path
21 21
      *
@@ -33,33 +33,33 @@  discard block
 block discarded – undo
33 33
      *
34 34
      * @var boolean
35 35
      */
36
-    public $isNew = true;
36
+    public $isNew=true;
37 37
     /**
38 38
      * Return type: 'Array' to return results as array, 'Object' as object
39 39
      * 'Json' as json string
40 40
      *
41 41
      * @var string
42 42
      */
43
-    public $returnType = 'Object';
43
+    public $returnType='Object';
44 44
     /**
45 45
      * An array that holds insert/update/select errors
46 46
      *
47 47
      * @var array
48 48
      */
49
-    public $errors = null;
49
+    public $errors=null;
50 50
     /**
51 51
      * Primary key for an object. 'id' is a default value.
52 52
      *
53 53
      * @var stating
54 54
      */
55
-    protected $primaryKey = 'id';
55
+    protected $primaryKey='id';
56 56
     /**
57 57
      * Table name for an object. Class name will be used by default
58 58
      *
59 59
      * @var stating
60 60
      */
61 61
     protected $dbTable;
62
-    protected $dbConn = null;
62
+    protected $dbConn=null;
63 63
     protected $prefix;
64 64
     /**
65 65
      * Working instance of MysqliDb created earlier
@@ -73,24 +73,24 @@  discard block
 block discarded – undo
73 73
      *
74 74
      * @var string
75 75
      */
76
-    private $_with = Array();
76
+    private $_with=Array();
77 77
 
78 78
     /**
79 79
      * @param array $data Data to preload on object creation
80 80
      */
81 81
     public function __construct() {
82
-        $this->db = app('db')->connect($this->dbConn);
82
+        $this->db=app('db')->connect($this->dbConn);
83 83
         if ($this->prefix) {
84
-            $this->db = $this->db->setPrefix($this->prefix);
84
+            $this->db=$this->db->setPrefix($this->prefix);
85 85
         }
86 86
         if (!$this->dbTable) {
87
-            $classFull = get_class($this);
88
-            $classArray = explode("\\", $classFull);
89
-            $classSelf = array_pop($classArray);
90
-            $classSelf = Str::snake($classSelf);
91
-            $this->dbTable = $classSelf;
87
+            $classFull=get_class($this);
88
+            $classArray=explode("\\", $classFull);
89
+            $classSelf=array_pop($classArray);
90
+            $classSelf=Str::snake($classSelf);
91
+            $this->dbTable=$classSelf;
92 92
         }
93
-        $this->db = $this->db->table($this->dbTable);
93
+        $this->db=$this->db->table($this->dbTable);
94 94
     }
95 95
 
96 96
     /**
@@ -100,10 +100,10 @@  discard block
 block discarded – undo
100 100
      * @return dbObject
101 101
      */
102 102
     public static function table($tableName) {
103
-        $tableName = preg_replace("/[^-a-z0-9_]+/i", '', $tableName);
103
+        $tableName=preg_replace("/[^-a-z0-9_]+/i", '', $tableName);
104 104
         if (!class_exists($tableName))
105 105
             eval ("class $tableName extends dbObject {}");
106
-        return new $tableName ();
106
+        return new $tableName();
107 107
     }
108 108
 
109 109
     /**
@@ -117,23 +117,23 @@  discard block
 block discarded – undo
117 117
      * @return mixed
118 118
      */
119 119
     public static function __callStatic($method, $arg) {
120
-        $obj = new static;
121
-        $result = call_user_func_array(array($obj, $method), $arg);
120
+        $obj=new static;
121
+        $result=call_user_func_array(array($obj, $method), $arg);
122 122
         if (method_exists($obj, $method))
123 123
             return $result;
124 124
         return $obj;
125 125
     }
126 126
 
127
-    public static function autoload($path = null) {
127
+    public static function autoload($path=null) {
128 128
         if ($path)
129
-            static::$modelPath = $path . "/";
129
+            static::$modelPath=$path."/";
130 130
         else
131
-            static::$modelPath = __DIR__ . "/models/";
131
+            static::$modelPath=__DIR__."/models/";
132 132
         spl_autoload_register("dbObject::dbObjectAutoload");
133 133
     }
134 134
 
135 135
     private static function dbObjectAutoload($classname) {
136
-        $filename = static::$modelPath . $classname . ".php";
136
+        $filename=static::$modelPath.$classname.".php";
137 137
         if (file_exists($filename))
138 138
             include($filename);
139 139
     }
@@ -153,20 +153,20 @@  discard block
 block discarded – undo
153 153
             return $this->data[$name];
154 154
 
155 155
         if (property_exists($this, 'relations') && isset ($this->relations[$name])) {
156
-            $relationType = strtolower($this->relations[$name][0]);
157
-            $modelName = $this->relations[$name][1];
156
+            $relationType=strtolower($this->relations[$name][0]);
157
+            $modelName=$this->relations[$name][1];
158 158
             switch ($relationType) {
159 159
                 case 'hasone':
160
-                    $key = isset ($this->relations[$name][2]) ? $this->relations[$name][2] : $name;
161
-                    $obj = new $modelName;
162
-                    $obj->returnType = $this->returnType;
163
-                    return $this->data[$name] = $obj->byId($this->data[$key]);
160
+                    $key=isset ($this->relations[$name][2]) ? $this->relations[$name][2] : $name;
161
+                    $obj=new $modelName;
162
+                    $obj->returnType=$this->returnType;
163
+                    return $this->data[$name]=$obj->byId($this->data[$key]);
164 164
                     break;
165 165
                 case 'hasmany':
166
-                    $key = $this->relations[$name][2];
167
-                    $obj = new $modelName;
168
-                    $obj->returnType = $this->returnType;
169
-                    return $this->data[$name] = $obj->where($key, $this->data[$this->primaryKey])->get();
166
+                    $key=$this->relations[$name][2];
167
+                    $obj=new $modelName;
168
+                    $obj->returnType=$this->returnType;
169
+                    return $this->data[$name]=$obj->where($key, $this->data[$this->primaryKey])->get();
170 170
                     break;
171 171
                 default:
172 172
                     break;
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
         if (property_exists($this, 'hidden') && array_search($name, $this->hidden) !== false)
190 190
             return;
191 191
 
192
-        $this->data[$name] = $value;
192
+        $this->data[$name]=$value;
193 193
     }
194 194
 
195 195
     public function __isset($name) {
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
      *
210 210
      * @return mixed insert id or false in case of failure
211 211
      */
212
-    public function save($data = null) {
212
+    public function save($data=null) {
213 213
         if ($this->isNew)
214 214
             return $this->insert();
215 215
         return $this->update($data);
@@ -220,22 +220,22 @@  discard block
 block discarded – undo
220 220
      */
221 221
     public function insert() {
222 222
         if (!empty ($this->timestamps) && in_array("createdAt", $this->timestamps))
223
-            $this->createdAt = date("Y-m-d H:i:s");
224
-        $sqlData = $this->prepareData();
223
+            $this->createdAt=date("Y-m-d H:i:s");
224
+        $sqlData=$this->prepareData();
225 225
         if (!$this->validate($sqlData))
226 226
             return false;
227 227
 
228
-        $id = $this->db->insert($this->dbTable, $sqlData);
228
+        $id=$this->db->insert($this->dbTable, $sqlData);
229 229
         if (!empty ($this->primaryKey) && empty ($this->data[$this->primaryKey]))
230
-            $this->data[$this->primaryKey] = $id;
231
-        $this->isNew = false;
230
+            $this->data[$this->primaryKey]=$id;
231
+        $this->isNew=false;
232 232
 
233 233
         return $id;
234 234
     }
235 235
 
236 236
     private function prepareData() {
237
-        $this->errors = Array();
238
-        $sqlData = Array();
237
+        $this->errors=Array();
238
+        $sqlData=Array();
239 239
         if (count($this->data) == 0)
240 240
             return Array();
241 241
 
@@ -247,27 +247,27 @@  discard block
 block discarded – undo
247 247
 
248 248
         foreach ($this->data as $key => &$value) {
249 249
             if ($value instanceof dbObject && $value->isNew == true) {
250
-                $id = $value->save();
250
+                $id=$value->save();
251 251
                 if ($id)
252
-                    $value = $id;
252
+                    $value=$id;
253 253
                 else
254
-                    $this->errors = array_merge($this->errors, $value->errors);
254
+                    $this->errors=array_merge($this->errors, $value->errors);
255 255
             }
256 256
 
257 257
             if (!in_array($key, array_keys($this->dbFields)))
258 258
                 continue;
259 259
 
260 260
             if (!is_array($value)) {
261
-                $sqlData[$key] = $value;
261
+                $sqlData[$key]=$value;
262 262
                 continue;
263 263
             }
264 264
 
265 265
             if (isset ($this->jsonFields) && in_array($key, $this->jsonFields))
266
-                $sqlData[$key] = json_encode($value);
266
+                $sqlData[$key]=json_encode($value);
267 267
             else if (isset ($this->arrayFields) && in_array($key, $this->arrayFields))
268
-                $sqlData[$key] = implode("|", $value);
268
+                $sqlData[$key]=implode("|", $value);
269 269
             else
270
-                $sqlData[$key] = $value;
270
+                $sqlData[$key]=$value;
271 271
         }
272 272
         return $sqlData;
273 273
     }
@@ -280,23 +280,23 @@  discard block
 block discarded – undo
280 280
             return true;
281 281
 
282 282
         foreach ($this->dbFields as $key => $desc) {
283
-            $type = null;
284
-            $required = false;
283
+            $type=null;
284
+            $required=false;
285 285
             if (isset ($data[$key]))
286
-                $value = $data[$key];
286
+                $value=$data[$key];
287 287
             else
288
-                $value = null;
288
+                $value=null;
289 289
 
290 290
             if (is_array($value))
291 291
                 continue;
292 292
 
293 293
             if (isset ($desc[0]))
294
-                $type = $desc[0];
294
+                $type=$desc[0];
295 295
             if (isset ($desc[1]) && ($desc[1] == 'required'))
296
-                $required = true;
296
+                $required=true;
297 297
 
298 298
             if ($required && strlen($value) == 0) {
299
-                $this->errors[] = Array($this->dbTable . "." . $key => "is required");
299
+                $this->errors[]=Array($this->dbTable.".".$key => "is required");
300 300
                 continue;
301 301
             }
302 302
             if ($value == null)
@@ -304,29 +304,29 @@  discard block
 block discarded – undo
304 304
 
305 305
             switch ($type) {
306 306
                 case "text";
307
-                    $regexp = null;
307
+                    $regexp=null;
308 308
                     break;
309 309
                 case "int":
310
-                    $regexp = "/^[0-9]*$/";
310
+                    $regexp="/^[0-9]*$/";
311 311
                     break;
312 312
                 case "double":
313
-                    $regexp = "/^[0-9\.]*$/";
313
+                    $regexp="/^[0-9\.]*$/";
314 314
                     break;
315 315
                 case "bool":
316
-                    $regexp = '/^[yes|no|0|1|true|false]$/i';
316
+                    $regexp='/^[yes|no|0|1|true|false]$/i';
317 317
                     break;
318 318
                 case "datetime":
319
-                    $regexp = "/^[0-9a-zA-Z -:]*$/";
319
+                    $regexp="/^[0-9a-zA-Z -:]*$/";
320 320
                     break;
321 321
                 default:
322
-                    $regexp = $type;
322
+                    $regexp=$type;
323 323
                     break;
324 324
             }
325 325
             if (!$regexp)
326 326
                 continue;
327 327
 
328 328
             if (!preg_match($regexp, $value)) {
329
-                $this->errors[] = Array($this->dbTable . "." . $key => "$type validation failed");
329
+                $this->errors[]=Array($this->dbTable.".".$key => "$type validation failed");
330 330
                 continue;
331 331
             }
332 332
         }
@@ -336,7 +336,7 @@  discard block
 block discarded – undo
336 336
     /**
337 337
      * @param array $data Optional update data to apply to the object
338 338
      */
339
-    public function update($data = null) {
339
+    public function update($data=null) {
340 340
         if (empty ($this->dbFields))
341 341
             return false;
342 342
 
@@ -345,13 +345,13 @@  discard block
 block discarded – undo
345 345
 
346 346
         if ($data) {
347 347
             foreach ($data as $k => $v)
348
-                $this->$k = $v;
348
+                $this->$k=$v;
349 349
         }
350 350
 
351 351
         if (!empty ($this->timestamps) && in_array("updatedAt", $this->timestamps))
352
-            $this->updatedAt = date("Y-m-d H:i:s");
352
+            $this->updatedAt=date("Y-m-d H:i:s");
353 353
 
354
-        $sqlData = $this->prepareData();
354
+        $sqlData=$this->prepareData();
355 355
         if (!$this->validate($sqlData))
356 356
             return false;
357 357
 
@@ -384,7 +384,7 @@  discard block
 block discarded – undo
384 384
         if (method_exists($this, $method))
385 385
             return call_user_func_array(array($this, $method), $arg);
386 386
         $this->db->table($this->dbTable);
387
-        return call_user_func_array(array($this->db, $method), $arg);;
387
+        return call_user_func_array(array($this->db, $method), $arg); ;
388 388
     }
389 389
 
390 390
     /**
@@ -411,11 +411,11 @@  discard block
 block discarded – undo
411 411
      * @return array Converted data
412 412
      */
413 413
     public function toArray() {
414
-        $data = $this->data;
414
+        $data=$this->data;
415 415
         $this->processAllWith($data);
416 416
         foreach ($data as &$d) {
417 417
             if ($d instanceof dbObject)
418
-                $d = $d->data;
418
+                $d=$d->data;
419 419
         }
420 420
         return $data;
421 421
     }
@@ -425,40 +425,40 @@  discard block
 block discarded – undo
425 425
      *
426 426
      * @param array $data
427 427
      */
428
-    private function processAllWith(&$data, $shouldReset = true) {
428
+    private function processAllWith(&$data, $shouldReset=true) {
429 429
         if (count($this->_with) == 0)
430 430
             return;
431 431
 
432 432
         foreach ($this->_with as $name => $opts) {
433
-            $relationType = strtolower($opts[0]);
434
-            $modelName = $opts[1];
433
+            $relationType=strtolower($opts[0]);
434
+            $modelName=$opts[1];
435 435
             if ($relationType == 'hasone') {
436
-                $obj = new $modelName;
437
-                $table = $obj->dbTable;
438
-                $primaryKey = $obj->primaryKey;
436
+                $obj=new $modelName;
437
+                $table=$obj->dbTable;
438
+                $primaryKey=$obj->primaryKey;
439 439
 
440 440
                 if (!isset ($data[$table])) {
441
-                    $data[$name] = $this->$name;
441
+                    $data[$name]=$this->$name;
442 442
                     continue;
443 443
                 }
444 444
                 if ($data[$table][$primaryKey] === null) {
445
-                    $data[$name] = null;
445
+                    $data[$name]=null;
446 446
                 } else {
447 447
                     if ($this->returnType == 'Object') {
448
-                        $item = new $modelName ($data[$table]);
449
-                        $item->returnType = $this->returnType;
450
-                        $item->isNew = false;
451
-                        $data[$name] = $item;
448
+                        $item=new $modelName($data[$table]);
449
+                        $item->returnType=$this->returnType;
450
+                        $item->isNew=false;
451
+                        $data[$name]=$item;
452 452
                     } else {
453
-                        $data[$name] = $data[$table];
453
+                        $data[$name]=$data[$table];
454 454
                     }
455 455
                 }
456 456
                 unset ($data[$table]);
457 457
             } else
458
-                $data[$name] = $this->$name;
458
+                $data[$name]=$this->$name;
459 459
         }
460 460
         if ($shouldReset)
461
-            $this->_with = Array();
461
+            $this->_with=Array();
462 462
     }
463 463
 
464 464
     /**
@@ -471,24 +471,24 @@  discard block
 block discarded – undo
471 471
      *
472 472
      * @return array Array of dbObjects
473 473
      */
474
-    protected function get($limit = null, $fields = null) {
475
-        $objects = Array();
474
+    protected function get($limit=null, $fields=null) {
475
+        $objects=Array();
476 476
         $this->processHasOneWith();
477
-        $results = $this->db->ArrayBuilder()->get($this->dbTable, $limit, $fields);
477
+        $results=$this->db->ArrayBuilder()->get($this->dbTable, $limit, $fields);
478 478
         if ($this->db->count == 0)
479 479
             return null;
480 480
 
481 481
         foreach ($results as &$r) {
482 482
             $this->processArrays($r);
483
-            $this->data = $r;
483
+            $this->data=$r;
484 484
             $this->processAllWith($r, false);
485 485
             if ($this->returnType == 'Object') {
486
-                $item = new static ($r);
487
-                $item->isNew = false;
488
-                $objects[] = $item;
486
+                $item=new static ($r);
487
+                $item->isNew=false;
488
+                $objects[]=$item;
489 489
             }
490 490
         }
491
-        $this->_with = Array();
491
+        $this->_with=Array();
492 492
         if ($this->returnType == 'Object')
493 493
             return $objects;
494 494
 
@@ -502,11 +502,11 @@  discard block
 block discarded – undo
502 502
         if (count($this->_with) == 0)
503 503
             return;
504 504
         foreach ($this->_with as $name => $opts) {
505
-            $relationType = strtolower($opts[0]);
506
-            $modelName = $opts[1];
507
-            $key = null;
505
+            $relationType=strtolower($opts[0]);
506
+            $modelName=$opts[1];
507
+            $key=null;
508 508
             if (isset ($opts[2]))
509
-                $key = $opts[2];
509
+                $key=$opts[2];
510 510
             if ($relationType == 'hasone') {
511 511
                 $this->db->setQueryOption("MYSQLI_NESTJOIN");
512 512
                 $this->join($modelName, $key);
@@ -525,18 +525,18 @@  discard block
 block discarded – undo
525 525
      *
526 526
      * @return dbObject
527 527
      */
528
-    private function join($objectName, $key = null, $joinType = 'LEFT', $primaryKey = null) {
529
-        $joinObj = new $objectName;
528
+    private function join($objectName, $key=null, $joinType='LEFT', $primaryKey=null) {
529
+        $joinObj=new $objectName;
530 530
         if (!$key)
531
-            $key = $objectName . "id";
531
+            $key=$objectName."id";
532 532
 
533 533
         if (!$primaryKey)
534
-            $primaryKey = $this->db->getPrefix() . $joinObj->dbTable . "." . $joinObj->primaryKey;
534
+            $primaryKey=$this->db->getPrefix().$joinObj->dbTable.".".$joinObj->primaryKey;
535 535
 
536 536
         if (!strchr($key, '.'))
537
-            $joinStr = $this->db->getPrefix() . $this->dbTable . ".{$key} = " . $primaryKey;
537
+            $joinStr=$this->db->getPrefix().$this->dbTable.".{$key} = ".$primaryKey;
538 538
         else
539
-            $joinStr = $this->db->getPrefix() . "{$key} = " . $primaryKey;
539
+            $joinStr=$this->db->getPrefix()."{$key} = ".$primaryKey;
540 540
 
541 541
         $this->db->join($joinObj->dbTable, $joinStr, $joinType);
542 542
         return $this;
@@ -548,12 +548,12 @@  discard block
 block discarded – undo
548 548
     private function processArrays(&$data) {
549 549
         if (isset ($this->jsonFields) && is_array($this->jsonFields)) {
550 550
             foreach ($this->jsonFields as $key)
551
-                $data[$key] = json_decode($data[$key]);
551
+                $data[$key]=json_decode($data[$key]);
552 552
         }
553 553
 
554 554
         if (isset ($this->arrayFields) && is_array($this->arrayFields)) {
555 555
             foreach ($this->arrayFields as $key)
556
-                $data[$key] = explode("|", $data[$key]);
556
+                $data[$key]=explode("|", $data[$key]);
557 557
         }
558 558
     }
559 559
 
@@ -563,7 +563,7 @@  discard block
 block discarded – undo
563 563
      * @return int
564 564
      */
565 565
     protected function count() {
566
-        $res = $this->db->ArrayBuilder()->getValue($this->dbTable, "count(*)");
566
+        $res=$this->db->ArrayBuilder()->getValue($this->dbTable, "count(*)");
567 567
         if (!$res)
568 568
             return 0;
569 569
         return $res;
@@ -575,7 +575,7 @@  discard block
 block discarded – undo
575 575
      * @return dbObject
576 576
      */
577 577
     private function JsonBuilder() {
578
-        $this->returnType = 'Json';
578
+        $this->returnType='Json';
579 579
         return $this;
580 580
     }
581 581
 
@@ -589,7 +589,7 @@  discard block
 block discarded – undo
589 589
      * @return dbObject
590 590
      */
591 591
     private function ArrayBuilder() {
592
-        $this->returnType = 'Array';
592
+        $this->returnType='Array';
593 593
         return $this;
594 594
     }
595 595
 
@@ -600,7 +600,7 @@  discard block
 block discarded – undo
600 600
      * @return dbObject
601 601
      */
602 602
     private function ObjectBuilder() {
603
-        $this->returnType = 'Object';
603
+        $this->returnType='Object';
604 604
         return $this;
605 605
     }
606 606
 
@@ -613,8 +613,8 @@  discard block
 block discarded – undo
613 613
      *
614 614
      * @return dbObject|array
615 615
      */
616
-    private function byId($id, $fields = null) {
617
-        $this->db->where($this->db->getPrefix() . $this->dbTable . '.' . $this->primaryKey, $id);
616
+    private function byId($id, $fields=null) {
617
+        $this->db->where($this->db->getPrefix().$this->dbTable.'.'.$this->primaryKey, $id);
618 618
         return $this->getOne($fields);
619 619
     }
620 620
 
@@ -626,22 +626,22 @@  discard block
 block discarded – undo
626 626
      *
627 627
      * @return dbObject
628 628
      */
629
-    protected function getOne($fields = null) {
629
+    protected function getOne($fields=null) {
630 630
         $this->processHasOneWith();
631
-        $results = $this->db->ArrayBuilder()->getOne($this->dbTable, $fields);
631
+        $results=$this->db->ArrayBuilder()->getOne($this->dbTable, $fields);
632 632
         if ($this->db->count == 0)
633 633
             return null;
634 634
 
635 635
         $this->processArrays($results);
636
-        $this->data = $results;
636
+        $this->data=$results;
637 637
         $this->processAllWith($results);
638 638
         if ($this->returnType == 'Json')
639 639
             return json_encode($results);
640 640
         if ($this->returnType == 'Array')
641 641
             return $results;
642 642
 
643
-        $item = new static ($results);
644
-        $item->isNew = false;
643
+        $item=new static ($results);
644
+        $item->isNew=false;
645 645
 
646 646
         return $item;
647 647
     }
@@ -658,7 +658,7 @@  discard block
 block discarded – undo
658 658
         if (!property_exists($this, 'relations') && !isset ($this->relations[$name]))
659 659
             die ("No relation with name $objectName found");
660 660
 
661
-        $this->_with[$objectName] = $this->relations[$objectName];
661
+        $this->_with[$objectName]=$this->relations[$objectName];
662 662
 
663 663
         return $this;
664 664
     }
@@ -679,23 +679,23 @@  discard block
 block discarded – undo
679 679
      * @param array|string $fields Array or coma separated list of fields to fetch
680 680
      * @return array
681 681
      */
682
-    private function paginate($page, $fields = null) {
683
-        $this->db->pageLimit = self::$pageLimit;
684
-        $res = $this->db->paginate($this->dbTable, $page, $fields);
685
-        self::$totalPages = $this->db->totalPages;
682
+    private function paginate($page, $fields=null) {
683
+        $this->db->pageLimit=self::$pageLimit;
684
+        $res=$this->db->paginate($this->dbTable, $page, $fields);
685
+        self::$totalPages=$this->db->totalPages;
686 686
         if ($this->db->count == 0) return null;
687 687
 
688 688
         foreach ($res as &$r) {
689 689
             $this->processArrays($r);
690
-            $this->data = $r;
690
+            $this->data=$r;
691 691
             $this->processAllWith($r, false);
692 692
             if ($this->returnType == 'Object') {
693
-                $item = new static ($r);
694
-                $item->isNew = false;
695
-                $objects[] = $item;
693
+                $item=new static ($r);
694
+                $item->isNew=false;
695
+                $objects[]=$item;
696 696
             }
697 697
         }
698
-        $this->_with = Array();
698
+        $this->_with=Array();
699 699
         if ($this->returnType == 'Object')
700 700
             return $objects;
701 701
 
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
         $this->db->table($this->dbTable);
387 422
         return call_user_func_array(array($this->db, $method), $arg);;
388 423
     }
@@ -414,8 +449,9 @@  discard block
 block discarded – undo
414 449
         $data = $this->data;
415 450
         $this->processAllWith($data);
416 451
         foreach ($data as &$d) {
417
-            if ($d instanceof dbObject)
418
-                $d = $d->data;
452
+            if ($d instanceof dbObject) {
453
+                            $d = $d->data;
454
+            }
419 455
         }
420 456
         return $data;
421 457
     }
@@ -426,8 +462,9 @@  discard block
 block discarded – undo
426 462
      * @param array $data
427 463
      */
428 464
     private function processAllWith(&$data, $shouldReset = true) {
429
-        if (count($this->_with) == 0)
430
-            return;
465
+        if (count($this->_with) == 0) {
466
+                    return;
467
+        }
431 468
 
432 469
         foreach ($this->_with as $name => $opts) {
433 470
             $relationType = strtolower($opts[0]);
@@ -454,11 +491,13 @@  discard block
 block discarded – undo
454 491
                     }
455 492
                 }
456 493
                 unset ($data[$table]);
457
-            } else
458
-                $data[$name] = $this->$name;
494
+            } else {
495
+                            $data[$name] = $this->$name;
496
+            }
497
+        }
498
+        if ($shouldReset) {
499
+                    $this->_with = Array();
459 500
         }
460
-        if ($shouldReset)
461
-            $this->_with = Array();
462 501
     }
463 502
 
464 503
     /**
@@ -475,8 +514,9 @@  discard block
 block discarded – undo
475 514
         $objects = Array();
476 515
         $this->processHasOneWith();
477 516
         $results = $this->db->ArrayBuilder()->get($this->dbTable, $limit, $fields);
478
-        if ($this->db->count == 0)
479
-            return null;
517
+        if ($this->db->count == 0) {
518
+                    return null;
519
+        }
480 520
 
481 521
         foreach ($results as &$r) {
482 522
             $this->processArrays($r);
@@ -489,24 +529,28 @@  discard block
 block discarded – undo
489 529
             }
490 530
         }
491 531
         $this->_with = Array();
492
-        if ($this->returnType == 'Object')
493
-            return $objects;
532
+        if ($this->returnType == 'Object') {
533
+                    return $objects;
534
+        }
494 535
 
495
-        if ($this->returnType == 'Json')
496
-            return json_encode($results);
536
+        if ($this->returnType == 'Json') {
537
+                    return json_encode($results);
538
+        }
497 539
 
498 540
         return $results;
499 541
     }
500 542
 
501 543
     private function processHasOneWith() {
502
-        if (count($this->_with) == 0)
503
-            return;
544
+        if (count($this->_with) == 0) {
545
+                    return;
546
+        }
504 547
         foreach ($this->_with as $name => $opts) {
505 548
             $relationType = strtolower($opts[0]);
506 549
             $modelName = $opts[1];
507 550
             $key = null;
508
-            if (isset ($opts[2]))
509
-                $key = $opts[2];
551
+            if (isset ($opts[2])) {
552
+                            $key = $opts[2];
553
+            }
510 554
             if ($relationType == 'hasone') {
511 555
                 $this->db->setQueryOption("MYSQLI_NESTJOIN");
512 556
                 $this->join($modelName, $key);
@@ -527,16 +571,19 @@  discard block
 block discarded – undo
527 571
      */
528 572
     private function join($objectName, $key = null, $joinType = 'LEFT', $primaryKey = null) {
529 573
         $joinObj = new $objectName;
530
-        if (!$key)
531
-            $key = $objectName . "id";
574
+        if (!$key) {
575
+                    $key = $objectName . "id";
576
+        }
532 577
 
533
-        if (!$primaryKey)
534
-            $primaryKey = $this->db->getPrefix() . $joinObj->dbTable . "." . $joinObj->primaryKey;
578
+        if (!$primaryKey) {
579
+                    $primaryKey = $this->db->getPrefix() . $joinObj->dbTable . "." . $joinObj->primaryKey;
580
+        }
535 581
 
536
-        if (!strchr($key, '.'))
537
-            $joinStr = $this->db->getPrefix() . $this->dbTable . ".{$key} = " . $primaryKey;
538
-        else
539
-            $joinStr = $this->db->getPrefix() . "{$key} = " . $primaryKey;
582
+        if (!strchr($key, '.')) {
583
+                    $joinStr = $this->db->getPrefix() . $this->dbTable . ".{$key} = " . $primaryKey;
584
+        } else {
585
+                    $joinStr = $this->db->getPrefix() . "{$key} = " . $primaryKey;
586
+        }
540 587
 
541 588
         $this->db->join($joinObj->dbTable, $joinStr, $joinType);
542 589
         return $this;
@@ -547,13 +594,15 @@  discard block
 block discarded – undo
547 594
      */
548 595
     private function processArrays(&$data) {
549 596
         if (isset ($this->jsonFields) && is_array($this->jsonFields)) {
550
-            foreach ($this->jsonFields as $key)
551
-                $data[$key] = json_decode($data[$key]);
597
+            foreach ($this->jsonFields as $key) {
598
+                            $data[$key] = json_decode($data[$key]);
599
+            }
552 600
         }
553 601
 
554 602
         if (isset ($this->arrayFields) && is_array($this->arrayFields)) {
555
-            foreach ($this->arrayFields as $key)
556
-                $data[$key] = explode("|", $data[$key]);
603
+            foreach ($this->arrayFields as $key) {
604
+                            $data[$key] = explode("|", $data[$key]);
605
+            }
557 606
         }
558 607
     }
559 608
 
@@ -564,8 +613,9 @@  discard block
 block discarded – undo
564 613
      */
565 614
     protected function count() {
566 615
         $res = $this->db->ArrayBuilder()->getValue($this->dbTable, "count(*)");
567
-        if (!$res)
568
-            return 0;
616
+        if (!$res) {
617
+                    return 0;
618
+        }
569 619
         return $res;
570 620
     }
571 621
 
@@ -629,16 +679,19 @@  discard block
 block discarded – undo
629 679
     protected function getOne($fields = null) {
630 680
         $this->processHasOneWith();
631 681
         $results = $this->db->ArrayBuilder()->getOne($this->dbTable, $fields);
632
-        if ($this->db->count == 0)
633
-            return null;
682
+        if ($this->db->count == 0) {
683
+                    return null;
684
+        }
634 685
 
635 686
         $this->processArrays($results);
636 687
         $this->data = $results;
637 688
         $this->processAllWith($results);
638
-        if ($this->returnType == 'Json')
639
-            return json_encode($results);
640
-        if ($this->returnType == 'Array')
641
-            return $results;
689
+        if ($this->returnType == 'Json') {
690
+                    return json_encode($results);
691
+        }
692
+        if ($this->returnType == 'Array') {
693
+                    return $results;
694
+        }
642 695
 
643 696
         $item = new static ($results);
644 697
         $item->isNew = false;
@@ -655,8 +708,9 @@  discard block
 block discarded – undo
655 708
      * @return dbObject
656 709
      */
657 710
     private function with($objectName) {
658
-        if (!property_exists($this, 'relations') && !isset ($this->relations[$name]))
659
-            die ("No relation with name $objectName found");
711
+        if (!property_exists($this, 'relations') && !isset ($this->relations[$name])) {
712
+                    die ("No relation with name $objectName found");
713
+        }
660 714
 
661 715
         $this->_with[$objectName] = $this->relations[$objectName];
662 716
 
@@ -683,7 +737,9 @@  discard block
 block discarded – undo
683 737
         $this->db->pageLimit = self::$pageLimit;
684 738
         $res = $this->db->paginate($this->dbTable, $page, $fields);
685 739
         self::$totalPages = $this->db->totalPages;
686
-        if ($this->db->count == 0) return null;
740
+        if ($this->db->count == 0) {
741
+            return null;
742
+        }
687 743
 
688 744
         foreach ($res as &$r) {
689 745
             $this->processArrays($r);
@@ -696,11 +752,13 @@  discard block
 block discarded – undo
696 752
             }
697 753
         }
698 754
         $this->_with = Array();
699
-        if ($this->returnType == 'Object')
700
-            return $objects;
755
+        if ($this->returnType == 'Object') {
756
+                    return $objects;
757
+        }
701 758
 
702
-        if ($this->returnType == 'Json')
703
-            return json_encode($res);
759
+        if ($this->returnType == 'Json') {
760
+                    return json_encode($res);
761
+        }
704 762
 
705 763
         return $res;
706 764
     }
Please login to merge, or discard this patch.