Completed
Push — master ( 3bf301...d91bdc )
by Ivan
17:12
created
src/driver/postgre/Result.php 1 patch
Spacing   +3 added lines, -4 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,8 +74,8 @@  discard block
 block discarded – undo
75 74
     }
76 75
     public function next(): void
77 76
     {
78
-        $this->fetched ++;
79
-        $this->last = \pg_fetch_array($this->statement, null, \PGSQL_ASSOC)?:null;
77
+        $this->fetched++;
78
+        $this->last = \pg_fetch_array($this->statement, null, \PGSQL_ASSOC) ?: null;
80 79
     }
81 80
     public function valid(): bool
82 81
     {
Please login to merge, or discard this patch.
src/driver/postgre/Statement.php 1 patch
Spacing   +12 added lines, -14 removed lines patch added patch discarded remove patch
@@ -23,17 +23,17 @@  discard block
 block discarded – undo
23 23
         if (strpos(strtolower($statement), 'prepare') === 0) {
24 24
             $this->drv->raw($this->statement);
25 25
             if (!isset($this->name)) {
26
-                $this->name = trim((preg_split('(\s+)', trim($this->statement))?:[])[1]??'', '"');
26
+                $this->name = trim((preg_split('(\s+)', trim($this->statement)) ?: [])[1] ?? '', '"');
27 27
             }
28 28
         } elseif ($this->name !== null) {
29 29
             $temp = \pg_prepare($this->driver, $this->name, $this->statement);
30 30
             if (!$temp) {
31 31
                 $log = $this->drv->option('log_file');
32
-                if ($log && (int)$this->drv->option('log_errors', 1)) {
32
+                if ($log && (int) $this->drv->option('log_errors', 1)) {
33 33
                     @file_put_contents(
34 34
                         $log,
35
-                        '--' . date('Y-m-d H:i:s') . ' ERROR PREPARING: ' . \pg_last_error($this->driver) . "\r\n" .
36
-                        $this->statement . "\r\n" .
35
+                        '--'.date('Y-m-d H:i:s').' ERROR PREPARING: '.\pg_last_error($this->driver)."\r\n".
36
+                        $this->statement."\r\n".
37 37
                         "\r\n",
38 38
                         FILE_APPEND
39 39
                     );
@@ -59,19 +59,17 @@  discard block
 block discarded – undo
59 59
         }
60 60
         if ($this->name !== null) {
61 61
             $temp = (is_array($data) && count($data)) ?
62
-                \pg_execute($this->driver, $this->name, $data) :
63
-                \pg_execute($this->driver, $this->name, array());
62
+                \pg_execute($this->driver, $this->name, $data) : \pg_execute($this->driver, $this->name, array());
64 63
         } else {
65 64
             $temp = (is_array($data) && count($data)) ?
66
-                \pg_query_params($this->driver, $this->statement, $data) :
67
-                \pg_query_params($this->driver, $this->statement, array());
65
+                \pg_query_params($this->driver, $this->statement, $data) : \pg_query_params($this->driver, $this->statement, array());
68 66
         }
69 67
         if (!$temp) {
70
-            if ($log && (int)$this->drv->option('log_errors', 1)) {
68
+            if ($log && (int) $this->drv->option('log_errors', 1)) {
71 69
                 @file_put_contents(
72 70
                     $log,
73
-                    '--' . date('Y-m-d H:i:s') . ' ERROR: ' . \pg_last_error($this->driver) . "\r\n" .
74
-                    $this->statement . "\r\n" .
71
+                    '--'.date('Y-m-d H:i:s').' ERROR: '.\pg_last_error($this->driver)."\r\n".
72
+                    $this->statement."\r\n".
75 73
                     "\r\n",
76 74
                     FILE_APPEND
77 75
                 );
@@ -80,11 +78,11 @@  discard block
 block discarded – undo
80 78
         }
81 79
         if ($log) {
82 80
             $tm = microtime(true) - $tm;
83
-            if ($tm >= (float)$this->drv->option('log_slow', 0)) {
81
+            if ($tm >= (float) $this->drv->option('log_slow', 0)) {
84 82
                 @file_put_contents(
85 83
                     $log,
86
-                    '--' . date('Y-m-d H:i:s') . ' ' . sprintf('%01.6f', $tm) . "s\r\n" .
87
-                    $this->statement . "\r\n" .
84
+                    '--'.date('Y-m-d H:i:s').' '.sprintf('%01.6f', $tm)."s\r\n".
85
+                    $this->statement."\r\n".
88 86
                     "\r\n",
89 87
                     FILE_APPEND
90 88
                 );
Please login to merge, or discard this patch.
src/driver/sqlite/Result.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -62,8 +62,8 @@
 block discarded – undo
62 62
     }
63 63
     public function next(): void
64 64
     {
65
-        $this->fetched ++;
66
-        $this->last = $this->statement->fetchArray(\SQLITE3_ASSOC)?:null;
65
+        $this->fetched++;
66
+        $this->last = $this->statement->fetchArray(\SQLITE3_ASSOC) ?: null;
67 67
     }
68 68
     public function valid(): bool
69 69
     {
Please login to merge, or discard this patch.
src/driver/ibase/Result.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -67,8 +67,8 @@
 block discarded – undo
67 67
     }
68 68
     public function next(): void
69 69
     {
70
-        $this->fetched ++;
71
-        $this->last = \ibase_fetch_assoc($this->result, \IBASE_TEXT)?:null;
70
+        $this->fetched++;
71
+        $this->last = \ibase_fetch_assoc($this->result, \IBASE_TEXT) ?: null;
72 72
     }
73 73
     public function valid(): bool
74 74
     {
Please login to merge, or discard this patch.
src/schema/Mapper.php 1 patch
Spacing   +7 added lines, -8 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
     }
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
         $definition = $entity->definition();
137 137
         foreach ($definition->getColumns() as $column) {
138 138
             if (!array_key_exists($column, $data)) {
139
-                $entity->__lazyProperty($column, function () use ($definition, $primary, $column) {
139
+                $entity->__lazyProperty($column, function() use ($definition, $primary, $column) {
140 140
                     $query = $this->db->table($definition->getFullName());
141 141
                     foreach ($primary as $k => $v) {
142 142
                         $query->filter($k, $v);
@@ -150,18 +150,18 @@  discard block
 block discarded – undo
150 150
                 $name,
151 151
                 array_key_exists($name, $data) && isset($data[$name]) ?
152 152
                     ($relation->many ?
153
-                        array_map(function ($v) use ($relation) {
153
+                        array_map(function($v) use ($relation) {
154 154
                             return $this->entity($relation->table, $v);
155 155
                         }, $data[$name]) :
156 156
                         $this->entity($relation->table, $data[$name])
157 157
                     ) :
158
-                    function (array $columns = null, string $order = null, bool $desc = false) use ($entity, $definition, $relation, $data) {
158
+                    function(array $columns = null, string $order = null, bool $desc = false) use ($entity, $definition, $relation, $data) {
159 159
                         $query = $this->db->table($relation->table->getFullName(), true);
160 160
                         if ($columns !== null) {
161 161
                             $query->columns($columns);
162 162
                         }
163 163
                         if ($relation->sql) {
164
-                            $query->where($relation->sql, $relation->par?:[]);
164
+                            $query->where($relation->sql, $relation->par ?: []);
165 165
                         }
166 166
                         if ($relation->pivot) {
167 167
                             $nm = null;
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
                                 );
182 182
                             }
183 183
                             foreach ($definition->getPrimaryKey() as $v) {
184
-                                $query->filter($nm . '.' . $v, $data[$v] ?? null);
184
+                                $query->filter($nm.'.'.$v, $data[$v] ?? null);
185 185
                             }
186 186
                         } else {
187 187
                             foreach ($relation->keymap as $k => $v) {
@@ -192,8 +192,7 @@  discard block
 block discarded – undo
192 192
                             $query->sort($order, $desc);
193 193
                         }
194 194
                         return $relation->many ?
195
-                            $query->iterator() :
196
-                            $query[0];
195
+                            $query->iterator() : $query[0];
197 196
                     }
198 197
             );
199 198
         }
Please login to merge, or discard this patch.
src/schema/Table.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -79,10 +79,10 @@  discard block
 block discarded – undo
79 79
      * @param  array|string        $column either a single column name or an array of column names
80 80
      * @return  static
81 81
      */
82
-    public function setPrimaryKey(array|string $column): static
82
+    public function setPrimaryKey(array | string $column): static
83 83
     {
84 84
         if (!is_array($column)) {
85
-            $column = [ $column ];
85
+            $column = [$column];
86 86
         }
87 87
         $this->data['primary'] = array_values($column);
88 88
         return $this;
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
      */
110 110
     public function getFullName(): string
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
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
     public function hasOne(
157 157
         Table $toTable,
158 158
         string $name = null,
159
-        string|array|null $toTableColumn = null,
159
+        string | array | null $toTableColumn = null,
160 160
         string $sql = null,
161 161
         array $par = []
162 162
     ) : static {
@@ -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,
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
     public function hasMany(
211 211
         Table $toTable,
212 212
         string $name = null,
213
-        string|array|null $toTableColumn = null,
213
+        string | array | null $toTableColumn = null,
214 214
         ?string $sql = null,
215 215
         array $par = []
216 216
     ): static {
@@ -264,7 +264,7 @@  discard block
 block discarded – undo
264 264
     public function belongsTo(
265 265
         Table $toTable,
266 266
         string $name = null,
267
-        string|array|null $localColumn = null,
267
+        string | array | null $localColumn = null,
268 268
         ?string $sql = null,
269 269
         array $par = []
270 270
     ): static {
@@ -319,8 +319,8 @@  discard block
 block discarded – undo
319 319
         Table $toTable,
320 320
         Table $pivot,
321 321
         ?string $name = null,
322
-        string|array|null $toTableColumn = null,
323
-        string|array|null $localColumn = null
322
+        string | array | null $toTableColumn = null,
323
+        string | array | null $localColumn = null
324 324
     ): static {
325 325
         $pivotColumns = $pivot->getColumns();
326 326
 
Please login to merge, or discard this patch.
src/schema/TableColumn.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
             $instance->setLength($data['length']);
52 52
         }
53 53
         if ($instance->getBasicType() === 'enum' && strpos($instance->getType(), 'enum(') === 0) {
54
-            $temp = array_map(function ($v) {
54
+            $temp = array_map(function($v) {
55 55
                 return str_replace("''", "'", $v);
56 56
             }, explode("','", substr($instance->getType(), 6, -2)));
57 57
             $instance->setValues($temp);
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
     }
170 170
     public function getLength(): int
171 171
     {
172
-        return (int)$this->length;
172
+        return (int) $this->length;
173 173
     }
174 174
     public function setLength(int $length): static
175 175
     {
Please login to merge, or discard this patch.
src/schema/TableQuery.php 1 patch
Spacing   +251 added lines, -255 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
     protected array $order = [];
23 23
     protected array $group = [];
24 24
     protected array $having = [];
25
-    protected array $li_of = [0,0,0];
25
+    protected array $li_of = [0, 0, 0];
26 26
     protected array $fields = [];
27 27
     protected array $withr = [];
28 28
     protected array $joins = [];
@@ -36,11 +36,11 @@  discard block
 block discarded – undo
36 36
      * @param  Table|string   $table           the name or definition of the main table in the query
37 37
      * @param  bool           $findRelations   should the query builder try to find missing joins
38 38
      */
39
-    public function __construct(DBInterface $db, Table|string $table, bool $findRelations = false)
39
+    public function __construct(DBInterface $db, Table | string $table, bool $findRelations = false)
40 40
     {
41 41
         $this->db = $db;
42 42
         $this->findRelations = $findRelations;
43
-        $this->definition = $table instanceof Table ? $table : $this->db->definition((string)$table);
43
+        $this->definition = $table instanceof Table ? $table : $this->db->definition((string) $table);
44 44
         $primary = $this->definition->getPrimaryKey();
45 45
         $columns = $this->definition->getColumns();
46 46
         $this->pkey = count($primary) ? $primary : $columns;
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
     {
64 64
         $column = explode('.', $column);
65 65
         if (count($column) === 1) {
66
-            $column = [ $this->definition->getFullName(), $column[0] ];
66
+            $column = [$this->definition->getFullName(), $column[0]];
67 67
             $col = $this->definition->getColumn($column[1]);
68 68
             if (!$col) {
69 69
                 throw new DBException('Invalid column name in own table');
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
                             $path = $this->db->findRelation($this->definition->getName(), $column[0]);
103 103
                         }
104 104
                         if (!count($path)) {
105
-                            throw new DBException('Invalid foreign table / column name: ' . implode(',', $column));
105
+                            throw new DBException('Invalid foreign table / column name: '.implode(',', $column));
106 106
                         }
107 107
                         unset($path[0]);
108 108
                         $this->with(implode('.', $path), false);
@@ -115,26 +115,26 @@  discard block
 block discarded – undo
115 115
             if ($this->definition->hasRelation(implode('.', $column))) {
116 116
                 $this->with(implode('.', $column), false);
117 117
                 $col = $this->definition->getRelation(implode('.', $column))?->table?->getColumn($name);
118
-                $column = [ implode('.', $column), $name ];
118
+                $column = [implode('.', $column), $name];
119 119
             } else {
120 120
                 $this->with(implode('.', $column), false);
121 121
                 $table = $this->definition;
122 122
                 $table = array_reduce(
123 123
                     $column,
124
-                    function ($carry, $item) use (&$table) {
124
+                    function($carry, $item) use (&$table) {
125 125
                         $table = $table->getRelation($item)->table;
126 126
                         return $table;
127 127
                     }
128 128
                 );
129 129
                 $col = $table->getColumn($name);
130
-                $column = [ implode(static::SEP, $column), $name ];
130
+                $column = [implode(static::SEP, $column), $name];
131 131
             }
132 132
         }
133
-        return [ 'name' => implode('.', $column), 'data' => $col ];
133
+        return ['name' => implode('.', $column), 'data' => $col];
134 134
     }
135 135
     protected function normalizeValue(TableColumn $col, mixed $value): mixed
136 136
     {
137
-        $strict = (int)$this->db->driverOption('strict', 0) > 0;
137
+        $strict = (int) $this->db->driverOption('strict', 0) > 0;
138 138
         if ($value === null && $col->isNullable()) {
139 139
             return null;
140 140
         }
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
                     $temp = strtotime($value);
145 145
                     if (!$temp) {
146 146
                         if ($strict) {
147
-                            throw new DBException('Invalid value for date column ' . $col->getName());
147
+                            throw new DBException('Invalid value for date column '.$col->getName());
148 148
                         }
149 149
                         return null;
150 150
                     }
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
                     return $value->format('Y-m-d');
158 158
                 }
159 159
                 if ($strict) {
160
-                    throw new DBException('Invalid value (unknown data type) for date column ' . $col->getName());
160
+                    throw new DBException('Invalid value (unknown data type) for date column '.$col->getName());
161 161
                 }
162 162
                 return $value;
163 163
             case 'datetime':
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
                     $temp = strtotime($value);
166 166
                     if (!$temp) {
167 167
                         if ($strict) {
168
-                            throw new DBException('Invalid value for datetime column ' . $col->getName());
168
+                            throw new DBException('Invalid value for datetime column '.$col->getName());
169 169
                         }
170 170
                         return null;
171 171
                     }
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
                     return $value->format('Y-m-d H:i:s');
179 179
                 }
180 180
                 if ($strict) {
181
-                    throw new DBException('Invalid value (unknown data type) for datetime column ' . $col->getName());
181
+                    throw new DBException('Invalid value (unknown data type) for datetime column '.$col->getName());
182 182
                 }
183 183
                 return $value;
184 184
             case 'enum':
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
                 if (is_int($value)) {
187 187
                     if (!isset($values[$value])) {
188 188
                         if ($strict) {
189
-                            throw new DBException('Invalid value (using integer) for enum ' . $col->getName());
189
+                            throw new DBException('Invalid value (using integer) for enum '.$col->getName());
190 190
                         }
191 191
                         return $value;
192 192
                     }
@@ -194,23 +194,23 @@  discard block
 block discarded – undo
194 194
                 }
195 195
                 if (!in_array($value, $col->getValues())) {
196 196
                     if ($strict) {
197
-                        throw new DBException('Invalid value for enum ' . $col->getName());
197
+                        throw new DBException('Invalid value for enum '.$col->getName());
198 198
                     }
199 199
                     return 0;
200 200
                 }
201 201
                 return $value;
202 202
             case 'int':
203 203
                 $temp = preg_replace('([^+\-0-9]+)', '', $value);
204
-                return is_string($temp) ? (int)$temp : 0;
204
+                return is_string($temp) ? (int) $temp : 0;
205 205
             case 'float':
206 206
                 $temp = preg_replace('([^+\-0-9.]+)', '', str_replace(',', '.', $value));
207
-                return is_string($temp) ? (float)$temp : 0;
207
+                return is_string($temp) ? (float) $temp : 0;
208 208
             case 'text':
209 209
                 // check using strlen first, in order to avoid hitting mb_ functions which might be polyfilled
210 210
                 // because the polyfill is quite slow
211 211
                 if ($col->hasLength() && strlen($value) > $col->getLength() && mb_strlen($value) > $col->getLength()) {
212 212
                     if ($strict) {
213
-                        throw new DBException('Invalid value for text column ' . $col->getName());
213
+                        throw new DBException('Invalid value for text column '.$col->getName());
214 214
                     }
215 215
                     return mb_substr($value, 0, $col->getLength());
216 216
                 }
@@ -232,35 +232,32 @@  discard block
 block discarded – undo
232 232
             // str_replace(['%', '_'], ['\\%','\\_'], $q)
233 233
             return $negate ?
234 234
                 [
235
-                    $name . ' NOT LIKE ?',
236
-                    [ $this->normalizeValue($column, $value) ]
237
-                ] :
238
-                [
239
-                    $name . ' LIKE ?',
240
-                    [ $this->normalizeValue($column, $value) ]
235
+                    $name.' NOT LIKE ?',
236
+                    [$this->normalizeValue($column, $value)]
237
+                ] : [
238
+                    $name.' LIKE ?',
239
+                    [$this->normalizeValue($column, $value)]
241 240
                 ];
242 241
         }
243 242
         if (is_null($value)) {
244 243
             return $negate ?
245
-                [ $name . ' IS NOT NULL', [] ]:
246
-                [ $name . ' IS NULL', [] ];
244
+                [$name.' IS NOT NULL', []] : [$name.' IS NULL', []];
247 245
         }
248 246
         if (!is_array($value)) {
249 247
             return $negate ?
250 248
                 [
251
-                    $name . ' <> ?',
252
-                    [ $this->normalizeValue($column, $value) ]
253
-                ] :
254
-                [
255
-                    $name . ' = ?',
256
-                    [ $this->normalizeValue($column, $value) ]
249
+                    $name.' <> ?',
250
+                    [$this->normalizeValue($column, $value)]
251
+                ] : [
252
+                    $name.' = ?',
253
+                    [$this->normalizeValue($column, $value)]
257 254
                 ];
258 255
         }
259 256
         if (isset($value['beg']) && strlen($value['beg']) && (!isset($value['end']) || !strlen($value['end']))) {
260
-            $value = [ 'gte' => $value['beg'] ];
257
+            $value = ['gte' => $value['beg']];
261 258
         }
262 259
         if (isset($value['end']) && strlen($value['end']) && (!isset($value['beg']) || !strlen($value['beg']))) {
263
-            $value = [ 'lte' => $value['end'] ];
260
+            $value = ['lte' => $value['end']];
264 261
         }
265 262
         if (isset($value['beg']) && isset($value['end'])) {
266 263
             return $negate ?
@@ -270,8 +267,7 @@  discard block
 block discarded – undo
270 267
                         $this->normalizeValue($column, $value['beg']),
271 268
                         $this->normalizeValue($column, $value['end'])
272 269
                     ]
273
-                ] :
274
-                [
270
+                ] : [
275 271
                     $name.' BETWEEN ? AND ?',
276 272
                     [
277 273
                         $this->normalizeValue($column, $value['beg']),
@@ -283,42 +279,42 @@  discard block
 block discarded – undo
283 279
             $sql = [];
284 280
             $par = [];
285 281
             if (isset($value['gt'])) {
286
-                $sql[] = $name. ' ' . ($negate ? '<=' : '>') . ' ?';
282
+                $sql[] = $name.' '.($negate ? '<=' : '>').' ?';
287 283
                 $par[] = $this->normalizeValue($column, $value['gt']);
288 284
             }
289 285
             if (isset($value['gte'])) {
290
-                $sql[] = $name. ' ' . ($negate ? '<' : '>=') . ' ?';
286
+                $sql[] = $name.' '.($negate ? '<' : '>=').' ?';
291 287
                 $par[] = $this->normalizeValue($column, $value['gte']);
292 288
             }
293 289
             if (isset($value['lt'])) {
294
-                $sql[] = $name. ' ' . ($negate ? '>=' : '<') . ' ?';
290
+                $sql[] = $name.' '.($negate ? '>=' : '<').' ?';
295 291
                 $par[] = $this->normalizeValue($column, $value['lt']);
296 292
             }
297 293
             if (isset($value['lte'])) {
298
-                $sql[] = $name. ' ' . ($negate ? '>' : '<=') . ' ?';
294
+                $sql[] = $name.' '.($negate ? '>' : '<=').' ?';
299 295
                 $par[] = $this->normalizeValue($column, $value['lte']);
300 296
             }
301 297
             return [
302
-                '(' . implode(' AND ', $sql) . ')',
298
+                '('.implode(' AND ', $sql).')',
303 299
                 $par
304 300
             ];
305 301
         }
306 302
 
307
-        $value = array_values(array_map(function ($v) use ($column) {
303
+        $value = array_values(array_map(function($v) use ($column) {
308 304
             return $this->normalizeValue($column, $v);
309 305
         }, $value));
310 306
         if ($this->db->driverName() === 'oracle') {
311 307
             $sql = [];
312 308
             $par = [];
313 309
             for ($i = 0; $i < count($value); $i += 500) {
314
-                $sql[] = $negate ? $name . ' NOT IN (??)' : $name . ' IN (??)';
310
+                $sql[] = $negate ? $name.' NOT IN (??)' : $name.' IN (??)';
315 311
                 $par[] = array_slice($value, $i, 500);
316 312
             }
317
-            $sql = '(' . implode($negate ? ' AND ' : ' OR ', $sql) . ')';
318
-            return [ $sql, [$par] ];
313
+            $sql = '('.implode($negate ? ' AND ' : ' OR ', $sql).')';
314
+            return [$sql, [$par]];
319 315
         }
320 316
         return [
321
-            $negate ? $name . ' NOT IN (??)' : $name . ' IN (??)',
317
+            $negate ? $name.' NOT IN (??)' : $name.' IN (??)',
322 318
             [$value]
323 319
         ];
324 320
     }
@@ -350,7 +346,7 @@  discard block
 block discarded – undo
350 346
                 $par = array_merge($par, $temp[1]);
351 347
             }
352 348
         }
353
-        return $this->where('(' . implode(' OR ', $sql) . ')', $par);
349
+        return $this->where('('.implode(' OR ', $sql).')', $par);
354 350
     }
355 351
     /**
356 352
      * Filter the results matching all of the criteria
@@ -368,7 +364,7 @@  discard block
 block discarded – undo
368 364
                 $par = array_merge($par, $temp[1]);
369 365
             }
370 366
         }
371
-        return $this->where('(' . implode(' AND ', $sql) . ')', $par);
367
+        return $this->where('('.implode(' AND ', $sql).')', $par);
372 368
     }
373 369
     /**
374 370
      * Sort by a column
@@ -383,7 +379,7 @@  discard block
 block discarded – undo
383 379
         } catch (DBException $e) {
384 380
             throw new DBException('Invalid sort column');
385 381
         }
386
-        return $this->order($column . ' ' . ($desc ? 'DESC' : 'ASC'));
382
+        return $this->order($column.' '.($desc ? 'DESC' : 'ASC'));
387 383
     }
388 384
     /**
389 385
      * Group by a column (or columns)
@@ -393,7 +389,7 @@  discard block
 block discarded – undo
393 389
     public function group($column) : self
394 390
     {
395 391
         if (!is_array($column)) {
396
-            $column = [ $column ];
392
+            $column = [$column];
397 393
         }
398 394
         foreach ($column as $k => $v) {
399 395
             $column[$k] = $this->getColumn($v)['name'];
@@ -436,7 +432,7 @@  discard block
 block discarded – undo
436 432
         $this->order = [];
437 433
         $this->having = [];
438 434
         $this->aliases = [];
439
-        $this->li_of = [0,0,0];
435
+        $this->li_of = [0, 0, 0];
440 436
         $this->qiterator = null;
441 437
         return $this;
442 438
     }
@@ -449,7 +445,7 @@  discard block
 block discarded – undo
449 445
     public function groupBy(string $sql, array $params = []) : self
450 446
     {
451 447
         $this->qiterator = null;
452
-        $this->group = [ $sql, $params ];
448
+        $this->group = [$sql, $params];
453 449
         return $this;
454 450
     }
455 451
     /**
@@ -462,7 +458,7 @@  discard block
 block discarded – undo
462 458
      */
463 459
     public function join($table, array $fields, string $name = null, bool $multiple = true)
464 460
     {
465
-        $table = $table instanceof Table ? $table : $this->db->definition((string)$table);
461
+        $table = $table instanceof Table ? $table : $this->db->definition((string) $table);
466 462
         $name = $name ?? $table->getName();
467 463
         if (isset($this->joins[$name]) || $this->definition->hasRelation($name)) {
468 464
             throw new DBException('Alias / table name already in use');
@@ -471,7 +467,7 @@  discard block
 block discarded – undo
471 467
         foreach ($fields as $k => $v) {
472 468
             $k = explode('.', $k, 2);
473 469
             $k = count($k) == 2 ? $k[1] : $k[0];
474
-            $this->joins[$name]->keymap[$this->getColumn($name . '.' . $k)['name']] = $this->getColumn($v)['name'];
470
+            $this->joins[$name]->keymap[$this->getColumn($name.'.'.$k)['name']] = $this->getColumn($v)['name'];
475 471
         }
476 472
         return $this;
477 473
     }
@@ -484,7 +480,7 @@  discard block
 block discarded – undo
484 480
     public function where(string $sql, array $params = []) : self
485 481
     {
486 482
         $this->qiterator = null;
487
-        $this->where[] = [ $sql, $params ];
483
+        $this->where[] = [$sql, $params];
488 484
         return $this;
489 485
     }
490 486
     /**
@@ -496,7 +492,7 @@  discard block
 block discarded – undo
496 492
     public function having(string $sql, array $params = []) : self
497 493
     {
498 494
         $this->qiterator = null;
499
-        $this->having[] = [ $sql, $params ];
495
+        $this->having[] = [$sql, $params];
500 496
         return $this;
501 497
     }
502 498
     /**
@@ -516,12 +512,12 @@  discard block
 block discarded – undo
516 512
                     throw new \Exception();
517 513
                 }
518 514
                 $name = $this->getColumn(trim($name))['name'];
519
-                $sql = $name . ' ' . (strpos(strtolower($sql), ' desc') ? 'DESC' : 'ASC');
515
+                $sql = $name.' '.(strpos(strtolower($sql), ' desc') ? 'DESC' : 'ASC');
520 516
             } catch (\Exception $e) {
521 517
                 $name = null;
522 518
             }
523 519
         }
524
-        $this->order = [ $sql, $params, $name ];
520
+        $this->order = [$sql, $params, $name];
525 521
         return $this;
526 522
     }
527 523
     /**
@@ -533,7 +529,7 @@  discard block
 block discarded – undo
533 529
     public function limit(int $limit, int $offset = 0, bool $limitOnMainTable = false) : self
534 530
     {
535 531
         $this->qiterator = null;
536
-        $this->li_of = [ $limit, $offset, $limitOnMainTable ? 1 : 0 ];
532
+        $this->li_of = [$limit, $offset, $limitOnMainTable ? 1 : 0];
537 533
         return $this;
538 534
     }
539 535
     /**
@@ -544,9 +540,9 @@  discard block
 block discarded – undo
544 540
     {
545 541
         $aliases = [];
546 542
         $aliases_ext = [];
547
-        $getAlias = function ($name) use (&$aliases, &$aliases_ext) {
543
+        $getAlias = function($name) use (&$aliases, &$aliases_ext) {
548 544
             // to bypass use: return $name;
549
-            $aliases[$name] = $aliases[$name] ?? 'alias' . static::SEP . count($aliases);
545
+            $aliases[$name] = $aliases[$name] ?? 'alias'.static::SEP.count($aliases);
550 546
             if (isset($aliases_ext[$name])) {
551 547
                 unset($aliases_ext[$name]);
552 548
             }
@@ -569,7 +565,7 @@  discard block
 block discarded – undo
569 565
         $h = $this->having;
570 566
         $o = $this->order;
571 567
         $g = $this->group;
572
-        $j = array_map(function ($v) {
568
+        $j = array_map(function($v) {
573 569
             return clone $v;
574 570
         }, $this->joins);
575 571
 
@@ -579,28 +575,28 @@  discard block
 block discarded – undo
579 575
                 continue;
580 576
             }
581 577
             foreach ($w as $kk => $v) {
582
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) {
578
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) {
583 579
                     $used_relations[] = $k;
584
-                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $v[0]);
580
+                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $v[0]);
585 581
                 }
586 582
             }
587 583
             foreach ($h as $kk => $v) {
588
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) {
584
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) {
589 585
                     $used_relations[] = $k;
590
-                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $v[0]);
586
+                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $v[0]);
591 587
                 }
592 588
             }
593
-            if (isset($g[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $g[0])) {
589
+            if (isset($g[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $g[0])) {
594 590
                 $used_relations[] = $k;
595
-                $g[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $g[0]);
591
+                $g[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $g[0]);
596 592
             }
597 593
             foreach ($j as $kk => $v) {
598 594
                 foreach ($v->keymap as $kkk => $vv) {
599
-                    if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv)) {
595
+                    if (preg_match('(\b'.preg_quote($k.'.').')i', $vv)) {
600 596
                         $used_relations[] = $k;
601 597
                         $j[$kk]->keymap[$kkk] = preg_replace(
602
-                            '(\b'.preg_quote($k . '.'). ')i',
603
-                            $getAlias($k) . '.',
598
+                            '(\b'.preg_quote($k.'.').')i',
599
+                            $getAlias($k).'.',
604 600
                             $vv
605 601
                         );
606 602
                     }
@@ -609,65 +605,65 @@  discard block
 block discarded – undo
609 605
         }
610 606
         foreach ($this->definition->getRelations() as $k => $v) {
611 607
             foreach ($w as $kk => $vv) {
612
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv[0])) {
613
-                    $relations[$k] = [ $v, $table ];
608
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $vv[0])) {
609
+                    $relations[$k] = [$v, $table];
614 610
                     $used_relations[] = $k;
615
-                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vv[0]);
611
+                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vv[0]);
616 612
                 }
617 613
             }
618
-            if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) {
619
-                $relations[$k] = [ $v, $table ];
614
+            if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) {
615
+                $relations[$k] = [$v, $table];
620 616
             }
621 617
             foreach ($h as $kk => $vv) {
622
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv[0])) {
623
-                    $relations[$k] = [ $v, $table ];
618
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $vv[0])) {
619
+                    $relations[$k] = [$v, $table];
624 620
                     $used_relations[] = $k;
625
-                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vv[0]);
621
+                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vv[0]);
626 622
                 }
627 623
             }
628
-            if (isset($g[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $g[0])) {
629
-                $relations[$k] = [ $v, $table ];
624
+            if (isset($g[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $g[0])) {
625
+                $relations[$k] = [$v, $table];
630 626
                 $used_relations[] = $k;
631
-                $g[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $g[0]);
627
+                $g[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $g[0]);
632 628
             }
633 629
             foreach ($j as $kk => $vv) {
634 630
                 foreach ($vv->keymap as $kkk => $vvv) {
635
-                    if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vvv)) {
636
-                        $relations[$k] = [ $v, $table ];
631
+                    if (preg_match('(\b'.preg_quote($k.'.').')i', $vvv)) {
632
+                        $relations[$k] = [$v, $table];
637 633
                         $used_relations[] = $k;
638 634
                         $j[$kk]->keymap[$kkk] =
639
-                            preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vvv);
635
+                            preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vvv);
640 636
                     }
641 637
                 }
642 638
             }
643 639
         }
644 640
         foreach ($aliases_ext as $k => $alias) {
645 641
             foreach ($w as $kk => $v) {
646
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) {
647
-                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $alias . '.', $v[0]);
642
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) {
643
+                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $alias.'.', $v[0]);
648 644
                     $used_relations[] = $k;
649 645
                 }
650 646
             }
651 647
             foreach ($h as $kk => $v) {
652
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) {
653
-                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $alias . '.', $v[0]);
648
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) {
649
+                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $alias.'.', $v[0]);
654 650
                     $used_relations[] = $k;
655 651
                 }
656 652
             }
657
-            if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) {
653
+            if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) {
658 654
                 $used_relations[] = $k;
659 655
             }
660
-            if (isset($g[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $g[0])) {
661
-                $g[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $alias . '.', $g[0]);
656
+            if (isset($g[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $g[0])) {
657
+                $g[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $alias.'.', $g[0]);
662 658
                 $used_relations[] = $k;
663 659
             }
664 660
             foreach ($j as $kk => $v) {
665 661
                 foreach ($v->keymap as $kkk => $vv) {
666
-                    if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv)) {
662
+                    if (preg_match('(\b'.preg_quote($k.'.').')i', $vv)) {
667 663
                         $used_relations[] = $k;
668 664
                         $j[$kk]->keymap[$kkk] = preg_replace(
669
-                            '(\b'.preg_quote($k . '.'). ')i',
670
-                            $alias . '.',
665
+                            '(\b'.preg_quote($k.'.').')i',
666
+                            $alias.'.',
671 667
                             $vv
672 668
                         );
673 669
                     }
@@ -685,13 +681,13 @@  discard block
 block discarded – undo
685 681
                     foreach ($v->keymap as $kk => $vv) {
686 682
                         $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' ';
687 683
                     }
688
-                    $sql .= implode(' AND ', $tmp) . ' ';
684
+                    $sql .= implode(' AND ', $tmp).' ';
689 685
                     $sql .= 'LEFT JOIN '.$v->table->getFullName().' '.$getAlias($k).' ON ';
690 686
                     $tmp = [];
691 687
                     foreach ($v->pivot_keymap as $kk => $vv) {
692 688
                         $tmp[] = $getAlias($k).'.'.$vv.' = '.$alias.'.'.$kk.' ';
693 689
                     }
694
-                    $sql .= implode(' AND ', $tmp) . ' ';
690
+                    $sql .= implode(' AND ', $tmp).' ';
695 691
                 } else {
696 692
                     $alias = $getAlias($k);
697 693
                     $sql .= 'LEFT JOIN '.$v->table->getFullName().' '.$alias.' ON ';
@@ -700,19 +696,19 @@  discard block
 block discarded – undo
700 696
                         $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' ';
701 697
                     }
702 698
                     if ($v->sql) {
703
-                        $tmp[] = $v->sql . ' ';
699
+                        $tmp[] = $v->sql.' ';
704 700
                         $par = array_merge($par, $v->par ?? []);
705 701
                     }
706
-                    $sql .= implode(' AND ', $tmp) . ' ';
702
+                    $sql .= implode(' AND ', $tmp).' ';
707 703
                 }
708 704
             }
709 705
             foreach ($j as $k => $v) {
710
-                $sql .= ($v->many ? 'LEFT ' : '' ) . 'JOIN '.$v->table->getFullName().' '.$k.' ON ';
706
+                $sql .= ($v->many ? 'LEFT ' : '').'JOIN '.$v->table->getFullName().' '.$k.' ON ';
711 707
                 $tmp = [];
712 708
                 foreach ($v->keymap as $kk => $vv) {
713 709
                     $tmp[] = $kk.' = '.$vv;
714 710
                 }
715
-                $sql .= implode(' AND ', $tmp) . ' ';
711
+                $sql .= implode(' AND ', $tmp).' ';
716 712
             }
717 713
         } else {
718 714
             $sql = str_replace('COUNT(DISTINCT ', 'COUNT(', $sql);
@@ -721,20 +717,20 @@  discard block
 block discarded – undo
721 717
             $sql .= 'WHERE ';
722 718
             $tmp = [];
723 719
             foreach ($w as $v) {
724
-                $tmp[] = '(' . $v[0] . ')';
720
+                $tmp[] = '('.$v[0].')';
725 721
                 $par = array_merge($par, $v[1]);
726 722
             }
727 723
             $sql .= implode(' AND ', $tmp).' ';
728 724
         }
729 725
         if (count($g)) {
730
-            $sql .= 'GROUP BY ' . $g[0] . ' ';
726
+            $sql .= 'GROUP BY '.$g[0].' ';
731 727
             $par = array_merge($par, $g[1]);
732 728
         }
733 729
         if (count($h)) {
734 730
             $sql .= 'HAVING ';
735 731
             $tmp = [];
736 732
             foreach ($h as $v) {
737
-                $tmp[] = '(' . $v[0] . ')';
733
+                $tmp[] = '('.$v[0].')';
738 734
                 $par = array_merge($par, $v[1]);
739 735
             }
740 736
             $sql .= implode(' AND ', $tmp).' ';
@@ -768,7 +764,7 @@  discard block
 block discarded – undo
768 764
                     $this->with(implode('.', $temp));
769 765
                     $table = array_reduce(
770 766
                         $temp,
771
-                        function ($carry, $item) use (&$table) {
767
+                        function($carry, $item) use (&$table) {
772 768
                             return $table->getRelation($item)->table;
773 769
                         }
774 770
                     );
@@ -777,7 +773,7 @@  discard block
 block discarded – undo
777 773
                 }
778 774
                 unset($fields[$k]);
779 775
                 foreach ($cols as $col) {
780
-                    $fields[] = $table . '.' . $col;
776
+                    $fields[] = $table.'.'.$col;
781 777
                 }
782 778
             }
783 779
         }
@@ -812,9 +808,9 @@  discard block
 block discarded – undo
812 808
         }
813 809
         $aliases = [];
814 810
         $aliases_ext = [];
815
-        $getAlias = function ($name) use (&$aliases, &$aliases_ext) {
811
+        $getAlias = function($name) use (&$aliases, &$aliases_ext) {
816 812
             // to bypass use: return $name;
817
-            $aliases[$name] = $aliases[$name] ?? 'alias' . static::SEP . count($aliases);
813
+            $aliases[$name] = $aliases[$name] ?? 'alias'.static::SEP.count($aliases);
818 814
             if (isset($aliases_ext[$name])) {
819 815
                 unset($aliases_ext[$name]);
820 816
             }
@@ -839,7 +835,7 @@  discard block
 block discarded – undo
839 835
         $h = $this->having;
840 836
         $o = $this->order;
841 837
         $g = $this->group;
842
-        $j = array_map(function ($v) {
838
+        $j = array_map(function($v) {
843 839
             return clone $v;
844 840
         }, $this->joins);
845 841
 
@@ -853,32 +849,32 @@  discard block
 block discarded – undo
853 849
                 continue;
854 850
             }
855 851
             foreach ($f as $kk => $field) {
856
-                if (strpos($field, $k . '.') === 0) {
857
-                    $f[$kk] = str_replace($k . '.', $getAlias($k) . '.', $field);
852
+                if (strpos($field, $k.'.') === 0) {
853
+                    $f[$kk] = str_replace($k.'.', $getAlias($k).'.', $field);
858 854
                 }
859 855
             }
860 856
             foreach ($w as $kk => $v) {
861
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) {
862
-                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $v[0]);
857
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) {
858
+                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $v[0]);
863 859
                 }
864 860
             }
865 861
             foreach ($h as $kk => $v) {
866
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) {
867
-                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $v[0]);
862
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) {
863
+                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $v[0]);
868 864
                 }
869 865
             }
870
-            if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) {
871
-                $o[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $o[0]);
866
+            if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) {
867
+                $o[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $o[0]);
872 868
             }
873
-            if (isset($g[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $g[0])) {
874
-                $g[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $g[0]);
869
+            if (isset($g[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $g[0])) {
870
+                $g[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $g[0]);
875 871
             }
876 872
             foreach ($j as $kk => $v) {
877 873
                 foreach ($v->keymap as $kkk => $vv) {
878
-                    if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv)) {
874
+                    if (preg_match('(\b'.preg_quote($k.'.').')i', $vv)) {
879 875
                         $j[$kk]->keymap[$kkk] = preg_replace(
880
-                            '(\b'.preg_quote($k . '.'). ')i',
881
-                            $getAlias($k) . '.',
876
+                            '(\b'.preg_quote($k.'.').')i',
877
+                            $getAlias($k).'.',
882 878
                             $vv
883 879
                         );
884 880
                     }
@@ -887,38 +883,38 @@  discard block
 block discarded – undo
887 883
         }
888 884
         foreach ($this->definition->getRelations() as $k => $relation) {
889 885
             foreach ($f as $kk => $field) {
890
-                if (strpos($field, $k . '.') === 0) {
891
-                    $relations[$k] = [ $relation, $table ];
892
-                    $f[$kk] = str_replace($k . '.', $getAlias($k) . '.', $field);
886
+                if (strpos($field, $k.'.') === 0) {
887
+                    $relations[$k] = [$relation, $table];
888
+                    $f[$kk] = str_replace($k.'.', $getAlias($k).'.', $field);
893 889
                 }
894 890
             }
895 891
             foreach ($w as $kk => $v) {
896
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) {
897
-                    $relations[$k] = [ $relation, $table ];
898
-                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $v[0]);
892
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) {
893
+                    $relations[$k] = [$relation, $table];
894
+                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $v[0]);
899 895
                 }
900 896
             }
901 897
             foreach ($h as $kk => $v) {
902
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) {
903
-                    $relations[$k] = [ $relation, $table ];
904
-                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $v[0]);
898
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) {
899
+                    $relations[$k] = [$relation, $table];
900
+                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $v[0]);
905 901
                 }
906 902
             }
907
-            if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) {
908
-                $relations[$k] = [ $relation, $table ];
909
-                $o[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $o[0]);
903
+            if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) {
904
+                $relations[$k] = [$relation, $table];
905
+                $o[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $o[0]);
910 906
             }
911
-            if (isset($g[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $g[0])) {
912
-                $relations[$k] = [ $relation, $table ];
913
-                $g[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $g[0]);
907
+            if (isset($g[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $g[0])) {
908
+                $relations[$k] = [$relation, $table];
909
+                $g[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $g[0]);
914 910
             }
915 911
             foreach ($j as $kk => $v) {
916 912
                 foreach ($v->keymap as $kkk => $vv) {
917
-                    if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv)) {
918
-                        $relations[$k] = [ $relation, $table ];
913
+                    if (preg_match('(\b'.preg_quote($k.'.').')i', $vv)) {
914
+                        $relations[$k] = [$relation, $table];
919 915
                         $j[$kk]->keymap[$kkk] = preg_replace(
920
-                            '(\b'.preg_quote($k . '.'). ')i',
921
-                            $getAlias($k) . '.',
916
+                            '(\b'.preg_quote($k.'.').')i',
917
+                            $getAlias($k).'.',
922 918
                             $vv
923 919
                         );
924 920
                     }
@@ -927,32 +923,32 @@  discard block
 block discarded – undo
927 923
         }
928 924
         foreach ($aliases_ext as $k => $alias) {
929 925
             foreach ($f as $kk => $field) {
930
-                if (strpos($field, $k . '.') === 0) {
931
-                    $f[$kk] = str_replace($k . '.', $alias . '.', $field);
926
+                if (strpos($field, $k.'.') === 0) {
927
+                    $f[$kk] = str_replace($k.'.', $alias.'.', $field);
932 928
                 }
933 929
             }
934 930
             foreach ($w as $kk => $v) {
935
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) {
936
-                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $alias . '.', $v[0]);
931
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) {
932
+                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $alias.'.', $v[0]);
937 933
                 }
938 934
             }
939 935
             foreach ($h as $kk => $v) {
940
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) {
941
-                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $alias . '.', $v[0]);
936
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) {
937
+                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $alias.'.', $v[0]);
942 938
                 }
943 939
             }
944
-            if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) {
945
-                $o[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $alias . '.', $o[0]);
940
+            if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) {
941
+                $o[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $alias.'.', $o[0]);
946 942
             }
947
-            if (isset($g[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $g[0])) {
948
-                $g[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $alias . '.', $g[0]);
943
+            if (isset($g[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $g[0])) {
944
+                $g[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $alias.'.', $g[0]);
949 945
             }
950 946
             foreach ($j as $kk => $v) {
951 947
                 foreach ($v->keymap as $kkk => $vv) {
952
-                    if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv)) {
948
+                    if (preg_match('(\b'.preg_quote($k.'.').')i', $vv)) {
953 949
                         $j[$kk]->keymap[$kkk] = preg_replace(
954
-                            '(\b'.preg_quote($k . '.'). ')i',
955
-                            $alias . '.',
950
+                            '(\b'.preg_quote($k.'.').')i',
951
+                            $alias.'.',
956 952
                             $vv
957 953
                         );
958 954
                     }
@@ -961,12 +957,12 @@  discard block
 block discarded – undo
961 957
         }
962 958
         $select = [];
963 959
         foreach ($f as $k => $field) {
964
-            $select[] = $field . (!is_numeric($k) ? ' ' . $k : '');
960
+            $select[] = $field.(!is_numeric($k) ? ' '.$k : '');
965 961
         }
966 962
         foreach ($this->withr as $name => $relation) {
967 963
             if ($relation[2]) {
968 964
                 foreach ($relation[0]->table->getColumns() as $column) {
969
-                    $select[] = $getAlias($name) . '.' . $column . ' ' . $getAlias($name . static::SEP . $column);
965
+                    $select[] = $getAlias($name).'.'.$column.' '.$getAlias($name.static::SEP.$column);
970 966
                 }
971 967
             }
972 968
         }
@@ -986,13 +982,13 @@  discard block
 block discarded – undo
986 982
                 foreach ($v->keymap as $kk => $vv) {
987 983
                     $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' ';
988 984
                 }
989
-                $sql .= implode(' AND ', $tmp) . ' ';
985
+                $sql .= implode(' AND ', $tmp).' ';
990 986
                 $sql .= 'LEFT JOIN '.$v->table->getFullName().' '.$getAlias($relation).' ON ';
991 987
                 $tmp = [];
992 988
                 foreach ($v->pivot_keymap as $kk => $vv) {
993 989
                     $tmp[] = $getAlias($relation).'.'.$vv.' = '.$alias.'.'.$kk.' ';
994 990
                 }
995
-                $sql .= implode(' AND ', $tmp) . ' ';
991
+                $sql .= implode(' AND ', $tmp).' ';
996 992
             } else {
997 993
                 $alias = $getAlias($relation);
998 994
 
@@ -1002,22 +998,22 @@  discard block
 block discarded – undo
1002 998
                     $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' ';
1003 999
                 }
1004 1000
                 if ($v->sql) {
1005
-                    $tmp[] = $v->sql . ' ';
1001
+                    $tmp[] = $v->sql.' ';
1006 1002
                     $par = array_merge($par, $v->par ?? []);
1007 1003
                 }
1008
-                $sql .= implode(' AND ', $tmp) . ' ';
1004
+                $sql .= implode(' AND ', $tmp).' ';
1009 1005
             }
1010 1006
         }
1011 1007
         foreach ($j as $k => $v) {
1012 1008
             if ($v->many) {
1013 1009
                 $many = true;
1014 1010
             }
1015
-            $sql .= ($v->many ? 'LEFT ' : '' ) . 'JOIN '.$v->table->getName().' '.$k.' ON ';
1011
+            $sql .= ($v->many ? 'LEFT ' : '').'JOIN '.$v->table->getName().' '.$k.' ON ';
1016 1012
             $tmp = [];
1017 1013
             foreach ($v->keymap as $kk => $vv) {
1018 1014
                 $tmp[] = $kk.' = '.$vv;
1019 1015
             }
1020
-            $sql .= implode(' AND ', $tmp) . ' ';
1016
+            $sql .= implode(' AND ', $tmp).' ';
1021 1017
         }
1022 1018
         if ($many && count($porder) && $this->li_of[2] === 1) {
1023 1019
             $ids = $this->ids();
@@ -1025,9 +1021,9 @@  discard block
 block discarded – undo
1025 1021
                 if (count($porder) > 1) {
1026 1022
                     $pkw = [];
1027 1023
                     foreach ($porder as $name) {
1028
-                        $pkw[] = $name . ' = ?';
1024
+                        $pkw[] = $name.' = ?';
1029 1025
                     }
1030
-                    $pkw = '(' . implode(' AND ', $pkw) . ')';
1026
+                    $pkw = '('.implode(' AND ', $pkw).')';
1031 1027
                     $pkp = [];
1032 1028
                     foreach ($ids as $id) {
1033 1029
                         foreach ($id as $p) {
@@ -1039,60 +1035,60 @@  discard block
 block discarded – undo
1039 1035
                         $pkp
1040 1036
                     ];
1041 1037
                 } else {
1042
-                    $w[] = [ $porder[0] . ' IN ('.implode(',', array_fill(0, count($ids), '?')).')', $ids ];
1038
+                    $w[] = [$porder[0].' IN ('.implode(',', array_fill(0, count($ids), '?')).')', $ids];
1043 1039
                 }
1044 1040
             } else {
1045
-                $w[] = [ '1=0', [] ];
1041
+                $w[] = ['1=0', []];
1046 1042
             }
1047 1043
         }
1048 1044
         if (count($w)) {
1049 1045
             $sql .= 'WHERE ';
1050 1046
             $tmp = [];
1051 1047
             foreach ($w as $v) {
1052
-                $tmp[] = '(' . $v[0] . ')';
1048
+                $tmp[] = '('.$v[0].')';
1053 1049
                 $par = array_merge($par, $v[1]);
1054 1050
             }
1055 1051
             $sql .= implode(' AND ', $tmp).' ';
1056 1052
         }
1057 1053
         if (count($g)) {
1058
-            $sql .= 'GROUP BY ' . $g[0] . ' ';
1054
+            $sql .= 'GROUP BY '.$g[0].' ';
1059 1055
             $par = array_merge($par, $g[1]);
1060 1056
         }
1061 1057
         if (count($h)) {
1062 1058
             $sql .= 'HAVING ';
1063 1059
             $tmp = [];
1064 1060
             foreach ($h as $v) {
1065
-                $tmp[] = '(' . $v[0] . ')';
1061
+                $tmp[] = '('.$v[0].')';
1066 1062
                 $par = array_merge($par, $v[1]);
1067 1063
             }
1068 1064
             $sql .= implode(' AND ', $tmp).' ';
1069 1065
         }
1070 1066
         $ordered = false;
1071 1067
         if (count($o)) {
1072
-            $sql .= 'ORDER BY ' . $o[0] . ' ';
1068
+            $sql .= 'ORDER BY '.$o[0].' ';
1073 1069
             $par = array_merge($par, $o[1]);
1074 1070
             $ordered = true;
1075 1071
         }
1076 1072
         if (!count($g) && count($porder)) {
1077 1073
             $pdir = (count($o) && strpos($o[0], 'DESC') !== false) ? 'DESC' : 'ASC';
1078
-            $porder = array_map(function ($v) use ($pdir) {
1079
-                return $v . ' ' . $pdir;
1074
+            $porder = array_map(function($v) use ($pdir) {
1075
+                return $v.' '.$pdir;
1080 1076
             }, $porder);
1081
-            $sql .= ($ordered ? ', ' : 'ORDER BY ') . implode(', ', $porder) . ' ';
1077
+            $sql .= ($ordered ? ', ' : 'ORDER BY ').implode(', ', $porder).' ';
1082 1078
             $ordered = true;
1083 1079
         }
1084 1080
         foreach ($this->withr as $k => $v) {
1085 1081
             if (isset($v[3])) {
1086
-                $sql .= ($ordered ? ', ' : 'ORDER BY ') . $getAlias($k) . '.' . $v[3] . ' ' . ($v[4] ? 'DESC' : 'ASC');
1082
+                $sql .= ($ordered ? ', ' : 'ORDER BY ').$getAlias($k).'.'.$v[3].' '.($v[4] ? 'DESC' : 'ASC');
1087 1083
                 $ordered = true;
1088 1084
             }
1089 1085
         }
1090 1086
         if ((!$many || $this->li_of[2] === 0 || !count($porder)) && $this->li_of[0]) {
1091 1087
             if ($this->db->driverName() === 'oracle') {
1092
-                if ((int)$this->db->driverOption('version', 0) >= 12) {
1093
-                    $sql .= 'OFFSET ' . $this->li_of[1] . ' ROWS FETCH NEXT ' . $this->li_of[0] . ' ROWS ONLY';
1088
+                if ((int) $this->db->driverOption('version', 0) >= 12) {
1089
+                    $sql .= 'OFFSET '.$this->li_of[1].' ROWS FETCH NEXT '.$this->li_of[0].' ROWS ONLY';
1094 1090
                 } else {
1095
-                    $f = array_map(function ($v) {
1091
+                    $f = array_map(function($v) {
1096 1092
                         $v = explode(' ', trim($v), 2);
1097 1093
                         if (count($v) === 2) {
1098 1094
                             return $v[1];
@@ -1100,16 +1096,16 @@  discard block
 block discarded – undo
1100 1096
                         $v = explode('.', $v[0], 2);
1101 1097
                         return count($v) === 2 ? $v[1] : $v[0];
1102 1098
                     }, $select);
1103
-                    $sql = "SELECT " . implode(', ', $f) . " 
1099
+                    $sql = "SELECT ".implode(', ', $f)." 
1104 1100
                             FROM (
1105 1101
                                 SELECT tbl__.*, rownum rnum__ FROM (
1106
-                                    " . $sql . "
1102
+                                    " . $sql."
1107 1103
                                 ) tbl__ 
1108
-                                WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1]) . "
1104
+                                WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1])."
1109 1105
                             ) WHERE rnum__ > " . $this->li_of[1];
1110 1106
                 }
1111 1107
             } else {
1112
-                $sql .= 'LIMIT ' . $this->li_of[0] . ' OFFSET ' . $this->li_of[1];
1108
+                $sql .= 'LIMIT '.$this->li_of[0].' OFFSET '.$this->li_of[1];
1113 1109
             }
1114 1110
         }
1115 1111
         return $this->qiterator = new TableQueryIterator(
@@ -1159,12 +1155,12 @@  discard block
 block discarded – undo
1159 1155
                 $ret[$k] = str_repeat(' ', 255);
1160 1156
                 $par[] = &$ret[$k];
1161 1157
             }
1162
-            $sql .= ' RETURNING ' . implode(',', $primary) .
1163
-                ' INTO ' . implode(',', array_fill(0, count($primary), '?'));
1158
+            $sql .= ' RETURNING '.implode(',', $primary).
1159
+                ' INTO '.implode(',', array_fill(0, count($primary), '?'));
1164 1160
             $this->db->query($sql, $par);
1165 1161
             return $ret;
1166 1162
         } elseif ($this->db->driverName() === 'postgre') {
1167
-            $sql .= ' RETURNING ' . implode(',', $primary);
1163
+            $sql .= ' RETURNING '.implode(',', $primary);
1168 1164
             return $this->db->one($sql, $par, false);
1169 1165
         } else {
1170 1166
             $ret = [];
@@ -1195,9 +1191,9 @@  discard block
 block discarded – undo
1195 1191
         }
1196 1192
         $sql = 'UPDATE '.$table.' SET ';
1197 1193
         $par = [];
1198
-        $sql .= implode(', ', array_map(function ($v) {
1199
-            return $v . ' = ?';
1200
-        }, array_keys($update))) . ' ';
1194
+        $sql .= implode(', ', array_map(function($v) {
1195
+            return $v.' = ?';
1196
+        }, array_keys($update))).' ';
1201 1197
         $par = array_merge($par, array_values($update));
1202 1198
         if (count($this->where)) {
1203 1199
             $sql .= 'WHERE ';
@@ -1206,7 +1202,7 @@  discard block
 block discarded – undo
1206 1202
                 $tmp[] = $v[0];
1207 1203
                 $par = array_merge($par, $v[1]);
1208 1204
             }
1209
-            $sql .= implode(' AND ', $tmp) . ' ';
1205
+            $sql .= implode(' AND ', $tmp).' ';
1210 1206
         }
1211 1207
         if (count($this->order)) {
1212 1208
             $sql .= $this->order[0];
@@ -1230,7 +1226,7 @@  discard block
 block discarded – undo
1230 1226
                 $tmp[] = $v[0];
1231 1227
                 $par = array_merge($par, $v[1]);
1232 1228
             }
1233
-            $sql .= implode(' AND ', $tmp) . ' ';
1229
+            $sql .= implode(' AND ', $tmp).' ';
1234 1230
         }
1235 1231
         if (count($this->order)) {
1236 1232
             $sql .= $this->order[0];
@@ -1249,21 +1245,21 @@  discard block
 block discarded – undo
1249 1245
         $table = $this->definition;
1250 1246
         if ($table->hasRelation($relation)) {
1251 1247
             $temp = $table->getRelation($relation);
1252
-            $this->withr[$relation] = [ $temp, $table->getName(), $select || ($this->withr[$relation][2] ?? false), $order, $desc ];
1248
+            $this->withr[$relation] = [$temp, $table->getName(), $select || ($this->withr[$relation][2] ?? false), $order, $desc];
1253 1249
         } else {
1254 1250
             $parts = explode('.', $relation);
1255 1251
             try {
1256 1252
                 $name = array_reduce(
1257 1253
                     $parts,
1258
-                    function ($carry, $item) use (&$table, $select) {
1254
+                    function($carry, $item) use (&$table, $select) {
1259 1255
                         if (!$table->hasRelation($item)) {
1260
-                            throw new DBException('Invalid relation name: '.$table->getName().' -> ' . $item);
1256
+                            throw new DBException('Invalid relation name: '.$table->getName().' -> '.$item);
1261 1257
                         }
1262 1258
                         $relation = $table->getRelation($item);
1263 1259
                         if (!$relation) {
1264
-                            throw new DBException('Invalid relation name: '.$table->getName().' -> ' . $item);
1260
+                            throw new DBException('Invalid relation name: '.$table->getName().' -> '.$item);
1265 1261
                         }
1266
-                        $name = $carry ? $carry . static::SEP . $item : $item;
1262
+                        $name = $carry ? $carry.static::SEP.$item : $item;
1267 1263
                         $this->withr[$name] = [
1268 1264
                             $relation,
1269 1265
                             $carry ?? $table->getName(),
@@ -1328,9 +1324,9 @@  discard block
 block discarded – undo
1328 1324
 
1329 1325
         $aliases = [];
1330 1326
         $aliases_ext = [];
1331
-        $getAlias = function ($name) use (&$aliases, &$aliases_ext) {
1327
+        $getAlias = function($name) use (&$aliases, &$aliases_ext) {
1332 1328
             // to bypass use: return $name;
1333
-            $aliases[$name] = $aliases[$name] ?? 'alias' . static::SEP . count($aliases);
1329
+            $aliases[$name] = $aliases[$name] ?? 'alias'.static::SEP.count($aliases);
1334 1330
             if (isset($aliases_ext[$name])) {
1335 1331
                 unset($aliases_ext[$name]);
1336 1332
             }
@@ -1350,7 +1346,7 @@  discard block
 block discarded – undo
1350 1346
         $w = $this->where;
1351 1347
         $h = $this->having;
1352 1348
         $o = $this->order;
1353
-        $j = array_map(function ($v) {
1349
+        $j = array_map(function($v) {
1354 1350
             return clone $v;
1355 1351
         }, $this->joins);
1356 1352
 
@@ -1359,24 +1355,24 @@  discard block
 block discarded – undo
1359 1355
                 continue;
1360 1356
             }
1361 1357
             foreach ($w as $kk => $v) {
1362
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) {
1363
-                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $v[0]);
1358
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) {
1359
+                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $v[0]);
1364 1360
                 }
1365 1361
             }
1366 1362
             foreach ($h as $kk => $v) {
1367
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) {
1368
-                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $v[0]);
1363
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) {
1364
+                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $v[0]);
1369 1365
                 }
1370 1366
             }
1371
-            if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) {
1372
-                $o[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $o[0]);
1367
+            if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) {
1368
+                $o[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $o[0]);
1373 1369
             }
1374 1370
             foreach ($j as $kk => $v) {
1375 1371
                 foreach ($v->keymap as $kkk => $vv) {
1376
-                    if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv)) {
1372
+                    if (preg_match('(\b'.preg_quote($k.'.').')i', $vv)) {
1377 1373
                         $j[$kk]->keymap[$kkk] = preg_replace(
1378
-                            '(\b'.preg_quote($k . '.'). ')i',
1379
-                            $getAlias($k) . '.',
1374
+                            '(\b'.preg_quote($k.'.').')i',
1375
+                            $getAlias($k).'.',
1380 1376
                             $vv
1381 1377
                         );
1382 1378
                     }
@@ -1385,52 +1381,52 @@  discard block
 block discarded – undo
1385 1381
         }
1386 1382
         foreach ($this->definition->getRelations() as $k => $v) {
1387 1383
             foreach ($w as $kk => $vv) {
1388
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv[0])) {
1389
-                    $relations[$k] = [ $v, $table ];
1390
-                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vv[0]);
1384
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $vv[0])) {
1385
+                    $relations[$k] = [$v, $table];
1386
+                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vv[0]);
1391 1387
                 }
1392 1388
             }
1393
-            if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) {
1394
-                $relations[$k] = [ $v, $table ];
1395
-                $o[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $o[0]);
1396
-                $o[2] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $o[2]);
1389
+            if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) {
1390
+                $relations[$k] = [$v, $table];
1391
+                $o[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $o[0]);
1392
+                $o[2] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $o[2]);
1397 1393
             }
1398 1394
             foreach ($h as $kk => $vv) {
1399
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv[0])) {
1400
-                    $relations[$k] = [ $v, $table ];
1401
-                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vv[0]);
1395
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $vv[0])) {
1396
+                    $relations[$k] = [$v, $table];
1397
+                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vv[0]);
1402 1398
                 }
1403 1399
             }
1404 1400
             foreach ($j as $kk => $vv) {
1405 1401
                 foreach ($vv->keymap as $kkk => $vvv) {
1406
-                    if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vvv)) {
1407
-                        $relations[$k] = [ $v, $table ];
1402
+                    if (preg_match('(\b'.preg_quote($k.'.').')i', $vvv)) {
1403
+                        $relations[$k] = [$v, $table];
1408 1404
                         $j[$kk]->keymap[$kkk] =
1409
-                            preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vvv);
1405
+                            preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vvv);
1410 1406
                     }
1411 1407
                 }
1412 1408
             }
1413 1409
         }
1414 1410
         foreach ($aliases_ext as $k => $alias) {
1415 1411
             foreach ($w as $kk => $v) {
1416
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) {
1417
-                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $alias . '.', $v[0]);
1412
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) {
1413
+                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $alias.'.', $v[0]);
1418 1414
                 }
1419 1415
             }
1420 1416
             foreach ($h as $kk => $v) {
1421
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) {
1422
-                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $alias . '.', $v[0]);
1417
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) {
1418
+                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $alias.'.', $v[0]);
1423 1419
                 }
1424 1420
             }
1425
-            if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) {
1426
-                $o[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $alias . '.', $o[0]);
1421
+            if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) {
1422
+                $o[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $alias.'.', $o[0]);
1427 1423
             }
1428 1424
             foreach ($j as $kk => $v) {
1429 1425
                 foreach ($v->keymap as $kkk => $vv) {
1430
-                    if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv)) {
1426
+                    if (preg_match('(\b'.preg_quote($k.'.').')i', $vv)) {
1431 1427
                         $j[$kk]->keymap[$kkk] = preg_replace(
1432
-                            '(\b'.preg_quote($k . '.'). ')i',
1433
-                            $alias . '.',
1428
+                            '(\b'.preg_quote($k.'.').')i',
1429
+                            $alias.'.',
1434 1430
                             $vv
1435 1431
                         );
1436 1432
                     }
@@ -1438,29 +1434,29 @@  discard block
 block discarded – undo
1438 1434
             }
1439 1435
         }
1440 1436
 
1441
-        $key = array_map(function ($v) use ($table) {
1442
-            return $table . '.' . $v;
1437
+        $key = array_map(function($v) use ($table) {
1438
+            return $table.'.'.$v;
1443 1439
         }, $this->pkey);
1444 1440
         $own = false;
1445 1441
         $dir = 'ASC';
1446 1442
         if (count($o)) {
1447 1443
             $dir = strpos($o[0], ' DESC') ? 'DESC' : 'ASC';
1448
-            $own = strpos($o[2], $table . '.') === 0;
1444
+            $own = strpos($o[2], $table.'.') === 0;
1449 1445
         }
1450 1446
 
1451 1447
         $dst = $key;
1452 1448
         if (count($o)) {
1453 1449
             if ($own) {
1454 1450
                 // if using own table - do not use max/min in order - that will prevent index usage
1455
-                $dst[] = $o[2] . ' orderbyfix___';
1451
+                $dst[] = $o[2].' orderbyfix___';
1456 1452
             } else {
1457
-                $dst[] = 'MAX(' . $o[2] . ') orderbyfix___';
1453
+                $dst[] = 'MAX('.$o[2].') orderbyfix___';
1458 1454
             }
1459 1455
         }
1460 1456
         $dst = array_unique($dst);
1461 1457
 
1462 1458
         $par = [];
1463
-        $sql  = 'SELECT DISTINCT '.implode(', ', $dst).' FROM '.$this->definition->getFullName().' ';
1459
+        $sql = 'SELECT DISTINCT '.implode(', ', $dst).' FROM '.$this->definition->getFullName().' ';
1464 1460
         foreach ($relations as $k => $v) {
1465 1461
             $table = $v[1] !== $this->definition->getName() ? $getAlias($v[1]) : $v[1];
1466 1462
             $v = $v[0];
@@ -1471,13 +1467,13 @@  discard block
 block discarded – undo
1471 1467
                 foreach ($v->keymap as $kk => $vv) {
1472 1468
                     $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' ';
1473 1469
                 }
1474
-                $sql .= implode(' AND ', $tmp) . ' ';
1470
+                $sql .= implode(' AND ', $tmp).' ';
1475 1471
                 $sql .= 'LEFT JOIN '.$v->table->getName().' '.$getAlias($k).' ON ';
1476 1472
                 $tmp = [];
1477 1473
                 foreach ($v->pivot_keymap as $kk => $vv) {
1478 1474
                     $tmp[] = $getAlias($k).'.'.$vv.' = '.$alias.'.'.$kk.' ';
1479 1475
                 }
1480
-                $sql .= implode(' AND ', $tmp) . ' ';
1476
+                $sql .= implode(' AND ', $tmp).' ';
1481 1477
             } else {
1482 1478
                 $alias = $getAlias($k);
1483 1479
                 $sql .= 'LEFT JOIN '.$v->table->getName().' '.$alias.' ON ';
@@ -1486,37 +1482,37 @@  discard block
 block discarded – undo
1486 1482
                     $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' ';
1487 1483
                 }
1488 1484
                 if ($v->sql) {
1489
-                    $tmp[] = $v->sql . ' ';
1485
+                    $tmp[] = $v->sql.' ';
1490 1486
                     $par = array_merge($par, $v->par ?? []);
1491 1487
                 }
1492
-                $sql .= implode(' AND ', $tmp) . ' ';
1488
+                $sql .= implode(' AND ', $tmp).' ';
1493 1489
             }
1494 1490
         }
1495 1491
         foreach ($j as $k => $v) {
1496
-            $sql .= ($v->many ? 'LEFT ' : '' ) . 'JOIN '.$v->table->getName().' '.$k.' ON ';
1492
+            $sql .= ($v->many ? 'LEFT ' : '').'JOIN '.$v->table->getName().' '.$k.' ON ';
1497 1493
             $tmp = [];
1498 1494
             foreach ($v->keymap as $kk => $vv) {
1499 1495
                 $tmp[] = $kk.' = '.$vv;
1500 1496
             }
1501
-            $sql .= implode(' AND ', $tmp) . ' ';
1497
+            $sql .= implode(' AND ', $tmp).' ';
1502 1498
         }
1503 1499
         if (count($w)) {
1504 1500
             $sql .= 'WHERE ';
1505 1501
             $tmp = [];
1506 1502
             foreach ($w as $v) {
1507
-                $tmp[] = '(' . $v[0] . ')';
1503
+                $tmp[] = '('.$v[0].')';
1508 1504
                 $par = array_merge($par, $v[1]);
1509 1505
             }
1510 1506
             $sql .= implode(' AND ', $tmp).' ';
1511 1507
         }
1512 1508
         if (!$own) {
1513
-            $sql .= 'GROUP BY ' . implode(', ', $key) . ' ';
1509
+            $sql .= 'GROUP BY '.implode(', ', $key).' ';
1514 1510
         }
1515 1511
         if (count($h)) {
1516 1512
             $sql .= 'HAVING ';
1517 1513
             $tmp = [];
1518 1514
             foreach ($h as $v) {
1519
-                $tmp[] = '(' . $v[0] . ')';
1515
+                $tmp[] = '('.$v[0].')';
1520 1516
                 $par = array_merge($par, $v[1]);
1521 1517
             }
1522 1518
             $sql .= implode(' AND ', $tmp).' ';
@@ -1524,38 +1520,38 @@  discard block
 block discarded – undo
1524 1520
         if (count($o)) {
1525 1521
             $sql .= 'ORDER BY ';
1526 1522
             if ($own) {
1527
-                $sql .= $o[2] . ' ' . $dir;
1523
+                $sql .= $o[2].' '.$dir;
1528 1524
             } else {
1529
-                $sql .= 'MAX('.$o[2].') ' . $dir;
1525
+                $sql .= 'MAX('.$o[2].') '.$dir;
1530 1526
             }
1531 1527
         }
1532 1528
         $porder = [];
1533 1529
         $pdir = (count($o) && strpos($o[0], 'DESC') !== false) ? 'DESC' : 'ASC';
1534 1530
         foreach ($this->definition->getPrimaryKey() as $field) {
1535
-            $porder[] = $this->getColumn($field)['name'] . ' ' . $pdir;
1531
+            $porder[] = $this->getColumn($field)['name'].' '.$pdir;
1536 1532
         }
1537 1533
         if (count($porder)) {
1538
-            $sql .= (count($o) ? ', ' : 'ORDER BY ') . implode(', ', $porder) . ' ';
1534
+            $sql .= (count($o) ? ', ' : 'ORDER BY ').implode(', ', $porder).' ';
1539 1535
         }
1540 1536
 
1541 1537
         if ($this->li_of[0]) {
1542 1538
             if ($this->db->driverName() === 'oracle') {
1543
-                if ((int)$this->db->driverOption('version', 0) >= 12) {
1544
-                    $sql .= 'OFFSET ' . $this->li_of[1] . ' ROWS FETCH NEXT ' . $this->li_of[0] . ' ROWS ONLY';
1539
+                if ((int) $this->db->driverOption('version', 0) >= 12) {
1540
+                    $sql .= 'OFFSET '.$this->li_of[1].' ROWS FETCH NEXT '.$this->li_of[0].' ROWS ONLY';
1545 1541
                 } else {
1546
-                    $sql = "SELECT " . implode(', ', $dst) . " 
1542
+                    $sql = "SELECT ".implode(', ', $dst)." 
1547 1543
                             FROM (
1548 1544
                                 SELECT tbl__.*, rownum rnum__ FROM (
1549
-                                    " . $sql . "
1545
+                                    " . $sql."
1550 1546
                                 ) tbl__ 
1551
-                                WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1]) . "
1547
+                                WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1])."
1552 1548
                             ) WHERE rnum__ > " . $this->li_of[1];
1553 1549
                 }
1554 1550
             } else {
1555
-                $sql .= 'LIMIT ' . $this->li_of[0] . ' OFFSET ' . $this->li_of[1];
1551
+                $sql .= 'LIMIT '.$this->li_of[0].' OFFSET '.$this->li_of[1];
1556 1552
             }
1557 1553
         }
1558
-        return array_map(function ($v) {
1554
+        return array_map(function($v) {
1559 1555
             if (array_key_exists('orderbyfix___', $v)) {
1560 1556
                 unset($v['orderbyfix___']);
1561 1557
             }
Please login to merge, or discard this patch.
src/schema/TableQueryMapped.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@
 block discarded – undo
14 14
     protected static array $mappers = [];
15 15
     protected MapperInterface $mapper;
16 16
 
17
-    public function __construct(DBInterface $db, Table|string $table, bool $findRelations = false)
17
+    public function __construct(DBInterface $db, Table | string $table, bool $findRelations = false)
18 18
     {
19 19
         parent::__construct($db, $table, $findRelations);
20 20
         if (!isset(static::$mappers[spl_object_hash($db)])) {
Please login to merge, or discard this patch.