Completed
Push — master ( 00f534...a38610 )
by Ivan
12:17
created
src/schema/Table.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
     public function setPrimaryKey($column) : Table
83 83
     {
84 84
         if (!is_array($column)) {
85
-            $column = [ $column ];
85
+            $column = [$column];
86 86
         }
87 87
         $this->data['primary'] = $column;
88 88
         return $this;
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
      */
110 110
     public function getFullName()
111 111
     {
112
-        return ($this->data['schema'] ? $this->data['schema'] . '.' : '') . $this->data['name'];
112
+        return ($this->data['schema'] ? $this->data['schema'].'.' : '').$this->data['name'];
113 113
     }
114 114
     /**
115 115
      * Get a column definition
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
         }
185 185
 
186 186
         if (!isset($name)) {
187
-            $name = $toTable->getName() . '_' . implode('_', array_keys($keymap));
187
+            $name = $toTable->getName().'_'.implode('_', array_keys($keymap));
188 188
         }
189 189
         $this->addRelation(new TableRelation(
190 190
             $name,
Please login to merge, or discard this patch.
src/driver/postgre/Schema.php 1 patch
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -29,8 +29,8 @@  discard block
 block discarded – undo
29 29
             $table = $temp[1];
30 30
         }
31 31
 
32
-        if (isset($tables[$schema . '.' . $table])) {
33
-            return $tables[$schema . '.' . $table];
32
+        if (isset($tables[$schema.'.'.$table])) {
33
+            return $tables[$schema.'.'.$table];
34 34
         }
35 35
 
36 36
         static $relationsT = null;
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
                         (kc.table_schema = ? OR ct.table_schema = ?) AND
62 62
                         kc.table_name IS NOT NULL AND
63 63
                         kc.position_in_unique_constraint IS NOT NULL",
64
-                    [ $catalog, $main, $main ]
64
+                    [$catalog, $main, $main]
65 65
                 )
66 66
             )->toArray();
67 67
             foreach ($col as $row) {
@@ -71,8 +71,8 @@  discard block
 block discarded – undo
71 71
                 if ($row['referenced_table_schema'] !== $main) {
72 72
                     $additional[] = $row['referenced_table_schema'];
73 73
                 }
74
-                $relationsT[$row['table_schema'] . '.' . $row['table_name']][] = $row;
75
-                $relationsR[$row['referenced_table_schema'] . '.' . $row['referenced_table_name']][] = $row;
74
+                $relationsT[$row['table_schema'].'.'.$row['table_name']][] = $row;
75
+                $relationsR[$row['referenced_table_schema'].'.'.$row['referenced_table_name']][] = $row;
76 76
             }
77 77
             foreach (array_filter(array_unique($additional)) as $s) {
78 78
                 $col = Collection::from(
@@ -97,12 +97,12 @@  discard block
 block discarded – undo
97 97
                             (kc.table_schema = ? AND ct.table_schema = ?) AND
98 98
                             kc.table_name IS NOT NULL AND
99 99
                             kc.position_in_unique_constraint IS NOT NULL",
100
-                        [ $catalog, $s, $s ]
100
+                        [$catalog, $s, $s]
101 101
                     )
102 102
                 )->toArray();
103 103
                 foreach ($col as $row) {
104
-                    $relationsT[$row['table_schema'] . '.' . $row['table_name']][] = $row;
105
-                    $relationsR[$row['referenced_table_schema'] . '.' . $row['referenced_table_name']][] = $row;
104
+                    $relationsT[$row['table_schema'].'.'.$row['table_name']][] = $row;
105
+                    $relationsR[$row['referenced_table_schema'].'.'.$row['referenced_table_name']][] = $row;
106 106
                 }
107 107
             }
108 108
         }
@@ -110,12 +110,12 @@  discard block
 block discarded – undo
110 110
         $columns = Collection::from($this
111 111
             ->query(
112 112
                 "SELECT * FROM information_schema.columns WHERE table_name = ? AND table_schema = ? AND table_catalog = ?",
113
-                [ $table, $schema, $catalog ]
113
+                [$table, $schema, $catalog]
114 114
             ))
115
-            ->mapKey(function ($v) {
115
+            ->mapKey(function($v) {
116 116
                 return $v['column_name'];
117 117
             })
118
-            ->map(function ($v) {
118
+            ->map(function($v) {
119 119
                 $v['length'] = null;
120 120
                 if (!isset($v['data_type'])) {
121 121
                     return $v;
@@ -123,20 +123,20 @@  discard block
 block discarded – undo
123 123
                 switch ($v['data_type']) {
124 124
                     case 'character':
125 125
                     case 'character varying':
126
-                        $v['length'] = (int)$v['character_maximum_length'];
126
+                        $v['length'] = (int) $v['character_maximum_length'];
127 127
                         break;
128 128
                 }
129 129
                 return $v;
130 130
             })
131 131
             ->toArray();
132 132
         if (!count($columns)) {
133
-            throw new DBException('Table not found by name: ' . implode('.', [$schema,$table]));
133
+            throw new DBException('Table not found by name: '.implode('.', [$schema, $table]));
134 134
         }
135 135
         $pkname = Collection::from($this
136 136
             ->query(
137 137
                 "SELECT constraint_name FROM information_schema.table_constraints
138 138
                 WHERE table_name = ? AND constraint_type = ? AND table_schema = ? AND table_catalog = ?",
139
-                [ $table, 'PRIMARY KEY', $schema, $catalog ]
139
+                [$table, 'PRIMARY KEY', $schema, $catalog]
140 140
             ))
141 141
             ->pluck('constraint_name')
142 142
             ->value();
@@ -146,12 +146,12 @@  discard block
 block discarded – undo
146 146
                 ->query(
147 147
                     "SELECT column_name FROM information_schema.constraint_column_usage
148 148
                      WHERE table_name = ? AND constraint_name = ? AND table_schema = ? AND table_catalog = ?",
149
-                    [ $table, $pkname, $schema, $catalog ]
149
+                    [$table, $pkname, $schema, $catalog]
150 150
                 ))
151 151
                 ->pluck('column_name')
152 152
                 ->toArray();
153 153
         }
154
-        $tables[$schema . '.' .$table] = $definition = (new Table($table, $schema))
154
+        $tables[$schema.'.'.$table] = $definition = (new Table($table, $schema))
155 155
             ->addColumns($columns)
156 156
             ->setPrimaryKey($primary)
157 157
             ->setComment('');
@@ -161,8 +161,8 @@  discard block
 block discarded – undo
161 161
             // assuming current table is on the "one" end having "many" records in the referencing table
162 162
             // resulting in a "hasMany" or "manyToMany" relationship (if a pivot table is detected)
163 163
             $relations = [];
164
-            foreach ($relationsR[$schema . '.' . $table] ?? [] as $relation) {
165
-                $relations[$relation['constraint_name']]['table'] = $relation['table_schema'] . '.' . $relation['table_name'];
164
+            foreach ($relationsR[$schema.'.'.$table] ?? [] as $relation) {
165
+                $relations[$relation['constraint_name']]['table'] = $relation['table_schema'].'.'.$relation['table_name'];
166 166
                 $relations[$relation['constraint_name']]['keymap'][$relation['referenced_column_name']] =
167 167
                     $relation['column_name'];
168 168
             }
@@ -178,11 +178,11 @@  discard block
 block discarded – undo
178 178
                 $usedcol = [];
179 179
                 if (count($columns)) {
180 180
                     foreach (Collection::from($relationsT[$data['table']] ?? [])
181
-                        ->filter(function ($v) use ($columns) {
181
+                        ->filter(function($v) use ($columns) {
182 182
                             return in_array($v['column_name'], $columns);
183 183
                         }) as $relation
184 184
                     ) {
185
-                        $foreign[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'] . '.' . $relation['referenced_table_name'];
185
+                        $foreign[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'].'.'.$relation['referenced_table_name'];
186 186
                         $foreign[$relation['constraint_name']]['keymap'][$relation['column_name']] =
187 187
                             $relation['referenced_column_name'];
188 188
                         $usedcol[] = $relation['column_name'];
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
                     $orig = $relname;
199 199
                     $cntr = 1;
200 200
                     while ($definition->hasRelation($relname) || $definition->getName() == $relname) {
201
-                        $relname = $orig . '_' . (++ $cntr);
201
+                        $relname = $orig.'_'.(++$cntr);
202 202
                     }
203 203
                     $definition->addRelation(
204 204
                         new TableRelation(
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
                     $orig = $relname;
220 220
                     $cntr = 1;
221 221
                     while ($definition->hasRelation($relname) || $definition->getName() == $relname) {
222
-                        $relname = $orig . '_' . (++ $cntr);
222
+                        $relname = $orig.'_'.(++$cntr);
223 223
                     }
224 224
                     $definition->addRelation(
225 225
                         new TableRelation(
@@ -235,8 +235,8 @@  discard block
 block discarded – undo
235 235
             // assuming current table is linked to "one" record in the referenced table
236 236
             // resulting in a "belongsTo" relationship
237 237
             $relations = [];
238
-            foreach ($relationsT[$schema . '.' . $table] ?? [] as $relation) {
239
-                $relations[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'] . '.' . $relation['referenced_table_name'];
238
+            foreach ($relationsT[$schema.'.'.$table] ?? [] as $relation) {
239
+                $relations[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'].'.'.$relation['referenced_table_name'];
240 240
                 $relations[$relation['constraint_name']]['keymap'][$relation['column_name']] =
241 241
                     $relation['referenced_column_name'];
242 242
             }
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
                 $orig = $relname;
250 250
                 $cntr = 1;
251 251
                 while ($definition->hasRelation($relname) || $definition->getName() == $relname) {
252
-                    $relname = $orig . '_' . (++ $cntr);
252
+                    $relname = $orig.'_'.(++$cntr);
253 253
                 }
254 254
                 $definition->addRelation(
255 255
                     new TableRelation(
@@ -268,10 +268,10 @@  discard block
 block discarded – undo
268 268
         return Collection::from($this
269 269
             ->query(
270 270
                 "SELECT table_name FROM information_schema.tables where table_schema = ? AND table_catalog = ?",
271
-                [ $this->connection['opts']['schema'] ?? 'public', $this->connection['name'] ]
271
+                [$this->connection['opts']['schema'] ?? 'public', $this->connection['name']]
272 272
             ))
273 273
             ->pluck('table_name')
274
-            ->map(function ($v) {
274
+            ->map(function($v) {
275 275
                 return $this->table($v);
276 276
             })
277 277
             ->toArray();
Please login to merge, or discard this patch.
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(string $sequence = null)
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/driver/postgre/Result.php 1 patch
Spacing   +2 added lines, -3 removed lines patch added patch discarded remove patch
@@ -36,8 +36,7 @@  discard block
 block discarded – undo
36 36
             $temp = @\pg_query(
37 37
                 $this->driver,
38 38
                 $sequence ?
39
-                    'SELECT currval('.@\pg_escape_string($this->driver, $sequence).')' :
40
-                    'SELECT lastval()'
39
+                    'SELECT currval('.@\pg_escape_string($this->driver, $sequence).')' : 'SELECT lastval()'
41 40
             );
42 41
             if ($temp) {
43 42
                 $res = \pg_fetch_row($temp);
@@ -75,7 +74,7 @@  discard block
 block discarded – undo
75 74
     }
76 75
     public function next()
77 76
     {
78
-        $this->fetched ++;
77
+        $this->fetched++;
79 78
         $this->last = \pg_fetch_array($this->statement, null, \PGSQL_ASSOC);
80 79
     }
81 80
     public function valid()
Please login to merge, or discard this patch.
src/schema/TableQuery.php 1 patch
Spacing   +187 added lines, -191 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->getFullName(), $column[0] ];
100
+            $column = [$this->definition->getFullName(), $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 {
@@ -128,26 +128,26 @@  discard block
 block discarded – undo
128 128
             if ($this->definition->hasRelation(implode('.', $column))) {
129 129
                 $this->with(implode('.', $column));
130 130
                 $col = $this->definition->getRelation(implode('.', $column))->table->getColumn($name);
131
-                $column = [ implode('.', $column), $name ];
131
+                $column = [implode('.', $column), $name];
132 132
             } else {
133 133
                 $this->with(implode('.', $column));
134 134
                 $table = $this->definition;
135 135
                 $table = array_reduce(
136 136
                     $column,
137
-                    function ($carry, $item) use (&$table) {
137
+                    function($carry, $item) use (&$table) {
138 138
                         $table = $table->getRelation($item)->table;
139 139
                         return $table;
140 140
                     }
141 141
                 );
142 142
                 $col = $table->getColumn($name);
143
-                $column = [ implode(static::SEP, $column), $name ];
143
+                $column = [implode(static::SEP, $column), $name];
144 144
             }
145 145
         }
146
-        return [ 'name' => implode('.', $column), 'data' => $col ];
146
+        return ['name' => implode('.', $column), 'data' => $col];
147 147
     }
148 148
     protected function normalizeValue(TableColumn $col, $value)
149 149
     {
150
-        $strict = (int)$this->db->driverOption('strict', 0) > 0;
150
+        $strict = (int) $this->db->driverOption('strict', 0) > 0;
151 151
         if ($value === null && $col->isNullable()) {
152 152
             return null;
153 153
         }
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
                     $temp = strtotime($value);
158 158
                     if (!$temp) {
159 159
                         if ($strict) {
160
-                            throw new DBException('Invalid value for date column ' . $col->getName());
160
+                            throw new DBException('Invalid value for date column '.$col->getName());
161 161
                         }
162 162
                         return null;
163 163
                     }
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
                     return $value->format('Y-m-d');
171 171
                 }
172 172
                 if ($strict) {
173
-                    throw new DBException('Invalid value (unknown data type) for date column ' . $col->getName());
173
+                    throw new DBException('Invalid value (unknown data type) for date column '.$col->getName());
174 174
                 }
175 175
                 return $value;
176 176
             case 'datetime':
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
                     $temp = strtotime($value);
179 179
                     if (!$temp) {
180 180
                         if ($strict) {
181
-                            throw new DBException('Invalid value for datetime column ' . $col->getName());
181
+                            throw new DBException('Invalid value for datetime column '.$col->getName());
182 182
                         }
183 183
                         return null;
184 184
                     }
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
                     return $value->format('Y-m-d H:i:s');
192 192
                 }
193 193
                 if ($strict) {
194
-                    throw new DBException('Invalid value (unknown data type) for datetime column ' . $col->getName());
194
+                    throw new DBException('Invalid value (unknown data type) for datetime column '.$col->getName());
195 195
                 }
196 196
                 return $value;
197 197
             case 'enum':
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
                 if (is_int($value)) {
200 200
                     if (!isset($values[$value])) {
201 201
                         if ($strict) {
202
-                            throw new DBException('Invalid value (using integer) for enum ' . $col->getName());
202
+                            throw new DBException('Invalid value (using integer) for enum '.$col->getName());
203 203
                         }
204 204
                         return $value;
205 205
                     }
@@ -207,23 +207,23 @@  discard block
 block discarded – undo
207 207
                 }
208 208
                 if (!in_array($value, $col->getValues())) {
209 209
                     if ($strict) {
210
-                        throw new DBException('Invalid value for enum ' . $col->getName());
210
+                        throw new DBException('Invalid value for enum '.$col->getName());
211 211
                     }
212 212
                     return 0;
213 213
                 }
214 214
                 return $value;
215 215
             case 'int':
216 216
                 $temp = preg_replace('([^+\-0-9]+)', '', $value);
217
-                return is_string($temp) ? (int)$temp : 0;
217
+                return is_string($temp) ? (int) $temp : 0;
218 218
             case 'float':
219 219
                 $temp = preg_replace('([^+\-0-9.]+)', '', str_replace(',', '.', $value));
220
-                return is_string($temp) ? (float)$temp : 0;
220
+                return is_string($temp) ? (float) $temp : 0;
221 221
             case 'text':
222 222
                 // check using strlen first, in order to avoid hitting mb_ functions which might be polyfilled
223 223
                 // because the polyfill is quite slow
224 224
                 if ($col->hasLength() && strlen($value) > $col->getLength() && mb_strlen($value) > $col->getLength()) {
225 225
                     if ($strict) {
226
-                        throw new DBException('Invalid value for text column ' . $col->getName());
226
+                        throw new DBException('Invalid value for text column '.$col->getName());
227 227
                     }
228 228
                     return mb_substr($value, 0, $col->getLength());
229 229
                 }
@@ -245,35 +245,32 @@  discard block
 block discarded – undo
245 245
             // str_replace(['%', '_'], ['\\%','\\_'], $q)
246 246
             return $negate ?
247 247
                 [
248
-                    $name . ' NOT LIKE ?',
249
-                    [ $this->normalizeValue($column, $value) ]
250
-                ] :
251
-                [
252
-                    $name . ' LIKE ?',
253
-                    [ $this->normalizeValue($column, $value) ]
248
+                    $name.' NOT LIKE ?',
249
+                    [$this->normalizeValue($column, $value)]
250
+                ] : [
251
+                    $name.' LIKE ?',
252
+                    [$this->normalizeValue($column, $value)]
254 253
                 ];
255 254
         }
256 255
         if (is_null($value)) {
257 256
             return $negate ?
258
-                [ $name . ' IS NOT NULL', [] ]:
259
-                [ $name . ' IS NULL', [] ];
257
+                [$name.' IS NOT NULL', []] : [$name.' IS NULL', []];
260 258
         }
261 259
         if (!is_array($value)) {
262 260
             return $negate ?
263 261
                 [
264
-                    $name . ' <> ?',
265
-                    [ $this->normalizeValue($column, $value) ]
266
-                ] :
267
-                [
268
-                    $name . ' = ?',
269
-                    [ $this->normalizeValue($column, $value) ]
262
+                    $name.' <> ?',
263
+                    [$this->normalizeValue($column, $value)]
264
+                ] : [
265
+                    $name.' = ?',
266
+                    [$this->normalizeValue($column, $value)]
270 267
                 ];
271 268
         }
272 269
         if (isset($value['beg']) && strlen($value['beg']) && (!isset($value['end']) || !strlen($value['end']))) {
273
-            $value = [ 'gte' => $value['beg'] ];
270
+            $value = ['gte' => $value['beg']];
274 271
         }
275 272
         if (isset($value['end']) && strlen($value['end']) && (!isset($value['beg']) || !strlen($value['beg']))) {
276
-            $value = [ 'lte' => $value['end'] ];
273
+            $value = ['lte' => $value['end']];
277 274
         }
278 275
         if (isset($value['beg']) && isset($value['end'])) {
279 276
             return $negate ?
@@ -283,8 +280,7 @@  discard block
 block discarded – undo
283 280
                         $this->normalizeValue($column, $value['beg']),
284 281
                         $this->normalizeValue($column, $value['end'])
285 282
                     ]
286
-                ] :
287
-                [
283
+                ] : [
288 284
                     $name.' BETWEEN ? AND ?',
289 285
                     [
290 286
                         $this->normalizeValue($column, $value['beg']),
@@ -296,42 +292,42 @@  discard block
 block discarded – undo
296 292
             $sql = [];
297 293
             $par = [];
298 294
             if (isset($value['gt'])) {
299
-                $sql[] = $name. ' ' . ($negate ? '<=' : '>') . ' ?';
295
+                $sql[] = $name.' '.($negate ? '<=' : '>').' ?';
300 296
                 $par[] = $this->normalizeValue($column, $value['gt']);
301 297
             }
302 298
             if (isset($value['gte'])) {
303
-                $sql[] = $name. ' ' . ($negate ? '<' : '>=') . ' ?';
299
+                $sql[] = $name.' '.($negate ? '<' : '>=').' ?';
304 300
                 $par[] = $this->normalizeValue($column, $value['gte']);
305 301
             }
306 302
             if (isset($value['lt'])) {
307
-                $sql[] = $name. ' ' . ($negate ? '>=' : '<') . ' ?';
303
+                $sql[] = $name.' '.($negate ? '>=' : '<').' ?';
308 304
                 $par[] = $this->normalizeValue($column, $value['lt']);
309 305
             }
310 306
             if (isset($value['lte'])) {
311
-                $sql[] = $name. ' ' . ($negate ? '>' : '<=') . ' ?';
307
+                $sql[] = $name.' '.($negate ? '>' : '<=').' ?';
312 308
                 $par[] = $this->normalizeValue($column, $value['lte']);
313 309
             }
314 310
             return [
315
-                '(' . implode(' AND ', $sql) . ')',
311
+                '('.implode(' AND ', $sql).')',
316 312
                 $par
317 313
             ];
318 314
         }
319 315
 
320
-        $value = array_values(array_map(function ($v) use ($column) {
316
+        $value = array_values(array_map(function($v) use ($column) {
321 317
             return $this->normalizeValue($column, $v);
322 318
         }, $value));
323 319
         if ($this->db->driverName() === 'oracle') {
324 320
             $sql = [];
325 321
             $par = [];
326 322
             for ($i = 0; $i < count($value); $i += 500) {
327
-                $sql[] = $negate ? $name . ' NOT IN (??)' : $name . ' IN (??)';
323
+                $sql[] = $negate ? $name.' NOT IN (??)' : $name.' IN (??)';
328 324
                 $par[] = array_slice($value, $i, 500);
329 325
             }
330
-            $sql = '(' . implode($negate ? ' AND ' : ' OR ', $sql) . ')';
331
-            return [ $sql, [$par] ];
326
+            $sql = '('.implode($negate ? ' AND ' : ' OR ', $sql).')';
327
+            return [$sql, [$par]];
332 328
         }
333 329
         return [
334
-            $negate ? $name . ' NOT IN (??)' : $name . ' IN (??)',
330
+            $negate ? $name.' NOT IN (??)' : $name.' IN (??)',
335 331
             [$value]
336 332
         ];
337 333
     }
@@ -363,7 +359,7 @@  discard block
 block discarded – undo
363 359
                 $par = array_merge($par, $temp[1]);
364 360
             }
365 361
         }
366
-        return $this->where('(' . implode(' OR ', $sql) . ')', $par);
362
+        return $this->where('('.implode(' OR ', $sql).')', $par);
367 363
     }
368 364
     /**
369 365
      * Filter the results matching all of the criteria
@@ -381,7 +377,7 @@  discard block
 block discarded – undo
381 377
                 $par = array_merge($par, $temp[1]);
382 378
             }
383 379
         }
384
-        return $this->where('(' . implode(' AND ', $sql) . ')', $par);
380
+        return $this->where('('.implode(' AND ', $sql).')', $par);
385 381
     }
386 382
     /**
387 383
      * Sort by a column
@@ -391,7 +387,7 @@  discard block
 block discarded – undo
391 387
      */
392 388
     public function sort(string $column, bool $desc = false) : self
393 389
     {
394
-        return $this->order($this->getColumn($column)['name'] . ' ' . ($desc ? 'DESC' : 'ASC'));
390
+        return $this->order($this->getColumn($column)['name'].' '.($desc ? 'DESC' : 'ASC'));
395 391
     }
396 392
     /**
397 393
      * Group by a column (or columns)
@@ -401,7 +397,7 @@  discard block
 block discarded – undo
401 397
     public function group($column) : self
402 398
     {
403 399
         if (!is_array($column)) {
404
-            $column = [ $column ];
400
+            $column = [$column];
405 401
         }
406 402
         foreach ($column as $k => $v) {
407 403
             $column[$k] = $this->getColumn($v)['name'];
@@ -443,7 +439,7 @@  discard block
 block discarded – undo
443 439
         $this->order = [];
444 440
         $this->having = [];
445 441
         $this->aliases = [];
446
-        $this->li_of = [0,0,0];
442
+        $this->li_of = [0, 0, 0];
447 443
         $this->qiterator = null;
448 444
         return $this;
449 445
     }
@@ -456,7 +452,7 @@  discard block
 block discarded – undo
456 452
     public function groupBy(string $sql, array $params = []) : self
457 453
     {
458 454
         $this->qiterator = null;
459
-        $this->group = [ $sql, $params ];
455
+        $this->group = [$sql, $params];
460 456
         return $this;
461 457
     }
462 458
     /**
@@ -469,7 +465,7 @@  discard block
 block discarded – undo
469 465
      */
470 466
     public function join($table, array $fields, string $name = null, bool $multiple = true)
471 467
     {
472
-        $table = $table instanceof Table ? $table : $this->db->definition((string)$table);
468
+        $table = $table instanceof Table ? $table : $this->db->definition((string) $table);
473 469
         $name = $name ?? $table->getName();
474 470
         if (isset($this->joins[$name]) || $this->definition->hasRelation($name)) {
475 471
             throw new DBException('Alias / table name already in use');
@@ -478,7 +474,7 @@  discard block
 block discarded – undo
478 474
         foreach ($fields as $k => $v) {
479 475
             $k = explode('.', $k, 2);
480 476
             $k = count($k) == 2 ? $k[1] : $k[0];
481
-            $this->joins[$name]->keymap[$this->getColumn($name . '.' . $k)['name']] = $this->getColumn($v)['name'];
477
+            $this->joins[$name]->keymap[$this->getColumn($name.'.'.$k)['name']] = $this->getColumn($v)['name'];
482 478
         }
483 479
         return $this;
484 480
     }
@@ -491,7 +487,7 @@  discard block
 block discarded – undo
491 487
     public function where(string $sql, array $params = []) : self
492 488
     {
493 489
         $this->qiterator = null;
494
-        $this->where[] = [ $sql, $params ];
490
+        $this->where[] = [$sql, $params];
495 491
         return $this;
496 492
     }
497 493
     /**
@@ -503,7 +499,7 @@  discard block
 block discarded – undo
503 499
     public function having(string $sql, array $params = []) : self
504 500
     {
505 501
         $this->qiterator = null;
506
-        $this->having[] = [ $sql, $params ];
502
+        $this->having[] = [$sql, $params];
507 503
         return $this;
508 504
     }
509 505
     /**
@@ -527,7 +523,7 @@  discard block
 block discarded – undo
527 523
                 $name = null;
528 524
             }
529 525
         }
530
-        $this->order = [ $sql, $params, $name ];
526
+        $this->order = [$sql, $params, $name];
531 527
         return $this;
532 528
     }
533 529
     /**
@@ -539,7 +535,7 @@  discard block
 block discarded – undo
539 535
     public function limit(int $limit, int $offset = 0, bool $limitOnMainTable = false) : self
540 536
     {
541 537
         $this->qiterator = null;
542
-        $this->li_of = [ $limit, $offset, $limitOnMainTable ? 1 : 0 ];
538
+        $this->li_of = [$limit, $offset, $limitOnMainTable ? 1 : 0];
543 539
         return $this;
544 540
     }
545 541
     /**
@@ -549,9 +545,9 @@  discard block
 block discarded – undo
549 545
     public function count() : int
550 546
     {
551 547
         $aliases = [];
552
-        $getAlias = function ($name) use (&$aliases) {
548
+        $getAlias = function($name) use (&$aliases) {
553 549
             // to bypass use: return $name;
554
-            return $aliases[$name] = $aliases[$name] ?? 'alias' . static::SEP . count($aliases);
550
+            return $aliases[$name] = $aliases[$name] ?? 'alias'.static::SEP.count($aliases);
555 551
         };
556 552
         $table = $this->definition->getFullName();
557 553
         $sql = 'SELECT COUNT(DISTINCT '.$table.'.'.implode(', '.$table.'.', $this->pkey).') FROM '.$table.' ';
@@ -565,35 +561,35 @@  discard block
 block discarded – undo
565 561
         $h = $this->having;
566 562
         $o = $this->order;
567 563
         $g = $this->group;
568
-        $j = array_map(function ($v) {
564
+        $j = array_map(function($v) {
569 565
             return clone $v;
570 566
         }, $this->joins);
571 567
         foreach ($this->definition->getRelations() as $k => $v) {
572 568
             foreach ($w as $kk => $vv) {
573
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv[0])) {
574
-                    $relations[$k] = [ $v, $table ];
575
-                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vv[0]);
569
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $vv[0])) {
570
+                    $relations[$k] = [$v, $table];
571
+                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vv[0]);
576 572
                 }
577 573
             }
578
-            if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) {
579
-                $relations[$k] = [ $v, $table ];
574
+            if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) {
575
+                $relations[$k] = [$v, $table];
580 576
             }
581 577
             foreach ($h as $kk => $vv) {
582
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv[0])) {
583
-                    $relations[$k] = [ $v, $table ];
584
-                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vv[0]);
578
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $vv[0])) {
579
+                    $relations[$k] = [$v, $table];
580
+                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vv[0]);
585 581
                 }
586 582
             }
587
-            if (isset($g[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $g[0])) {
588
-                $relations[$k] = [ $v, $table ];
589
-                $g[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $g[0]);
583
+            if (isset($g[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $g[0])) {
584
+                $relations[$k] = [$v, $table];
585
+                $g[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $g[0]);
590 586
             }
591 587
             foreach ($j as $kk => $vv) {
592 588
                 foreach ($vv->keymap as $kkk => $vvv) {
593
-                    if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vvv)) {
594
-                        $relations[$k] = [ $v, $table ];
589
+                    if (preg_match('(\b'.preg_quote($k.'.').')i', $vvv)) {
590
+                        $relations[$k] = [$v, $table];
595 591
                         $j[$kk]->keymap[$kkk] =
596
-                            preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vvv);
592
+                            preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vvv);
597 593
                     }
598 594
                 }
599 595
             }
@@ -609,13 +605,13 @@  discard block
 block discarded – undo
609 605
                 foreach ($v->keymap as $kk => $vv) {
610 606
                     $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' ';
611 607
                 }
612
-                $sql .= implode(' AND ', $tmp) . ' ';
608
+                $sql .= implode(' AND ', $tmp).' ';
613 609
                 $sql .= 'LEFT JOIN '.$v->table->getFullName().' '.$getAlias($k).' ON ';
614 610
                 $tmp = [];
615 611
                 foreach ($v->pivot_keymap as $kk => $vv) {
616 612
                     $tmp[] = $getAlias($k).'.'.$vv.' = '.$alias.'.'.$kk.' ';
617 613
                 }
618
-                $sql .= implode(' AND ', $tmp) . ' ';
614
+                $sql .= implode(' AND ', $tmp).' ';
619 615
             } else {
620 616
                 $alias = $getAlias($k);
621 617
                 $sql .= 'LEFT JOIN '.$v->table->getFullName().' '.$alias.' ON ';
@@ -624,38 +620,38 @@  discard block
 block discarded – undo
624 620
                     $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' ';
625 621
                 }
626 622
                 if ($v->sql) {
627
-                    $tmp[] = $v->sql . ' ';
623
+                    $tmp[] = $v->sql.' ';
628 624
                     $par = array_merge($par, $v->par ?? []);
629 625
                 }
630
-                $sql .= implode(' AND ', $tmp) . ' ';
626
+                $sql .= implode(' AND ', $tmp).' ';
631 627
             }
632 628
         }
633 629
         foreach ($j as $k => $v) {
634
-            $sql .= ($v->many ? 'LEFT ' : '' ) . 'JOIN '.$v->table->getFullName().' '.$k.' ON ';
630
+            $sql .= ($v->many ? 'LEFT ' : '').'JOIN '.$v->table->getFullName().' '.$k.' ON ';
635 631
             $tmp = [];
636 632
             foreach ($v->keymap as $kk => $vv) {
637 633
                 $tmp[] = $kk.' = '.$vv;
638 634
             }
639
-            $sql .= implode(' AND ', $tmp) . ' ';
635
+            $sql .= implode(' AND ', $tmp).' ';
640 636
         }
641 637
         if (count($w)) {
642 638
             $sql .= 'WHERE ';
643 639
             $tmp = [];
644 640
             foreach ($w as $v) {
645
-                $tmp[] = '(' . $v[0] . ')';
641
+                $tmp[] = '('.$v[0].')';
646 642
                 $par = array_merge($par, $v[1]);
647 643
             }
648 644
             $sql .= implode(' AND ', $tmp).' ';
649 645
         }
650 646
         if (count($g)) {
651
-            $sql .= 'GROUP BY ' . $g[0] . ' ';
647
+            $sql .= 'GROUP BY '.$g[0].' ';
652 648
             $par = array_merge($par, $g[1]);
653 649
         }
654 650
         if (count($h)) {
655 651
             $sql .= 'HAVING ';
656 652
             $tmp = [];
657 653
             foreach ($h as $v) {
658
-                $tmp[] = '(' . $v[0] . ')';
654
+                $tmp[] = '('.$v[0].')';
659 655
                 $par = array_merge($par, $v[1]);
660 656
             }
661 657
             $sql .= implode(' AND ', $tmp).' ';
@@ -689,7 +685,7 @@  discard block
 block discarded – undo
689 685
                     $this->with(implode('.', $temp));
690 686
                     $table = array_reduce(
691 687
                         $temp,
692
-                        function ($carry, $item) use (&$table) {
688
+                        function($carry, $item) use (&$table) {
693 689
                             return $table->getRelation($item)->table;
694 690
                         }
695 691
                     );
@@ -698,7 +694,7 @@  discard block
 block discarded – undo
698 694
                 }
699 695
                 unset($fields[$k]);
700 696
                 foreach ($cols as $col) {
701
-                    $fields[] = $table . '.' . $col;
697
+                    $fields[] = $table.'.'.$col;
702 698
                 }
703 699
             }
704 700
         }
@@ -732,9 +728,9 @@  discard block
 block discarded – undo
732 728
             return $this->qiterator;
733 729
         }
734 730
         $aliases = [];
735
-        $getAlias = function ($name) use (&$aliases) {
731
+        $getAlias = function($name) use (&$aliases) {
736 732
             // to bypass use: return $name;
737
-            return $aliases[$name] = $aliases[$name] ?? 'alias' . static::SEP . count($aliases);
733
+            return $aliases[$name] = $aliases[$name] ?? 'alias'.static::SEP.count($aliases);
738 734
         };
739 735
         $table = $this->definition->getName();
740 736
         if ($fields !== null) {
@@ -750,7 +746,7 @@  discard block
 block discarded – undo
750 746
         $h = $this->having;
751 747
         $o = $this->order;
752 748
         $g = $this->group;
753
-        $j = array_map(function ($v) {
749
+        $j = array_map(function($v) {
754 750
             return clone $v;
755 751
         }, $this->joins);
756 752
 
@@ -761,38 +757,38 @@  discard block
 block discarded – undo
761 757
 
762 758
         foreach ($this->definition->getRelations() as $k => $relation) {
763 759
             foreach ($f as $kk => $field) {
764
-                if (strpos($field, $k . '.') === 0) {
765
-                    $relations[$k] = [ $relation, $table ];
766
-                    $f[$kk] = str_replace($k . '.', $getAlias($k) . '.', $field);
760
+                if (strpos($field, $k.'.') === 0) {
761
+                    $relations[$k] = [$relation, $table];
762
+                    $f[$kk] = str_replace($k.'.', $getAlias($k).'.', $field);
767 763
                 }
768 764
             }
769 765
             foreach ($w as $kk => $v) {
770
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) {
771
-                    $relations[$k] = [ $relation, $table ];
772
-                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $v[0]);
766
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) {
767
+                    $relations[$k] = [$relation, $table];
768
+                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $v[0]);
773 769
                 }
774 770
             }
775 771
             foreach ($h as $kk => $v) {
776
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) {
777
-                    $relations[$k] = [ $relation, $table ];
778
-                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $v[0]);
772
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) {
773
+                    $relations[$k] = [$relation, $table];
774
+                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $v[0]);
779 775
                 }
780 776
             }
781
-            if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) {
782
-                $relations[$k] = [ $relation, $table ];
783
-                $o[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $o[0]);
777
+            if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) {
778
+                $relations[$k] = [$relation, $table];
779
+                $o[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $o[0]);
784 780
             }
785
-            if (isset($g[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $g[0])) {
786
-                $relations[$k] = [ $relation, $table ];
787
-                $g[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $g[0]);
781
+            if (isset($g[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $g[0])) {
782
+                $relations[$k] = [$relation, $table];
783
+                $g[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $g[0]);
788 784
             }
789 785
             foreach ($j as $kk => $v) {
790 786
                 foreach ($v->keymap as $kkk => $vv) {
791
-                    if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv)) {
792
-                        $relations[$k] = [ $relation, $table ];
787
+                    if (preg_match('(\b'.preg_quote($k.'.').')i', $vv)) {
788
+                        $relations[$k] = [$relation, $table];
793 789
                         $j[$kk]->keymap[$kkk] = preg_replace(
794
-                            '(\b'.preg_quote($k . '.'). ')i',
795
-                            $getAlias($k) . '.',
790
+                            '(\b'.preg_quote($k.'.').')i',
791
+                            $getAlias($k).'.',
796 792
                             $vv
797 793
                         );
798 794
                     }
@@ -801,11 +797,11 @@  discard block
 block discarded – undo
801 797
         }
802 798
         $select = [];
803 799
         foreach ($f as $k => $field) {
804
-            $select[] = $field . (!is_numeric($k) ? ' ' . $k : '');
800
+            $select[] = $field.(!is_numeric($k) ? ' '.$k : '');
805 801
         }
806 802
         foreach ($this->withr as $name => $relation) {
807 803
             foreach ($relation[0]->table->getColumns() as $column) {
808
-                $select[] = $getAlias($name) . '.' . $column . ' ' . $getAlias($name . static::SEP . $column);
804
+                $select[] = $getAlias($name).'.'.$column.' '.$getAlias($name.static::SEP.$column);
809 805
             }
810 806
         }
811 807
         $sql = 'SELECT '.implode(', ', $select).' FROM '.$this->definition->getFullName().' ';
@@ -824,13 +820,13 @@  discard block
 block discarded – undo
824 820
                 foreach ($v->keymap as $kk => $vv) {
825 821
                     $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' ';
826 822
                 }
827
-                $sql .= implode(' AND ', $tmp) . ' ';
823
+                $sql .= implode(' AND ', $tmp).' ';
828 824
                 $sql .= 'LEFT JOIN '.$v->table->getFullName().' '.$getAlias($relation).' ON ';
829 825
                 $tmp = [];
830 826
                 foreach ($v->pivot_keymap as $kk => $vv) {
831 827
                     $tmp[] = $getAlias($relation).'.'.$vv.' = '.$alias.'.'.$kk.' ';
832 828
                 }
833
-                $sql .= implode(' AND ', $tmp) . ' ';
829
+                $sql .= implode(' AND ', $tmp).' ';
834 830
             } else {
835 831
                 $alias = $getAlias($relation);
836 832
 
@@ -840,22 +836,22 @@  discard block
 block discarded – undo
840 836
                     $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' ';
841 837
                 }
842 838
                 if ($v->sql) {
843
-                    $tmp[] = $v->sql . ' ';
839
+                    $tmp[] = $v->sql.' ';
844 840
                     $par = array_merge($par, $v->par ?? []);
845 841
                 }
846
-                $sql .= implode(' AND ', $tmp) . ' ';
842
+                $sql .= implode(' AND ', $tmp).' ';
847 843
             }
848 844
         }
849 845
         foreach ($j as $k => $v) {
850 846
             if ($v->many) {
851 847
                 $many = true;
852 848
             }
853
-            $sql .= ($v->many ? 'LEFT ' : '' ) . 'JOIN '.$v->table->getName().' '.$k.' ON ';
849
+            $sql .= ($v->many ? 'LEFT ' : '').'JOIN '.$v->table->getName().' '.$k.' ON ';
854 850
             $tmp = [];
855 851
             foreach ($v->keymap as $kk => $vv) {
856 852
                 $tmp[] = $kk.' = '.$vv;
857 853
             }
858
-            $sql .= implode(' AND ', $tmp) . ' ';
854
+            $sql .= implode(' AND ', $tmp).' ';
859 855
         }
860 856
         if ($many && count($porder) && $this->li_of[2] === 1) {
861 857
             $ids = $this->ids();
@@ -863,9 +859,9 @@  discard block
 block discarded – undo
863 859
                 if (count($porder) > 1) {
864 860
                     $pkw = [];
865 861
                     foreach ($porder as $name) {
866
-                        $pkw[] = $name . ' = ?';
862
+                        $pkw[] = $name.' = ?';
867 863
                     }
868
-                    $pkw = '(' . implode(' AND ', $pkw) . ')';
864
+                    $pkw = '('.implode(' AND ', $pkw).')';
869 865
                     $pkp = [];
870 866
                     foreach ($ids as $id) {
871 867
                         foreach ($id as $p) {
@@ -877,51 +873,51 @@  discard block
 block discarded – undo
877 873
                         $pkp
878 874
                     ];
879 875
                 } else {
880
-                    $w[] = [ $porder[0] . ' IN ('.implode(',', array_fill(0, count($ids), '?')).')', $ids ];
876
+                    $w[] = [$porder[0].' IN ('.implode(',', array_fill(0, count($ids), '?')).')', $ids];
881 877
                 }
882 878
             } else {
883
-                $w[] = [ '1=0', [] ];
879
+                $w[] = ['1=0', []];
884 880
             }
885 881
         }
886 882
         if (count($w)) {
887 883
             $sql .= 'WHERE ';
888 884
             $tmp = [];
889 885
             foreach ($w as $v) {
890
-                $tmp[] = '(' . $v[0] . ')';
886
+                $tmp[] = '('.$v[0].')';
891 887
                 $par = array_merge($par, $v[1]);
892 888
             }
893 889
             $sql .= implode(' AND ', $tmp).' ';
894 890
         }
895 891
         if (count($g)) {
896
-            $sql .= 'GROUP BY ' . $g[0] . ' ';
892
+            $sql .= 'GROUP BY '.$g[0].' ';
897 893
             $par = array_merge($par, $g[1]);
898 894
         }
899 895
         if (count($h)) {
900 896
             $sql .= 'HAVING ';
901 897
             $tmp = [];
902 898
             foreach ($h as $v) {
903
-                $tmp[] = '(' . $v[0] . ')';
899
+                $tmp[] = '('.$v[0].')';
904 900
                 $par = array_merge($par, $v[1]);
905 901
             }
906 902
             $sql .= implode(' AND ', $tmp).' ';
907 903
         }
908 904
         if (count($o)) {
909
-            $sql .= 'ORDER BY ' . $o[0] . ' ';
905
+            $sql .= 'ORDER BY '.$o[0].' ';
910 906
             $par = array_merge($par, $o[1]);
911 907
         }
912 908
         if (!count($g) && count($porder)) {
913 909
             $pdir = (count($o) && strpos($o[0], 'DESC') !== false) ? 'DESC' : 'ASC';
914
-            $porder = array_map(function ($v) use ($pdir) {
915
-                return $v . ' ' . $pdir;
910
+            $porder = array_map(function($v) use ($pdir) {
911
+                return $v.' '.$pdir;
916 912
             }, $porder);
917
-            $sql .= (count($o) ? ', ' : 'ORDER BY ') . implode(', ', $porder) . ' ';
913
+            $sql .= (count($o) ? ', ' : 'ORDER BY ').implode(', ', $porder).' ';
918 914
         }
919 915
         if ((!$many || $this->li_of[2] === 0 || !count($porder)) && $this->li_of[0]) {
920 916
             if ($this->db->driverName() === 'oracle') {
921
-                if ((int)$this->db->driverOption('version', 0) >= 12) {
922
-                    $sql .= 'OFFSET ' . $this->li_of[1] . ' ROWS FETCH NEXT ' . $this->li_of[0] . ' ROWS ONLY';
917
+                if ((int) $this->db->driverOption('version', 0) >= 12) {
918
+                    $sql .= 'OFFSET '.$this->li_of[1].' ROWS FETCH NEXT '.$this->li_of[0].' ROWS ONLY';
923 919
                 } else {
924
-                    $f = array_map(function ($v) {
920
+                    $f = array_map(function($v) {
925 921
                         $v = explode(' ', trim($v), 2);
926 922
                         if (count($v) === 2) {
927 923
                             return $v[1];
@@ -929,16 +925,16 @@  discard block
 block discarded – undo
929 925
                         $v = explode('.', $v[0], 2);
930 926
                         return count($v) === 2 ? $v[1] : $v[0];
931 927
                     }, $select);
932
-                    $sql = "SELECT " . implode(', ', $f) . " 
928
+                    $sql = "SELECT ".implode(', ', $f)." 
933 929
                             FROM (
934 930
                                 SELECT tbl__.*, rownum rnum__ FROM (
935
-                                    " . $sql . "
931
+                                    " . $sql."
936 932
                                 ) tbl__ 
937
-                                WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1]) . "
933
+                                WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1])."
938 934
                             ) WHERE rnum__ > " . $this->li_of[1];
939 935
                 }
940 936
             } else {
941
-                $sql .= 'LIMIT ' . $this->li_of[0] . ' OFFSET ' . $this->li_of[1];
937
+                $sql .= 'LIMIT '.$this->li_of[0].' OFFSET '.$this->li_of[1];
942 938
             }
943 939
         }
944 940
         return $this->qiterator = new TableQueryIterator(
@@ -988,8 +984,8 @@  discard block
 block discarded – undo
988 984
                 $ret[$k] = str_repeat(' ', 255);
989 985
                 $par[] = &$ret[$k];
990 986
             }
991
-            $sql .= ' RETURNING ' . implode(',', $primary) .
992
-                ' INTO ' . implode(',', array_fill(0, count($primary), '?'));
987
+            $sql .= ' RETURNING '.implode(',', $primary).
988
+                ' INTO '.implode(',', array_fill(0, count($primary), '?'));
993 989
             $this->db->query($sql, $par);
994 990
             return $ret;
995 991
         } else {
@@ -1021,9 +1017,9 @@  discard block
 block discarded – undo
1021 1017
         }
1022 1018
         $sql = 'UPDATE '.$table.' SET ';
1023 1019
         $par = [];
1024
-        $sql .= implode(', ', array_map(function ($v) {
1025
-            return $v . ' = ?';
1026
-        }, array_keys($update))) . ' ';
1020
+        $sql .= implode(', ', array_map(function($v) {
1021
+            return $v.' = ?';
1022
+        }, array_keys($update))).' ';
1027 1023
         $par = array_merge($par, array_values($update));
1028 1024
         if (count($this->where)) {
1029 1025
             $sql .= 'WHERE ';
@@ -1032,7 +1028,7 @@  discard block
 block discarded – undo
1032 1028
                 $tmp[] = $v[0];
1033 1029
                 $par = array_merge($par, $v[1]);
1034 1030
             }
1035
-            $sql .= implode(' AND ', $tmp) . ' ';
1031
+            $sql .= implode(' AND ', $tmp).' ';
1036 1032
         }
1037 1033
         if (count($this->order)) {
1038 1034
             $sql .= $this->order[0];
@@ -1056,7 +1052,7 @@  discard block
 block discarded – undo
1056 1052
                 $tmp[] = $v[0];
1057 1053
                 $par = array_merge($par, $v[1]);
1058 1054
             }
1059
-            $sql .= implode(' AND ', $tmp) . ' ';
1055
+            $sql .= implode(' AND ', $tmp).' ';
1060 1056
         }
1061 1057
         if (count($this->order)) {
1062 1058
             $sql .= $this->order[0];
@@ -1075,18 +1071,18 @@  discard block
 block discarded – undo
1075 1071
         $table = $this->definition;
1076 1072
         if ($table->hasRelation($relation)) {
1077 1073
             $temp = $table->getRelation($relation);
1078
-            $this->withr[$relation] = [ $temp, $table->getName() ];
1074
+            $this->withr[$relation] = [$temp, $table->getName()];
1079 1075
         } else {
1080 1076
             $parts = explode('.', $relation);
1081 1077
             array_reduce(
1082 1078
                 $parts,
1083
-                function ($carry, $item) use (&$table) {
1079
+                function($carry, $item) use (&$table) {
1084 1080
                     if (!$table->hasRelation($item)) {
1085
-                        throw new DBException('Invalid relation name: '.$table->getName().' -> ' . $item);
1081
+                        throw new DBException('Invalid relation name: '.$table->getName().' -> '.$item);
1086 1082
                     }
1087 1083
                     $relation = $table->getRelation($item);
1088
-                    $name = $carry ? $carry . static::SEP . $item : $item;
1089
-                    $this->withr[$name] = [ $relation, $carry ?? $table->getName() ];
1084
+                    $name = $carry ? $carry.static::SEP.$item : $item;
1085
+                    $this->withr[$name] = [$relation, $carry ?? $table->getName()];
1090 1086
                     $table = $relation->table;
1091 1087
                     return $name;
1092 1088
                 }
@@ -1132,9 +1128,9 @@  discard block
 block discarded – undo
1132 1128
         }
1133 1129
 
1134 1130
         $aliases = [];
1135
-        $getAlias = function ($name) use (&$aliases) {
1131
+        $getAlias = function($name) use (&$aliases) {
1136 1132
             // to bypass use: return $name;
1137
-            return $aliases[$name] = $aliases[$name] ?? 'alias' . static::SEP . count($aliases);
1133
+            return $aliases[$name] = $aliases[$name] ?? 'alias'.static::SEP.count($aliases);
1138 1134
         };
1139 1135
         
1140 1136
         $table = $this->definition->getName();
@@ -1146,65 +1142,65 @@  discard block
 block discarded – undo
1146 1142
         $h = $this->having;
1147 1143
         $o = $this->order;
1148 1144
         $g = $this->group;
1149
-        $j = array_map(function ($v) {
1145
+        $j = array_map(function($v) {
1150 1146
             return clone $v;
1151 1147
         }, $this->joins);
1152 1148
         foreach ($this->definition->getRelations() as $k => $v) {
1153 1149
             foreach ($w as $kk => $vv) {
1154
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv[0])) {
1155
-                    $relations[$k] = [ $v, $table ];
1156
-                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vv[0]);
1150
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $vv[0])) {
1151
+                    $relations[$k] = [$v, $table];
1152
+                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vv[0]);
1157 1153
                 }
1158 1154
             }
1159
-            if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) {
1160
-                $relations[$k] = [ $v, $table ];
1161
-                $o[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $o[0]);
1162
-                $o[2] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $o[2]);
1155
+            if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) {
1156
+                $relations[$k] = [$v, $table];
1157
+                $o[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $o[0]);
1158
+                $o[2] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $o[2]);
1163 1159
             }
1164 1160
             foreach ($h as $kk => $vv) {
1165
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv[0])) {
1166
-                    $relations[$k] = [ $v, $table ];
1167
-                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vv[0]);
1161
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $vv[0])) {
1162
+                    $relations[$k] = [$v, $table];
1163
+                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vv[0]);
1168 1164
                 }
1169 1165
             }
1170
-            if (isset($g[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $g[0])) {
1171
-                $relations[$k] = [ $v, $table ];
1172
-                $g[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $g[0]);
1166
+            if (isset($g[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $g[0])) {
1167
+                $relations[$k] = [$v, $table];
1168
+                $g[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $g[0]);
1173 1169
             }
1174 1170
             foreach ($j as $kk => $vv) {
1175 1171
                 foreach ($vv->keymap as $kkk => $vvv) {
1176
-                    if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vvv)) {
1177
-                        $relations[$k] = [ $v, $table ];
1172
+                    if (preg_match('(\b'.preg_quote($k.'.').')i', $vvv)) {
1173
+                        $relations[$k] = [$v, $table];
1178 1174
                         $j[$kk]->keymap[$kkk] =
1179
-                            preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vvv);
1175
+                            preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vvv);
1180 1176
                     }
1181 1177
                 }
1182 1178
             }
1183 1179
         }
1184 1180
 
1185
-        $key = array_map(function ($v) use ($table) {
1186
-            return $table . '.' . $v;
1181
+        $key = array_map(function($v) use ($table) {
1182
+            return $table.'.'.$v;
1187 1183
         }, $this->pkey);
1188 1184
         $own = false;
1189 1185
         $dir = 'ASC';
1190 1186
         if (count($o)) {
1191 1187
             $dir = strpos($o[0], ' DESC') ? 'DESC' : 'ASC';
1192
-            $own = strpos($o[2], $table . '.') === 0;
1188
+            $own = strpos($o[2], $table.'.') === 0;
1193 1189
         }
1194 1190
 
1195 1191
         $dst = $key;
1196 1192
         if (count($o)) {
1197 1193
             if ($own) {
1198 1194
                 // if using own table - do not use max/min in order - that will prevent index usage
1199
-                $dst[] = $o[2] . ' orderbyfix___';
1195
+                $dst[] = $o[2].' orderbyfix___';
1200 1196
             } else {
1201
-                $dst[] = 'MAX(' . $o[2] . ') orderbyfix___';
1197
+                $dst[] = 'MAX('.$o[2].') orderbyfix___';
1202 1198
             }
1203 1199
         }
1204 1200
         $dst = array_unique($dst);
1205 1201
 
1206 1202
         $par = [];
1207
-        $sql  = 'SELECT DISTINCT '.implode(', ', $dst).' FROM '.$this->definition->getFullName().' ';
1203
+        $sql = 'SELECT DISTINCT '.implode(', ', $dst).' FROM '.$this->definition->getFullName().' ';
1208 1204
         foreach ($relations as $k => $v) {
1209 1205
             $table = $v[1] !== $this->definition->getName() ? $getAlias($v[1]) : $v[1];
1210 1206
             $v = $v[0];
@@ -1215,13 +1211,13 @@  discard block
 block discarded – undo
1215 1211
                 foreach ($v->keymap as $kk => $vv) {
1216 1212
                     $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' ';
1217 1213
                 }
1218
-                $sql .= implode(' AND ', $tmp) . ' ';
1214
+                $sql .= implode(' AND ', $tmp).' ';
1219 1215
                 $sql .= 'LEFT JOIN '.$v->table->getName().' '.$getAlias($k).' ON ';
1220 1216
                 $tmp = [];
1221 1217
                 foreach ($v->pivot_keymap as $kk => $vv) {
1222 1218
                     $tmp[] = $getAlias($k).'.'.$vv.' = '.$alias.'.'.$kk.' ';
1223 1219
                 }
1224
-                $sql .= implode(' AND ', $tmp) . ' ';
1220
+                $sql .= implode(' AND ', $tmp).' ';
1225 1221
             } else {
1226 1222
                 $alias = $getAlias($k);
1227 1223
                 $sql .= 'LEFT JOIN '.$v->table->getName().' '.$alias.' ON ';
@@ -1230,37 +1226,37 @@  discard block
 block discarded – undo
1230 1226
                     $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' ';
1231 1227
                 }
1232 1228
                 if ($v->sql) {
1233
-                    $tmp[] = $v->sql . ' ';
1229
+                    $tmp[] = $v->sql.' ';
1234 1230
                     $par = array_merge($par, $v->par ?? []);
1235 1231
                 }
1236
-                $sql .= implode(' AND ', $tmp) . ' ';
1232
+                $sql .= implode(' AND ', $tmp).' ';
1237 1233
             }
1238 1234
         }
1239 1235
         foreach ($j as $k => $v) {
1240
-            $sql .= ($v->many ? 'LEFT ' : '' ) . 'JOIN '.$v->table->getName().' '.$k.' ON ';
1236
+            $sql .= ($v->many ? 'LEFT ' : '').'JOIN '.$v->table->getName().' '.$k.' ON ';
1241 1237
             $tmp = [];
1242 1238
             foreach ($v->keymap as $kk => $vv) {
1243 1239
                 $tmp[] = $kk.' = '.$vv;
1244 1240
             }
1245
-            $sql .= implode(' AND ', $tmp) . ' ';
1241
+            $sql .= implode(' AND ', $tmp).' ';
1246 1242
         }
1247 1243
         if (count($w)) {
1248 1244
             $sql .= 'WHERE ';
1249 1245
             $tmp = [];
1250 1246
             foreach ($w as $v) {
1251
-                $tmp[] = '(' . $v[0] . ')';
1247
+                $tmp[] = '('.$v[0].')';
1252 1248
                 $par = array_merge($par, $v[1]);
1253 1249
             }
1254 1250
             $sql .= implode(' AND ', $tmp).' ';
1255 1251
         }
1256 1252
         if (!$own) {
1257
-            $sql .= 'GROUP BY ' . implode(', ', $key) . ' ';
1253
+            $sql .= 'GROUP BY '.implode(', ', $key).' ';
1258 1254
         }
1259 1255
         if (count($h)) {
1260 1256
             $sql .= 'HAVING ';
1261 1257
             $tmp = [];
1262 1258
             foreach ($h as $v) {
1263
-                $tmp[] = '(' . $v[0] . ')';
1259
+                $tmp[] = '('.$v[0].')';
1264 1260
                 $par = array_merge($par, $v[1]);
1265 1261
             }
1266 1262
             $sql .= implode(' AND ', $tmp).' ';
@@ -1268,38 +1264,38 @@  discard block
 block discarded – undo
1268 1264
         if (count($o)) {
1269 1265
             $sql .= 'ORDER BY ';
1270 1266
             if ($own) {
1271
-                $sql .= $o[2] . ' ' . $dir;
1267
+                $sql .= $o[2].' '.$dir;
1272 1268
             } else {
1273
-                $sql .= 'MAX('.$o[2].') ' . $dir;
1269
+                $sql .= 'MAX('.$o[2].') '.$dir;
1274 1270
             }
1275 1271
         }
1276 1272
         $porder = [];
1277 1273
         $pdir = (count($o) && strpos($o[0], 'DESC') !== false) ? 'DESC' : 'ASC';
1278 1274
         foreach ($this->definition->getPrimaryKey() as $field) {
1279
-            $porder[] = $this->getColumn($field)['name'] . ' ' . $pdir;
1275
+            $porder[] = $this->getColumn($field)['name'].' '.$pdir;
1280 1276
         }
1281 1277
         if (count($porder)) {
1282
-            $sql .= (count($o) ? ', ' : 'ORDER BY ') . implode(', ', $porder) . ' ';
1278
+            $sql .= (count($o) ? ', ' : 'ORDER BY ').implode(', ', $porder).' ';
1283 1279
         }
1284 1280
 
1285 1281
         if ($this->li_of[0]) {
1286 1282
             if ($this->db->driverName() === 'oracle') {
1287
-                if ((int)$this->db->driverOption('version', 0) >= 12) {
1288
-                    $sql .= 'OFFSET ' . $this->li_of[1] . ' ROWS FETCH NEXT ' . $this->li_of[0] . ' ROWS ONLY';
1283
+                if ((int) $this->db->driverOption('version', 0) >= 12) {
1284
+                    $sql .= 'OFFSET '.$this->li_of[1].' ROWS FETCH NEXT '.$this->li_of[0].' ROWS ONLY';
1289 1285
                 } else {
1290
-                    $sql = "SELECT " . implode(', ', $dst) . " 
1286
+                    $sql = "SELECT ".implode(', ', $dst)." 
1291 1287
                             FROM (
1292 1288
                                 SELECT tbl__.*, rownum rnum__ FROM (
1293
-                                    " . $sql . "
1289
+                                    " . $sql."
1294 1290
                                 ) tbl__ 
1295
-                                WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1]) . "
1291
+                                WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1])."
1296 1292
                             ) WHERE rnum__ > " . $this->li_of[1];
1297 1293
                 }
1298 1294
             } else {
1299
-                $sql .= 'LIMIT ' . $this->li_of[0] . ' OFFSET ' . $this->li_of[1];
1295
+                $sql .= 'LIMIT '.$this->li_of[0].' OFFSET '.$this->li_of[1];
1300 1296
             }
1301 1297
         }
1302
-        return array_map(function ($v) {
1298
+        return array_map(function($v) {
1303 1299
             if (array_key_exists('orderbyfix___', $v)) {
1304 1300
                 unset($v['orderbyfix___']);
1305 1301
             }
Please login to merge, or discard this patch.