Completed
Push — master ( e4d56c...8e58c0 )
by Ivan
02:47
created
src/driver/oracle/Result.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
     }
24 24
     public function affected() : int
25 25
     {
26
-        return (int)\oci_num_rows($this->statement);
26
+        return (int) \oci_num_rows($this->statement);
27 27
     }
28 28
     public function insertID()
29 29
     {
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
     }
65 65
     public function next()
66 66
     {
67
-        $this->fetched ++;
67
+        $this->fetched++;
68 68
         $this->last = \oci_fetch_array($this->statement, \OCI_ASSOC + \OCI_RETURN_NULLS + \OCI_RETURN_LOBS);
69 69
     }
70 70
     public function valid()
Please login to merge, or discard this patch.
src/DB.php 1 patch
Spacing   +14 added lines, -16 removed lines patch added patch discarded remove patch
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
         $connection['pass'] = isset($temp['pass']) && strlen($temp['pass']) ? $temp['pass'] : null;
78 78
         $connection['host'] = isset($temp['host']) && strlen($temp['host']) ? $temp['host'] : null;
79 79
         $connection['name'] = isset($temp['path']) && strlen($temp['path']) ? $temp['path'] : null;
80
-        $connection['port'] = isset($temp['port']) && (int)$temp['port'] ? (int)$temp['port'] : null;
80
+        $connection['port'] = isset($temp['port']) && (int) $temp['port'] ? (int) $temp['port'] : null;
81 81
         if (isset($temp['query']) && strlen($temp['query'])) {
82 82
             parse_str($temp['query'], $connection['opts']);
83 83
         }
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
         $new = '';
115 115
         $par = array_values($par);
116 116
         if (substr_count($sql, '?') === 2 && !is_array($par[0])) {
117
-            $par = [ $par ];
117
+            $par = [$par];
118 118
         }
119 119
         $parts = explode('??', $sql);
120 120
         $index = 0;
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
             $index += count($tmp) - 1;
125 125
             if (isset($par[$index])) {
126 126
                 if (!is_array($par[$index])) {
127
-                    $par[$index] = [ $par[$index] ];
127
+                    $par[$index] = [$par[$index]];
128 128
                 }
129 129
                 $params = $par[$index];
130 130
                 array_splice($par, $index, 1, $params);
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
                 $new .= implode(',', array_fill(0, count($params), '?'));
133 133
             }
134 134
         }
135
-        return [ $new, $par ];
135
+        return [$new, $par];
136 136
     }
137 137
     /**
138 138
      * Run a query (prepare & execute).
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
     {
165 165
         $coll = Collection::from($this->query($sql, $par));
166 166
         if (($keys = $this->driver->option('mode')) && in_array($keys, ['strtoupper', 'strtolower'])) {
167
-            $coll->map(function ($v) use ($keys) {
167
+            $coll->map(function($v) use ($keys) {
168 168
                 $new = [];
169 169
                 foreach ($v as $k => $vv) {
170 170
                     $new[call_user_func($keys, $k)] = $vv;
@@ -173,18 +173,18 @@  discard block
 block discarded – undo
173 173
             });
174 174
         }
175 175
         if ($key !== null) {
176
-            $coll->mapKey(function ($v) use ($key) {
176
+            $coll->mapKey(function($v) use ($key) {
177 177
                 return $v[$key];
178 178
             });
179 179
         }
180 180
         if ($skip) {
181
-            $coll->map(function ($v) use ($key) {
181
+            $coll->map(function($v) use ($key) {
182 182
                 unset($v[$key]);
183 183
                 return $v;
184 184
             });
185 185
         }
186 186
         if ($opti) {
187
-            $coll->map(function ($v) {
187
+            $coll->map(function($v) {
188 188
                 return count($v) === 1 ? current($v) : $v;
189 189
             });
190 190
         }
@@ -270,8 +270,7 @@  discard block
 block discarded – undo
270 270
     public function definition(string $table, bool $detectRelations = true) : Table
271 271
     {
272 272
         return isset($this->tables[$table]) ?
273
-            $this->tables[$table] :
274
-            $this->driver->table($table, $detectRelations);
273
+            $this->tables[$table] : $this->driver->table($table, $detectRelations);
275 274
     }
276 275
     /**
277 276
      * Parse all tables from the database.
@@ -288,12 +287,12 @@  discard block
 block discarded – undo
288 287
      */
289 288
     public function getSchema($asPlainArray = true)
290 289
     {
291
-        return !$asPlainArray ? $this->tables : array_map(function ($table) {
290
+        return !$asPlainArray ? $this->tables : array_map(function($table) {
292 291
             return [
293 292
                 'name' => $table->getName(),
294 293
                 'pkey' => $table->getPrimaryKey(),
295 294
                 'comment' => $table->getComment(),
296
-                'columns' => array_map(function ($column) {
295
+                'columns' => array_map(function($column) {
297 296
                     return [
298 297
                         'name' => $column->getName(),
299 298
                         'type' => $column->getType(),
@@ -304,9 +303,9 @@  discard block
 block discarded – undo
304 303
                         'nullable' => $column->isNullable()
305 304
                     ];
306 305
                 }, $table->getFullColumns()),
307
-                'relations' => array_map(function ($rel) {
306
+                'relations' => array_map(function($rel) {
308 307
                     $relation = clone $rel;
309
-                    $relation = (array)$relation;
308
+                    $relation = (array) $relation;
310 309
                     $relation['table'] = $rel->table->getName();
311 310
                     if ($rel->pivot) {
312 311
                         $relation['pivot'] = $rel->pivot->getName();
@@ -359,8 +358,7 @@  discard block
 block discarded – undo
359 358
     public function table($table, bool $mapped = false)
360 359
     {
361 360
         return $mapped ?
362
-            new TableQueryMapped($this, $this->definition($table)) :
363
-            new TableQuery($this, $this->definition($table));
361
+            new TableQueryMapped($this, $this->definition($table)) : new TableQuery($this, $this->definition($table));
364 362
     }
365 363
     public function __call($method, $args)
366 364
     {
Please login to merge, or discard this patch.
src/schema/Mapper.php 1 patch
Spacing   +6 added lines, -7 removed lines patch added patch discarded remove patch
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
     public function collection(TableQueryIterator $iterator, Table $definition) : Collection
53 53
     {
54 54
         return Collection::from($iterator)
55
-            ->map(function ($v) use ($definition) {
55
+            ->map(function($v) use ($definition) {
56 56
                 return $this->entity($definition, $v);
57 57
             });
58 58
     }
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
         $definition = $entity->definition();
128 128
         foreach ($definition->getColumns() as $column) {
129 129
             if (!array_key_exists($column, $data)) {
130
-                $entity->__lazyProperty($column, function () use ($definition, $primary, $column) {
130
+                $entity->__lazyProperty($column, function() use ($definition, $primary, $column) {
131 131
                     $query = $this->db->table($definition->getName());
132 132
                     foreach ($primary as $k => $v) {
133 133
                         $query->filter($k, $v);
@@ -141,12 +141,12 @@  discard block
 block discarded – undo
141 141
                 $name,
142 142
                 array_key_exists($name, $data) && isset($data[$name]) ?
143 143
                     ($relation->many ?
144
-                        array_map(function ($v) use ($relation) {
144
+                        array_map(function($v) use ($relation) {
145 145
                             return $this->entity($relation->table, $v);
146 146
                         }, $data[$name]) :
147 147
                         $this->entity($relation->table, $data[$name])
148 148
                     ) :
149
-                    function (array $columns = null) use ($entity, $definition, $relation, $data) {
149
+                    function(array $columns = null) use ($entity, $definition, $relation, $data) {
150 150
                         $query = $this->db->table($relation->table->getName(), true);
151 151
                         if ($columns !== null) {
152 152
                             $query->columns($columns);
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
                                 );
173 173
                             }
174 174
                             foreach ($definition->getPrimaryKey() as $v) {
175
-                                $query->filter($nm . '.' . $v, $data[$v] ?? null);
175
+                                $query->filter($nm.'.'.$v, $data[$v] ?? null);
176 176
                             }
177 177
                         } else {
178 178
                             foreach ($relation->keymap as $k => $v) {
@@ -180,8 +180,7 @@  discard block
 block discarded – undo
180 180
                             }
181 181
                         }
182 182
                         return $relation->many ?
183
-                            $query->iterator() :
184
-                            $query[0];
183
+                            $query->iterator() : $query[0];
185 184
                     }
186 185
             );
187 186
         }
Please login to merge, or discard this patch.
src/schema/Entity.php 1 patch
Spacing   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -47,8 +47,7 @@
 block discarded – undo
47 47
         if (isset($this->definition->getRelations()[$method])) {
48 48
             if (array_key_exists($method, $this->fetched)) {
49 49
                 return is_callable($this->fetched[$method]) ?
50
-                    $this->fetched[$method] = call_user_func($this->fetched[$method], $args[0] ?? null) :
51
-                    $this->fetched[$method];
50
+                    $this->fetched[$method] = call_user_func($this->fetched[$method], $args[0] ?? null) : $this->fetched[$method];
52 51
             }
53 52
         }
54 53
         return null;
Please login to merge, or discard this patch.
src/schema/TableQuery.php 1 patch
Spacing   +184 added lines, -188 removed lines patch added patch discarded remove patch
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
     /**
45 45
      * @var int[]
46 46
      */
47
-    protected $li_of = [0,0,0];
47
+    protected $li_of = [0, 0, 0];
48 48
     /**
49 49
      * @var array
50 50
      */
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
     public function __construct(DBInterface $db, $table)
75 75
     {
76 76
         $this->db = $db;
77
-        $this->definition = $table instanceof Table ? $table : $this->db->definition((string)$table);
77
+        $this->definition = $table instanceof Table ? $table : $this->db->definition((string) $table);
78 78
         $primary = $this->definition->getPrimaryKey();
79 79
         $columns = $this->definition->getColumns();
80 80
         $this->pkey = count($primary) ? $primary : $columns;
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
     {
98 98
         $column = explode('.', $column);
99 99
         if (count($column) === 1) {
100
-            $column = [ $this->definition->getName(), $column[0] ];
100
+            $column = [$this->definition->getName(), $column[0]];
101 101
             $col = $this->definition->getColumn($column[1]);
102 102
             if (!$col) {
103 103
                 throw new DBException('Invalid column name in own table');
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
                         throw new DBException('Invalid column name in related table');
121 121
                     }
122 122
                 } else {
123
-                    throw new DBException('Invalid foreign table name: ' . implode(',', $column));
123
+                    throw new DBException('Invalid foreign table name: '.implode(',', $column));
124 124
                 }
125 125
             }
126 126
         } else {
@@ -129,19 +129,19 @@  discard block
 block discarded – undo
129 129
             $table = $this->definition;
130 130
             $table = array_reduce(
131 131
                 $column,
132
-                function ($carry, $item) use (&$table) {
132
+                function($carry, $item) use (&$table) {
133 133
                     $table = $table->getRelation($item)->table;
134 134
                     return $table;
135 135
                 }
136 136
             );
137 137
             $col = $table->getColumn($name);
138
-            $column = [ implode(static::SEP, $column), $name ];
138
+            $column = [implode(static::SEP, $column), $name];
139 139
         }
140
-        return [ 'name' => implode('.', $column), 'data' => $col ];
140
+        return ['name' => implode('.', $column), 'data' => $col];
141 141
     }
142 142
     protected function normalizeValue(TableColumn $col, $value)
143 143
     {
144
-        $strict = (int)$this->db->driverOption('strict', 0) > 0;
144
+        $strict = (int) $this->db->driverOption('strict', 0) > 0;
145 145
         if ($value === null && $col->isNullable()) {
146 146
             return null;
147 147
         }
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
                     $temp = strtotime($value);
152 152
                     if (!$temp) {
153 153
                         if ($strict) {
154
-                            throw new DBException('Invalid value for date column ' . $col->getName());
154
+                            throw new DBException('Invalid value for date column '.$col->getName());
155 155
                         }
156 156
                         return null;
157 157
                     }
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
                     return $value->format('Y-m-d');
165 165
                 }
166 166
                 if ($strict) {
167
-                    throw new DBException('Invalid value (unknown data type) for date column ' . $col->getName());
167
+                    throw new DBException('Invalid value (unknown data type) for date column '.$col->getName());
168 168
                 }
169 169
                 return $value;
170 170
             case 'datetime':
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
                     $temp = strtotime($value);
173 173
                     if (!$temp) {
174 174
                         if ($strict) {
175
-                            throw new DBException('Invalid value for datetime column ' . $col->getName());
175
+                            throw new DBException('Invalid value for datetime column '.$col->getName());
176 176
                         }
177 177
                         return null;
178 178
                     }
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
                     return $value->format('Y-m-d H:i:s');
186 186
                 }
187 187
                 if ($strict) {
188
-                    throw new DBException('Invalid value (unknown data type) for datetime column ' . $col->getName());
188
+                    throw new DBException('Invalid value (unknown data type) for datetime column '.$col->getName());
189 189
                 }
190 190
                 return $value;
191 191
             case 'enum':
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
                 if (is_int($value)) {
194 194
                     if (!isset($values[$value])) {
195 195
                         if ($strict) {
196
-                            throw new DBException('Invalid value (using integer) for enum ' . $col->getName());
196
+                            throw new DBException('Invalid value (using integer) for enum '.$col->getName());
197 197
                         }
198 198
                         return $value;
199 199
                     }
@@ -201,23 +201,23 @@  discard block
 block discarded – undo
201 201
                 }
202 202
                 if (!in_array($value, $col->getValues())) {
203 203
                     if ($strict) {
204
-                        throw new DBException('Invalid value for enum ' . $col->getName());
204
+                        throw new DBException('Invalid value for enum '.$col->getName());
205 205
                     }
206 206
                     return 0;
207 207
                 }
208 208
                 return $value;
209 209
             case 'int':
210 210
                 $temp = preg_replace('([^+\-0-9]+)', '', $value);
211
-                return is_string($temp) ? (int)$temp : 0;
211
+                return is_string($temp) ? (int) $temp : 0;
212 212
             case 'float':
213 213
                 $temp = preg_replace('([^+\-0-9.]+)', '', str_replace(',', '.', $value));
214
-                return is_string($temp) ? (float)$temp : 0;
214
+                return is_string($temp) ? (float) $temp : 0;
215 215
             case 'text':
216 216
                 // check using strlen first, in order to avoid hitting mb_ functions which might be polyfilled
217 217
                 // because the polyfill is quite slow
218 218
                 if ($col->hasLength() && strlen($value) > $col->getLength() && mb_strlen($value) > $col->getLength()) {
219 219
                     if ($strict) {
220
-                        throw new DBException('Invalid value for text column ' . $col->getName());
220
+                        throw new DBException('Invalid value for text column '.$col->getName());
221 221
                     }
222 222
                     return mb_substr($value, 0, $col->getLength());
223 223
                 }
@@ -239,35 +239,32 @@  discard block
 block discarded – undo
239 239
             // str_replace(['%', '_'], ['\\%','\\_'], $q)
240 240
             return $negate ?
241 241
                 [
242
-                    $name . ' NOT LIKE ?',
243
-                    [ $this->normalizeValue($column, $value) ]
244
-                ] :
245
-                [
246
-                    $name . ' LIKE ?',
247
-                    [ $this->normalizeValue($column, $value) ]
242
+                    $name.' NOT LIKE ?',
243
+                    [$this->normalizeValue($column, $value)]
244
+                ] : [
245
+                    $name.' LIKE ?',
246
+                    [$this->normalizeValue($column, $value)]
248 247
                 ];
249 248
         }
250 249
         if (is_null($value)) {
251 250
             return $negate ?
252
-                [ $name . ' IS NOT NULL', [] ]:
253
-                [ $name . ' IS NULL', [] ];
251
+                [$name.' IS NOT NULL', []] : [$name.' IS NULL', []];
254 252
         }
255 253
         if (!is_array($value)) {
256 254
             return $negate ?
257 255
                 [
258
-                    $name . ' <> ?',
259
-                    [ $this->normalizeValue($column, $value) ]
260
-                ] :
261
-                [
262
-                    $name . ' = ?',
263
-                    [ $this->normalizeValue($column, $value) ]
256
+                    $name.' <> ?',
257
+                    [$this->normalizeValue($column, $value)]
258
+                ] : [
259
+                    $name.' = ?',
260
+                    [$this->normalizeValue($column, $value)]
264 261
                 ];
265 262
         }
266 263
         if (isset($value['beg']) && strlen($value['beg']) && (!isset($value['end']) || !strlen($value['end']))) {
267
-            $value = [ 'gte' => $value['beg'] ];
264
+            $value = ['gte' => $value['beg']];
268 265
         }
269 266
         if (isset($value['end']) && strlen($value['end']) && (!isset($value['beg']) || !strlen($value['beg']))) {
270
-            $value = [ 'lte' => $value['end'] ];
267
+            $value = ['lte' => $value['end']];
271 268
         }
272 269
         if (isset($value['beg']) && isset($value['end'])) {
273 270
             return $negate ?
@@ -277,8 +274,7 @@  discard block
 block discarded – undo
277 274
                         $this->normalizeValue($column, $value['beg']),
278 275
                         $this->normalizeValue($column, $value['end'])
279 276
                     ]
280
-                ] :
281
-                [
277
+                ] : [
282 278
                     $name.' BETWEEN ? AND ?',
283 279
                     [
284 280
                         $this->normalizeValue($column, $value['beg']),
@@ -290,38 +286,38 @@  discard block
 block discarded – undo
290 286
             $sql = [];
291 287
             $par = [];
292 288
             if (isset($value['gt'])) {
293
-                $sql[] = $name. ' ' . ($negate ? '<=' : '>') . ' ?';
289
+                $sql[] = $name.' '.($negate ? '<=' : '>').' ?';
294 290
                 $par[] = $this->normalizeValue($column, $value['gt']);
295 291
             }
296 292
             if (isset($value['gte'])) {
297
-                $sql[] = $name. ' ' . ($negate ? '<' : '>=') . ' ?';
293
+                $sql[] = $name.' '.($negate ? '<' : '>=').' ?';
298 294
                 $par[] = $this->normalizeValue($column, $value['gte']);
299 295
             }
300 296
             if (isset($value['lt'])) {
301
-                $sql[] = $name. ' ' . ($negate ? '>=' : '<') . ' ?';
297
+                $sql[] = $name.' '.($negate ? '>=' : '<').' ?';
302 298
                 $par[] = $this->normalizeValue($column, $value['lt']);
303 299
             }
304 300
             if (isset($value['lte'])) {
305
-                $sql[] = $name. ' ' . ($negate ? '>' : '<=') . ' ?';
301
+                $sql[] = $name.' '.($negate ? '>' : '<=').' ?';
306 302
                 $par[] = $this->normalizeValue($column, $value['lte']);
307 303
             }
308 304
             return [
309
-                '(' . implode(' AND ', $sql) . ')',
305
+                '('.implode(' AND ', $sql).')',
310 306
                 $par
311 307
             ];
312 308
         }
313 309
         return $negate ?
314 310
             [
315
-                $name . ' NOT IN (??)',
316
-                [ array_map(function ($v) use ($column) {
311
+                $name.' NOT IN (??)',
312
+                [array_map(function($v) use ($column) {
317 313
                     return $this->normalizeValue($column, $v);
318
-                }, $value) ]
314
+                }, $value)]
319 315
             ] :
320 316
             [
321
-                $name . ' IN (??)',
322
-                [ array_map(function ($v) use ($column) {
317
+                $name.' IN (??)',
318
+                [array_map(function($v) use ($column) {
323 319
                     return $this->normalizeValue($column, $v);
324
-                }, $value) ]
320
+                }, $value)]
325 321
             ];
326 322
     }
327 323
     /**
@@ -352,7 +348,7 @@  discard block
 block discarded – undo
352 348
                 $par = array_merge($par, $temp[1]);
353 349
             }
354 350
         }
355
-        return $this->where('(' . implode(' OR ', $sql) . ')', $par);
351
+        return $this->where('('.implode(' OR ', $sql).')', $par);
356 352
     }
357 353
     /**
358 354
      * Filter the results matching all of the criteria
@@ -370,7 +366,7 @@  discard block
 block discarded – undo
370 366
                 $par = array_merge($par, $temp[1]);
371 367
             }
372 368
         }
373
-        return $this->where('(' . implode(' AND ', $sql) . ')', $par);
369
+        return $this->where('('.implode(' AND ', $sql).')', $par);
374 370
     }
375 371
     /**
376 372
      * Sort by a column
@@ -380,7 +376,7 @@  discard block
 block discarded – undo
380 376
      */
381 377
     public function sort(string $column, bool $desc = false) : self
382 378
     {
383
-        return $this->order($this->getColumn($column)['name'] . ' ' . ($desc ? 'DESC' : 'ASC'));
379
+        return $this->order($this->getColumn($column)['name'].' '.($desc ? 'DESC' : 'ASC'));
384 380
     }
385 381
     /**
386 382
      * Group by a column (or columns)
@@ -390,7 +386,7 @@  discard block
 block discarded – undo
390 386
     public function group($column) : self
391 387
     {
392 388
         if (!is_array($column)) {
393
-            $column = [ $column ];
389
+            $column = [$column];
394 390
         }
395 391
         foreach ($column as $k => $v) {
396 392
             $column[$k] = $this->getColumn($v)['name'];
@@ -432,7 +428,7 @@  discard block
 block discarded – undo
432 428
         $this->order = [];
433 429
         $this->having = [];
434 430
         $this->aliases = [];
435
-        $this->li_of = [0,0,0];
431
+        $this->li_of = [0, 0, 0];
436 432
         $this->qiterator = null;
437 433
         return $this;
438 434
     }
@@ -445,7 +441,7 @@  discard block
 block discarded – undo
445 441
     public function groupBy(string $sql, array $params = []) : self
446 442
     {
447 443
         $this->qiterator = null;
448
-        $this->group = [ $sql, $params ];
444
+        $this->group = [$sql, $params];
449 445
         return $this;
450 446
     }
451 447
     /**
@@ -458,7 +454,7 @@  discard block
 block discarded – undo
458 454
      */
459 455
     public function join($table, array $fields, string $name = null, bool $multiple = true)
460 456
     {
461
-        $table = $table instanceof Table ? $table : $this->db->definition((string)$table);
457
+        $table = $table instanceof Table ? $table : $this->db->definition((string) $table);
462 458
         $name = $name ?? $table->getName();
463 459
         if (isset($this->joins[$name]) || $this->definition->hasRelation($name)) {
464 460
             throw new DBException('Alias / table name already in use');
@@ -467,7 +463,7 @@  discard block
 block discarded – undo
467 463
         foreach ($fields as $k => $v) {
468 464
             $k = explode('.', $k, 2);
469 465
             $k = count($k) == 2 ? $k[1] : $k[0];
470
-            $this->joins[$name]->keymap[$this->getColumn($name . '.' . $k)['name']] = $this->getColumn($v)['name'];
466
+            $this->joins[$name]->keymap[$this->getColumn($name.'.'.$k)['name']] = $this->getColumn($v)['name'];
471 467
         }
472 468
         return $this;
473 469
     }
@@ -480,7 +476,7 @@  discard block
 block discarded – undo
480 476
     public function where(string $sql, array $params = []) : self
481 477
     {
482 478
         $this->qiterator = null;
483
-        $this->where[] = [ $sql, $params ];
479
+        $this->where[] = [$sql, $params];
484 480
         return $this;
485 481
     }
486 482
     /**
@@ -492,7 +488,7 @@  discard block
 block discarded – undo
492 488
     public function having(string $sql, array $params = []) : self
493 489
     {
494 490
         $this->qiterator = null;
495
-        $this->having[] = [ $sql, $params ];
491
+        $this->having[] = [$sql, $params];
496 492
         return $this;
497 493
     }
498 494
     /**
@@ -516,7 +512,7 @@  discard block
 block discarded – undo
516 512
                 $name = null;
517 513
             }
518 514
         }
519
-        $this->order = [ $sql, $params, $name ];
515
+        $this->order = [$sql, $params, $name];
520 516
         return $this;
521 517
     }
522 518
     /**
@@ -528,7 +524,7 @@  discard block
 block discarded – undo
528 524
     public function limit(int $limit, int $offset = 0, bool $limitOnMainTable = false) : self
529 525
     {
530 526
         $this->qiterator = null;
531
-        $this->li_of = [ $limit, $offset, $limitOnMainTable ? 1 : 0 ];
527
+        $this->li_of = [$limit, $offset, $limitOnMainTable ? 1 : 0];
532 528
         return $this;
533 529
     }
534 530
     /**
@@ -538,9 +534,9 @@  discard block
 block discarded – undo
538 534
     public function count() : int
539 535
     {
540 536
         $aliases = [];
541
-        $getAlias = function ($name) use (&$aliases) {
537
+        $getAlias = function($name) use (&$aliases) {
542 538
             // to bypass use: return $name;
543
-            return $aliases[$name] = $aliases[$name] ?? 'alias' . static::SEP . count($aliases);
539
+            return $aliases[$name] = $aliases[$name] ?? 'alias'.static::SEP.count($aliases);
544 540
         };
545 541
         $table = $this->definition->getName();
546 542
         $sql = 'SELECT COUNT(DISTINCT '.$table.'.'.implode(', '.$table.'.', $this->pkey).') FROM '.$table.' ';
@@ -554,47 +550,47 @@  discard block
 block discarded – undo
554 550
         $h = $this->having;
555 551
         $o = $this->order;
556 552
         $g = $this->group;
557
-        $j = array_map(function ($v) {
553
+        $j = array_map(function($v) {
558 554
             return clone $v;
559 555
         }, $this->joins);
560 556
         foreach ($this->definition->getRelations() as $k => $v) {
561 557
             foreach ($w as $kk => $vv) {
562
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv[0])) {
563
-                    $relations[$k] = [ $v, $table ];
564
-                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vv[0]);
558
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $vv[0])) {
559
+                    $relations[$k] = [$v, $table];
560
+                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vv[0]);
565 561
                 }
566 562
             }
567
-            if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) {
568
-                $relations[$k] = [ $v, $table ];
563
+            if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) {
564
+                $relations[$k] = [$v, $table];
569 565
             }
570 566
             foreach ($h as $kk => $vv) {
571
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv[0])) {
572
-                    $relations[$k] = [ $v, $table ];
573
-                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vv[0]);
567
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $vv[0])) {
568
+                    $relations[$k] = [$v, $table];
569
+                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vv[0]);
574 570
                 }
575 571
             }
576
-            if (isset($g[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $g[0])) {
577
-                $relations[$k] = [ $v, $table ];
578
-                $g[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $g[0]);
572
+            if (isset($g[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $g[0])) {
573
+                $relations[$k] = [$v, $table];
574
+                $g[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $g[0]);
579 575
             }
580 576
             foreach ($j as $kk => $vv) {
581 577
                 foreach ($vv->keymap as $kkk => $vvv) {
582
-                    if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vvv)) {
583
-                        $relations[$k] = [ $v, $table ];
578
+                    if (preg_match('(\b'.preg_quote($k.'.').')i', $vvv)) {
579
+                        $relations[$k] = [$v, $table];
584 580
                         $j[$kk]->keymap[$kkk] =
585
-                            preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vvv);
581
+                            preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vvv);
586 582
                     }
587 583
                 }
588 584
             }
589 585
         }
590 586
 
591 587
         foreach ($j as $k => $v) {
592
-            $sql .= ($v->many ? 'LEFT ' : '' ) . 'JOIN '.$v->table->getName().' '.$k.' ON ';
588
+            $sql .= ($v->many ? 'LEFT ' : '').'JOIN '.$v->table->getName().' '.$k.' ON ';
593 589
             $tmp = [];
594 590
             foreach ($v->keymap as $kk => $vv) {
595 591
                 $tmp[] = $kk.' = '.$vv;
596 592
             }
597
-            $sql .= implode(' AND ', $tmp) . ' ';
593
+            $sql .= implode(' AND ', $tmp).' ';
598 594
         }
599 595
         foreach ($relations as $k => $v) {
600 596
             $table = $v[1] !== $this->definition->getName() ? $getAlias($v[1]) : $v[1];
@@ -606,13 +602,13 @@  discard block
 block discarded – undo
606 602
                 foreach ($v->keymap as $kk => $vv) {
607 603
                     $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' ';
608 604
                 }
609
-                $sql .= implode(' AND ', $tmp) . ' ';
605
+                $sql .= implode(' AND ', $tmp).' ';
610 606
                 $sql .= 'LEFT JOIN '.$v->table->getName().' '.$getAlias($k).' ON ';
611 607
                 $tmp = [];
612 608
                 foreach ($v->pivot_keymap as $kk => $vv) {
613 609
                     $tmp[] = $getAlias($k).'.'.$vv.' = '.$alias.'.'.$kk.' ';
614 610
                 }
615
-                $sql .= implode(' AND ', $tmp) . ' ';
611
+                $sql .= implode(' AND ', $tmp).' ';
616 612
             } else {
617 613
                 $alias = $getAlias($k);
618 614
                 $sql .= 'LEFT JOIN '.$v->table->getName().' '.$alias.' ON ';
@@ -621,30 +617,30 @@  discard block
 block discarded – undo
621 617
                     $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' ';
622 618
                 }
623 619
                 if ($v->sql) {
624
-                    $tmp[] = $v->sql . ' ';
620
+                    $tmp[] = $v->sql.' ';
625 621
                     $par = array_merge($par, $v->par ?? []);
626 622
                 }
627
-                $sql .= implode(' AND ', $tmp) . ' ';
623
+                $sql .= implode(' AND ', $tmp).' ';
628 624
             }
629 625
         }
630 626
         if (count($w)) {
631 627
             $sql .= 'WHERE ';
632 628
             $tmp = [];
633 629
             foreach ($w as $v) {
634
-                $tmp[] = '(' . $v[0] . ')';
630
+                $tmp[] = '('.$v[0].')';
635 631
                 $par = array_merge($par, $v[1]);
636 632
             }
637 633
             $sql .= implode(' AND ', $tmp).' ';
638 634
         }
639 635
         if (count($g)) {
640
-            $sql .= 'GROUP BY ' . $g[0] . ' ';
636
+            $sql .= 'GROUP BY '.$g[0].' ';
641 637
             $par = array_merge($par, $g[1]);
642 638
         }
643 639
         if (count($h)) {
644 640
             $sql .= 'HAVING ';
645 641
             $tmp = [];
646 642
             foreach ($h as $v) {
647
-                $tmp[] = '(' . $v[0] . ')';
643
+                $tmp[] = '('.$v[0].')';
648 644
                 $par = array_merge($par, $v[1]);
649 645
             }
650 646
             $sql .= implode(' AND ', $tmp).' ';
@@ -678,7 +674,7 @@  discard block
 block discarded – undo
678 674
                     $this->with(implode('.', $temp));
679 675
                     $table = array_reduce(
680 676
                         $temp,
681
-                        function ($carry, $item) use (&$table) {
677
+                        function($carry, $item) use (&$table) {
682 678
                             return $table->getRelation($item)->table;
683 679
                         }
684 680
                     );
@@ -687,7 +683,7 @@  discard block
 block discarded – undo
687 683
                 }
688 684
                 unset($fields[$k]);
689 685
                 foreach ($cols as $col) {
690
-                    $fields[] = $table . '.' . $col;
686
+                    $fields[] = $table.'.'.$col;
691 687
                 }
692 688
             }
693 689
         }
@@ -719,9 +715,9 @@  discard block
 block discarded – undo
719 715
             return $this->qiterator;
720 716
         }
721 717
         $aliases = [];
722
-        $getAlias = function ($name) use (&$aliases) {
718
+        $getAlias = function($name) use (&$aliases) {
723 719
             // to bypass use: return $name;
724
-            return $aliases[$name] = $aliases[$name] ?? 'alias' . static::SEP . count($aliases);
720
+            return $aliases[$name] = $aliases[$name] ?? 'alias'.static::SEP.count($aliases);
725 721
         };
726 722
         $table = $this->definition->getName();
727 723
         if ($fields !== null) {
@@ -737,7 +733,7 @@  discard block
 block discarded – undo
737 733
         $h = $this->having;
738 734
         $o = $this->order;
739 735
         $g = $this->group;
740
-        $j = array_map(function ($v) {
736
+        $j = array_map(function($v) {
741 737
             return clone $v;
742 738
         }, $this->joins);
743 739
 
@@ -748,47 +744,47 @@  discard block
 block discarded – undo
748 744
 
749 745
         foreach ($this->definition->getRelations() as $k => $relation) {
750 746
             foreach ($f as $kk => $field) {
751
-                if (strpos($field, $k . '.') === 0) {
752
-                    $relations[$k] = [ $relation, $table ];
753
-                    $f[$kk] = str_replace($k . '.', $getAlias($k) . '.', $field);
747
+                if (strpos($field, $k.'.') === 0) {
748
+                    $relations[$k] = [$relation, $table];
749
+                    $f[$kk] = str_replace($k.'.', $getAlias($k).'.', $field);
754 750
                 }
755 751
             }
756 752
             foreach ($w as $kk => $v) {
757
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) {
758
-                    $relations[$k] = [ $relation, $table ];
759
-                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $v[0]);
753
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) {
754
+                    $relations[$k] = [$relation, $table];
755
+                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $v[0]);
760 756
                 }
761 757
             }
762 758
             foreach ($h as $kk => $v) {
763
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) {
764
-                    $relations[$k] = [ $relation, $table ];
765
-                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $v[0]);
759
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) {
760
+                    $relations[$k] = [$relation, $table];
761
+                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $v[0]);
766 762
                 }
767 763
             }
768
-            if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) {
769
-                $relations[$k] = [ $relation, $table ];
770
-                $o[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $o[0]);
764
+            if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) {
765
+                $relations[$k] = [$relation, $table];
766
+                $o[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $o[0]);
771 767
             }
772
-            if (isset($g[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $g[0])) {
773
-                $relations[$k] = [ $relation, $table ];
774
-                $g[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $g[0]);
768
+            if (isset($g[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $g[0])) {
769
+                $relations[$k] = [$relation, $table];
770
+                $g[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $g[0]);
775 771
             }
776 772
             foreach ($j as $kk => $v) {
777 773
                 foreach ($v->keymap as $kkk => $vv) {
778
-                    if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv)) {
779
-                        $relations[$k] = [ $relation, $table ];
780
-                        $j[$k]->keymap[$kkk] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vv);
774
+                    if (preg_match('(\b'.preg_quote($k.'.').')i', $vv)) {
775
+                        $relations[$k] = [$relation, $table];
776
+                        $j[$k]->keymap[$kkk] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vv);
781 777
                     }
782 778
                 }
783 779
             }
784 780
         }
785 781
         $select = [];
786 782
         foreach ($f as $k => $field) {
787
-            $select[] = $field . (!is_numeric($k) ? ' ' . $k : '');
783
+            $select[] = $field.(!is_numeric($k) ? ' '.$k : '');
788 784
         }
789 785
         foreach ($this->withr as $name => $relation) {
790 786
             foreach ($relation[0]->table->getColumns() as $column) {
791
-                $select[] = $getAlias($name) . '.' . $column . ' ' . $getAlias($name . static::SEP . $column);
787
+                $select[] = $getAlias($name).'.'.$column.' '.$getAlias($name.static::SEP.$column);
792 788
             }
793 789
         }
794 790
         $sql = 'SELECT '.implode(', ', $select).' FROM '.$table.' ';
@@ -798,12 +794,12 @@  discard block
 block discarded – undo
798 794
             if ($v->many) {
799 795
                 $many = true;
800 796
             }
801
-            $sql .= ($v->many ? 'LEFT ' : '' ) . 'JOIN '.$v->table->getName().' '.$k.' ON ';
797
+            $sql .= ($v->many ? 'LEFT ' : '').'JOIN '.$v->table->getName().' '.$k.' ON ';
802 798
             $tmp = [];
803 799
             foreach ($v->keymap as $kk => $vv) {
804 800
                 $tmp[] = $kk.' = '.$vv;
805 801
             }
806
-            $sql .= implode(' AND ', $tmp) . ' ';
802
+            $sql .= implode(' AND ', $tmp).' ';
807 803
         }
808 804
         foreach ($relations as $relation => $v) {
809 805
             $table = $v[1] !== $this->definition->getName() ? $getAlias($v[1]) : $v[1];
@@ -818,13 +814,13 @@  discard block
 block discarded – undo
818 814
                 foreach ($v->keymap as $kk => $vv) {
819 815
                     $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' ';
820 816
                 }
821
-                $sql .= implode(' AND ', $tmp) . ' ';
817
+                $sql .= implode(' AND ', $tmp).' ';
822 818
                 $sql .= 'LEFT JOIN '.$v->table->getName().' '.$getAlias($relation).' ON ';
823 819
                 $tmp = [];
824 820
                 foreach ($v->pivot_keymap as $kk => $vv) {
825 821
                     $tmp[] = $getAlias($relation).'.'.$vv.' = '.$alias.'.'.$kk.' ';
826 822
                 }
827
-                $sql .= implode(' AND ', $tmp) . ' ';
823
+                $sql .= implode(' AND ', $tmp).' ';
828 824
             } else {
829 825
                 $alias = $getAlias($relation);
830 826
 
@@ -834,10 +830,10 @@  discard block
 block discarded – undo
834 830
                     $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' ';
835 831
                 }
836 832
                 if ($v->sql) {
837
-                    $tmp[] = $v->sql . ' ';
833
+                    $tmp[] = $v->sql.' ';
838 834
                     $par = array_merge($par, $v->par ?? []);
839 835
                 }
840
-                $sql .= implode(' AND ', $tmp) . ' ';
836
+                $sql .= implode(' AND ', $tmp).' ';
841 837
             }
842 838
         }
843 839
 
@@ -847,9 +843,9 @@  discard block
 block discarded – undo
847 843
                 if (count($porder) > 1) {
848 844
                     $pkw = [];
849 845
                     foreach ($porder as $name) {
850
-                        $pkw[] = $name . ' = ?';
846
+                        $pkw[] = $name.' = ?';
851 847
                     }
852
-                    $pkw = '(' . implode(' AND ', $pkw) . ')';
848
+                    $pkw = '('.implode(' AND ', $pkw).')';
853 849
                     $pkp = [];
854 850
                     foreach ($ids as $id) {
855 851
                         foreach ($id as $p) {
@@ -861,51 +857,51 @@  discard block
 block discarded – undo
861 857
                         $pkp
862 858
                     ];
863 859
                 } else {
864
-                    $w[] = [ $porder[0] . ' IN ('.implode(',', array_fill(0, count($ids), '?')).')', $ids ];
860
+                    $w[] = [$porder[0].' IN ('.implode(',', array_fill(0, count($ids), '?')).')', $ids];
865 861
                 }
866 862
             } else {
867
-                $w[] = [ '1=0', [] ];
863
+                $w[] = ['1=0', []];
868 864
             }
869 865
         }
870 866
         if (count($w)) {
871 867
             $sql .= 'WHERE ';
872 868
             $tmp = [];
873 869
             foreach ($w as $v) {
874
-                $tmp[] = '(' . $v[0] . ')';
870
+                $tmp[] = '('.$v[0].')';
875 871
                 $par = array_merge($par, $v[1]);
876 872
             }
877 873
             $sql .= implode(' AND ', $tmp).' ';
878 874
         }
879 875
         if (count($g)) {
880
-            $sql .= 'GROUP BY ' . $g[0] . ' ';
876
+            $sql .= 'GROUP BY '.$g[0].' ';
881 877
             $par = array_merge($par, $g[1]);
882 878
         }
883 879
         if (count($h)) {
884 880
             $sql .= 'HAVING ';
885 881
             $tmp = [];
886 882
             foreach ($h as $v) {
887
-                $tmp[] = '(' . $v[0] . ')';
883
+                $tmp[] = '('.$v[0].')';
888 884
                 $par = array_merge($par, $v[1]);
889 885
             }
890 886
             $sql .= implode(' AND ', $tmp).' ';
891 887
         }
892 888
         if (count($o)) {
893
-            $sql .= 'ORDER BY ' . $o[0] . ' ';
889
+            $sql .= 'ORDER BY '.$o[0].' ';
894 890
             $par = array_merge($par, $o[1]);
895 891
         }
896 892
         if (count($porder)) {
897 893
             $pdir = (count($o) && strpos($o[0], 'DESC') !== false) ? 'DESC' : 'ASC';
898
-            $porder = array_map(function ($v) use ($pdir) {
899
-                return $v . ' ' . $pdir;
894
+            $porder = array_map(function($v) use ($pdir) {
895
+                return $v.' '.$pdir;
900 896
             }, $porder);
901
-            $sql .= (count($o) ? ', ' : 'ORDER BY ') . implode(', ', $porder) . ' ';
897
+            $sql .= (count($o) ? ', ' : 'ORDER BY ').implode(', ', $porder).' ';
902 898
         }
903 899
         if ((!$many || $this->li_of[2] === 0 || !count($porder)) && $this->li_of[0]) {
904 900
             if ($this->db->driverName() === 'oracle') {
905
-                if ((int)$this->db->driverOption('version', 0) >= 12) {
906
-                    $sql .= 'OFFSET ' . $this->li_of[1] . ' ROWS FETCH NEXT ' . $this->li_of[0] . ' ROWS ONLY';
901
+                if ((int) $this->db->driverOption('version', 0) >= 12) {
902
+                    $sql .= 'OFFSET '.$this->li_of[1].' ROWS FETCH NEXT '.$this->li_of[0].' ROWS ONLY';
907 903
                 } else {
908
-                    $f = array_map(function ($v) {
904
+                    $f = array_map(function($v) {
909 905
                         $v = explode(' ', trim($v), 2);
910 906
                         if (count($v) === 2) {
911 907
                             return $v[1];
@@ -913,16 +909,16 @@  discard block
 block discarded – undo
913 909
                         $v = explode('.', $v[0], 2);
914 910
                         return count($v) === 2 ? $v[1] : $v[0];
915 911
                     }, $select);
916
-                    $sql = "SELECT " . implode(', ', $f) . " 
912
+                    $sql = "SELECT ".implode(', ', $f)." 
917 913
                             FROM (
918 914
                                 SELECT tbl__.*, rownum rnum__ FROM (
919
-                                    " . $sql . "
915
+                                    " . $sql."
920 916
                                 ) tbl__ 
921
-                                WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1]) . "
917
+                                WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1])."
922 918
                             ) WHERE rnum__ > " . $this->li_of[1];
923 919
                 }
924 920
             } else {
925
-                $sql .= 'LIMIT ' . $this->li_of[0] . ' OFFSET ' . $this->li_of[1];
921
+                $sql .= 'LIMIT '.$this->li_of[0].' OFFSET '.$this->li_of[1];
926 922
             }
927 923
         }
928 924
         return $this->qiterator = new TableQueryIterator(
@@ -972,8 +968,8 @@  discard block
 block discarded – undo
972 968
                 $ret[$k] = str_repeat(' ', 255);
973 969
                 $par[] = &$ret[$k];
974 970
             }
975
-            $sql .= ' RETURNING ' . implode(',', $primary) .
976
-                ' INTO ' . implode(',', array_fill(0, count($primary), '?'));
971
+            $sql .= ' RETURNING '.implode(',', $primary).
972
+                ' INTO '.implode(',', array_fill(0, count($primary), '?'));
977 973
             $this->db->query($sql, $par);
978 974
             return $ret;
979 975
         } else {
@@ -1005,9 +1001,9 @@  discard block
 block discarded – undo
1005 1001
         }
1006 1002
         $sql = 'UPDATE '.$table.' SET ';
1007 1003
         $par = [];
1008
-        $sql .= implode(', ', array_map(function ($v) {
1009
-            return $v . ' = ?';
1010
-        }, array_keys($update))) . ' ';
1004
+        $sql .= implode(', ', array_map(function($v) {
1005
+            return $v.' = ?';
1006
+        }, array_keys($update))).' ';
1011 1007
         $par = array_merge($par, array_values($update));
1012 1008
         if (count($this->where)) {
1013 1009
             $sql .= 'WHERE ';
@@ -1016,7 +1012,7 @@  discard block
 block discarded – undo
1016 1012
                 $tmp[] = $v[0];
1017 1013
                 $par = array_merge($par, $v[1]);
1018 1014
             }
1019
-            $sql .= implode(' AND ', $tmp) . ' ';
1015
+            $sql .= implode(' AND ', $tmp).' ';
1020 1016
         }
1021 1017
         if (count($this->order)) {
1022 1018
             $sql .= $this->order[0];
@@ -1040,7 +1036,7 @@  discard block
 block discarded – undo
1040 1036
                 $tmp[] = $v[0];
1041 1037
                 $par = array_merge($par, $v[1]);
1042 1038
             }
1043
-            $sql .= implode(' AND ', $tmp) . ' ';
1039
+            $sql .= implode(' AND ', $tmp).' ';
1044 1040
         }
1045 1041
         if (count($this->order)) {
1046 1042
             $sql .= $this->order[0];
@@ -1060,13 +1056,13 @@  discard block
 block discarded – undo
1060 1056
         $table = $this->definition;
1061 1057
         array_reduce(
1062 1058
             $parts,
1063
-            function ($carry, $item) use (&$table) {
1059
+            function($carry, $item) use (&$table) {
1064 1060
                 if (!$table->hasRelation($item)) {
1065 1061
                     throw new DBException('Invalid relation name');
1066 1062
                 }
1067 1063
                 $relation = $table->getRelation($item);
1068
-                $name = $carry ? $carry . static::SEP . $item : $item;
1069
-                $this->withr[$name] = [ $relation, $carry ?? $table->getName() ];
1064
+                $name = $carry ? $carry.static::SEP.$item : $item;
1065
+                $this->withr[$name] = [$relation, $carry ?? $table->getName()];
1070 1066
                 $table = $relation->table;
1071 1067
                 return $name;
1072 1068
             }
@@ -1111,9 +1107,9 @@  discard block
 block discarded – undo
1111 1107
         }
1112 1108
 
1113 1109
         $aliases = [];
1114
-        $getAlias = function ($name) use (&$aliases) {
1110
+        $getAlias = function($name) use (&$aliases) {
1115 1111
             // to bypass use: return $name;
1116
-            return $aliases[$name] = $aliases[$name] ?? 'alias' . static::SEP . count($aliases);
1112
+            return $aliases[$name] = $aliases[$name] ?? 'alias'.static::SEP.count($aliases);
1117 1113
         };
1118 1114
         
1119 1115
         $table = $this->definition->getName();
@@ -1125,70 +1121,70 @@  discard block
 block discarded – undo
1125 1121
         $h = $this->having;
1126 1122
         $o = $this->order;
1127 1123
         $g = $this->group;
1128
-        $j = array_map(function ($v) {
1124
+        $j = array_map(function($v) {
1129 1125
             return clone $v;
1130 1126
         }, $this->joins);
1131 1127
         foreach ($this->definition->getRelations() as $k => $v) {
1132 1128
             foreach ($w as $kk => $vv) {
1133
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv[0])) {
1134
-                    $relations[$k] = [ $v, $table ];
1135
-                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vv[0]);
1129
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $vv[0])) {
1130
+                    $relations[$k] = [$v, $table];
1131
+                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vv[0]);
1136 1132
                 }
1137 1133
             }
1138
-            if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) {
1139
-                $relations[$k] = [ $v, $table ];
1140
-                $o[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $o[0]);
1141
-                $o[2] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $o[2]);
1134
+            if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) {
1135
+                $relations[$k] = [$v, $table];
1136
+                $o[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $o[0]);
1137
+                $o[2] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $o[2]);
1142 1138
             }
1143 1139
             foreach ($h as $kk => $vv) {
1144
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv[0])) {
1145
-                    $relations[$k] = [ $v, $table ];
1146
-                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vv[0]);
1140
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $vv[0])) {
1141
+                    $relations[$k] = [$v, $table];
1142
+                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vv[0]);
1147 1143
                 }
1148 1144
             }
1149
-            if (isset($g[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $g[0])) {
1150
-                $relations[$k] = [ $v, $table ];
1151
-                $g[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $g[0]);
1145
+            if (isset($g[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $g[0])) {
1146
+                $relations[$k] = [$v, $table];
1147
+                $g[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $g[0]);
1152 1148
             }
1153 1149
             foreach ($j as $kk => $vv) {
1154 1150
                 foreach ($vv->keymap as $kkk => $vvv) {
1155
-                    if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vvv)) {
1156
-                        $relations[$k] = [ $v, $table ];
1151
+                    if (preg_match('(\b'.preg_quote($k.'.').')i', $vvv)) {
1152
+                        $relations[$k] = [$v, $table];
1157 1153
                         $j[$kk]->keymap[$kkk] =
1158
-                            preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vvv);
1154
+                            preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vvv);
1159 1155
                     }
1160 1156
                 }
1161 1157
             }
1162 1158
         }
1163 1159
 
1164
-        $key = array_map(function ($v) use ($table) {
1165
-            return $table . '.' . $v;
1160
+        $key = array_map(function($v) use ($table) {
1161
+            return $table.'.'.$v;
1166 1162
         }, $this->pkey);
1167 1163
         $own = false;
1168 1164
         $dir = 'ASC';
1169 1165
         if (count($o)) {
1170 1166
             $dir = strpos($o[0], ' DESC') ? 'DESC' : 'ASC';
1171
-            $own = strpos($o[2], $table . '.') === 0;
1167
+            $own = strpos($o[2], $table.'.') === 0;
1172 1168
         }
1173 1169
 
1174 1170
         $dst = $key;
1175 1171
         if ($own) {
1176 1172
             // if using own table - do not use max/min in order - that will prevent index usage
1177
-            $dst[] = $o[2] . ' orderbyfix___';
1173
+            $dst[] = $o[2].' orderbyfix___';
1178 1174
         } else {
1179
-            $dst[] = 'MAX(' . $o[2] . ') orderbyfix___';
1175
+            $dst[] = 'MAX('.$o[2].') orderbyfix___';
1180 1176
         }
1181 1177
         $dst = array_unique($dst);
1182 1178
 
1183 1179
         $par = [];
1184
-        $sql  = 'SELECT DISTINCT '.implode(', ', $dst).' FROM '.$table.' ';
1180
+        $sql = 'SELECT DISTINCT '.implode(', ', $dst).' FROM '.$table.' ';
1185 1181
         foreach ($j as $k => $v) {
1186
-            $sql .= ($v->many ? 'LEFT ' : '' ) . 'JOIN '.$v->table->getName().' '.$k.' ON ';
1182
+            $sql .= ($v->many ? 'LEFT ' : '').'JOIN '.$v->table->getName().' '.$k.' ON ';
1187 1183
             $tmp = [];
1188 1184
             foreach ($v->keymap as $kk => $vv) {
1189 1185
                 $tmp[] = $kk.' = '.$vv;
1190 1186
             }
1191
-            $sql .= implode(' AND ', $tmp) . ' ';
1187
+            $sql .= implode(' AND ', $tmp).' ';
1192 1188
         }
1193 1189
         foreach ($relations as $k => $v) {
1194 1190
             $table = $v[1] !== $this->definition->getName() ? $getAlias($v[1]) : $v[1];
@@ -1200,13 +1196,13 @@  discard block
 block discarded – undo
1200 1196
                 foreach ($v->keymap as $kk => $vv) {
1201 1197
                     $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' ';
1202 1198
                 }
1203
-                $sql .= implode(' AND ', $tmp) . ' ';
1199
+                $sql .= implode(' AND ', $tmp).' ';
1204 1200
                 $sql .= 'LEFT JOIN '.$v->table->getName().' '.$getAlias($k).' ON ';
1205 1201
                 $tmp = [];
1206 1202
                 foreach ($v->pivot_keymap as $kk => $vv) {
1207 1203
                     $tmp[] = $getAlias($k).'.'.$vv.' = '.$alias.'.'.$kk.' ';
1208 1204
                 }
1209
-                $sql .= implode(' AND ', $tmp) . ' ';
1205
+                $sql .= implode(' AND ', $tmp).' ';
1210 1206
             } else {
1211 1207
                 $alias = $getAlias($k);
1212 1208
                 $sql .= 'LEFT JOIN '.$v->table->getName().' '.$alias.' ON ';
@@ -1215,29 +1211,29 @@  discard block
 block discarded – undo
1215 1211
                     $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' ';
1216 1212
                 }
1217 1213
                 if ($v->sql) {
1218
-                    $tmp[] = $v->sql . ' ';
1214
+                    $tmp[] = $v->sql.' ';
1219 1215
                     $par = array_merge($par, $v->par ?? []);
1220 1216
                 }
1221
-                $sql .= implode(' AND ', $tmp) . ' ';
1217
+                $sql .= implode(' AND ', $tmp).' ';
1222 1218
             }
1223 1219
         }
1224 1220
         if (count($w)) {
1225 1221
             $sql .= 'WHERE ';
1226 1222
             $tmp = [];
1227 1223
             foreach ($w as $v) {
1228
-                $tmp[] = '(' . $v[0] . ')';
1224
+                $tmp[] = '('.$v[0].')';
1229 1225
                 $par = array_merge($par, $v[1]);
1230 1226
             }
1231 1227
             $sql .= implode(' AND ', $tmp).' ';
1232 1228
         }
1233 1229
         if (!$own) {
1234
-            $sql .= 'GROUP BY ' . implode(', ', $key) . ' ';
1230
+            $sql .= 'GROUP BY '.implode(', ', $key).' ';
1235 1231
         }
1236 1232
         if (count($h)) {
1237 1233
             $sql .= 'HAVING ';
1238 1234
             $tmp = [];
1239 1235
             foreach ($h as $v) {
1240
-                $tmp[] = '(' . $v[0] . ')';
1236
+                $tmp[] = '('.$v[0].')';
1241 1237
                 $par = array_merge($par, $v[1]);
1242 1238
             }
1243 1239
             $sql .= implode(' AND ', $tmp).' ';
@@ -1245,38 +1241,38 @@  discard block
 block discarded – undo
1245 1241
         if (count($o)) {
1246 1242
             $sql .= 'ORDER BY ';
1247 1243
             if ($own) {
1248
-                $sql .= $o[2] . ' ' . $dir;
1244
+                $sql .= $o[2].' '.$dir;
1249 1245
             } else {
1250
-                $sql .= 'MAX('.$o[2].') ' . $dir;
1246
+                $sql .= 'MAX('.$o[2].') '.$dir;
1251 1247
             }
1252 1248
         }
1253 1249
         $porder = [];
1254 1250
         $pdir = (count($o) && strpos($o[0], 'DESC') !== false) ? 'DESC' : 'ASC';
1255 1251
         foreach ($this->definition->getPrimaryKey() as $field) {
1256
-            $porder[] = $this->getColumn($field)['name'] . ' ' . $pdir;
1252
+            $porder[] = $this->getColumn($field)['name'].' '.$pdir;
1257 1253
         }
1258 1254
         if (count($porder)) {
1259
-            $sql .= (count($o) ? ', ' : 'ORDER BY ') . implode(', ', $porder) . ' ';
1255
+            $sql .= (count($o) ? ', ' : 'ORDER BY ').implode(', ', $porder).' ';
1260 1256
         }
1261 1257
 
1262 1258
         if ($this->li_of[0]) {
1263 1259
             if ($this->db->driverName() === 'oracle') {
1264
-                if ((int)$this->db->driverOption('version', 0) >= 12) {
1265
-                    $sql .= 'OFFSET ' . $this->li_of[1] . ' ROWS FETCH NEXT ' . $this->li_of[0] . ' ROWS ONLY';
1260
+                if ((int) $this->db->driverOption('version', 0) >= 12) {
1261
+                    $sql .= 'OFFSET '.$this->li_of[1].' ROWS FETCH NEXT '.$this->li_of[0].' ROWS ONLY';
1266 1262
                 } else {
1267
-                    $sql = "SELECT " . implode(', ', $dst) . " 
1263
+                    $sql = "SELECT ".implode(', ', $dst)." 
1268 1264
                             FROM (
1269 1265
                                 SELECT tbl__.*, rownum rnum__ FROM (
1270
-                                    " . $sql . "
1266
+                                    " . $sql."
1271 1267
                                 ) tbl__ 
1272
-                                WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1]) . "
1268
+                                WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1])."
1273 1269
                             ) WHERE rnum__ > " . $this->li_of[1];
1274 1270
                 }
1275 1271
             } else {
1276
-                $sql .= 'LIMIT ' . $this->li_of[0] . ' OFFSET ' . $this->li_of[1];
1272
+                $sql .= 'LIMIT '.$this->li_of[0].' OFFSET '.$this->li_of[1];
1277 1273
             }
1278 1274
         }
1279
-        return array_map(function ($v) {
1275
+        return array_map(function($v) {
1280 1276
             if (isset($v['orderbyfix___'])) {
1281 1277
                 unset($v['orderbyfix___']);
1282 1278
             }
Please login to merge, or discard this patch.