@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | * @param string|Select $table |
113 | 113 | * @param string[] $columns |
114 | 114 | */ |
115 | - public function __construct (DB $db, $table, array $columns) { |
|
115 | + public function __construct(DB $db, $table, array $columns) { |
|
116 | 116 | parent::__construct($db); |
117 | 117 | if ($table instanceof Select) { |
118 | 118 | $this->table = $table->toSubquery(); |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | * @param array $args |
133 | 133 | * @return Statement |
134 | 134 | */ |
135 | - public function __invoke (array $args = []) { |
|
135 | + public function __invoke(array $args = []) { |
|
136 | 136 | return $this->execute($args); |
137 | 137 | } |
138 | 138 | |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | * |
142 | 142 | * @return string |
143 | 143 | */ |
144 | - final public function __toString () { |
|
144 | + final public function __toString() { |
|
145 | 145 | return $this->alias; |
146 | 146 | } |
147 | 147 | |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | * @param array $args Execution arguments. |
152 | 152 | * @return int |
153 | 153 | */ |
154 | - public function count (array $args = []): int { |
|
154 | + public function count(array $args = []): int { |
|
155 | 155 | $clone = clone $this; |
156 | 156 | $clone->_columns = 'COUNT(*)'; |
157 | 157 | $clone->_order = ''; |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | * @param array $args |
165 | 165 | * @return Statement |
166 | 166 | */ |
167 | - public function execute (array $args = []) { |
|
167 | + public function execute(array $args = []) { |
|
168 | 168 | if (empty($args)) { |
169 | 169 | return $this->db->query($this->toSql()); |
170 | 170 | } |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | * @param array $args Execution arguments. |
180 | 180 | * @return array |
181 | 181 | */ |
182 | - public function getAll (array $args = []): array { |
|
182 | + public function getAll(array $args = []): array { |
|
183 | 183 | return iterator_to_array($this->fetcher->__invoke($this->execute($args))); |
184 | 184 | } |
185 | 185 | |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | * @param array $args Execution arguments. |
193 | 193 | * @return Generator |
194 | 194 | */ |
195 | - public function getEach (array $args = []) { |
|
195 | + public function getEach(array $args = []) { |
|
196 | 196 | yield from $this->fetcher->__invoke($this->execute($args)); |
197 | 197 | } |
198 | 198 | |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | * @param array $args |
205 | 205 | * @return mixed |
206 | 206 | */ |
207 | - public function getFirst (array $args = []) { |
|
207 | + public function getFirst(array $args = []) { |
|
208 | 208 | return $this->getEach($args)->current(); |
209 | 209 | } |
210 | 210 | |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | * |
216 | 216 | * @return Generator |
217 | 217 | */ |
218 | - public function getIterator () { |
|
218 | + public function getIterator() { |
|
219 | 219 | yield from $this->getEach(); |
220 | 220 | } |
221 | 221 | |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | * @param string $column |
226 | 226 | * @return $this |
227 | 227 | */ |
228 | - public function group (string $column) { |
|
228 | + public function group(string $column) { |
|
229 | 229 | if (!strlen($this->_group)) { |
230 | 230 | $this->_group = " GROUP BY {$column}"; |
231 | 231 | } |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | * @param string $condition |
242 | 242 | * @return $this |
243 | 243 | */ |
244 | - public function having (string $condition) { |
|
244 | + public function having(string $condition) { |
|
245 | 245 | if (!strlen($this->_having)) { |
246 | 246 | $this->_having = " HAVING {$condition}"; |
247 | 247 | } |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | * @param bool $all |
259 | 259 | * @return $this |
260 | 260 | */ |
261 | - public function intersect (Select $select, $all = false) { |
|
261 | + public function intersect(Select $select, $all = false) { |
|
262 | 262 | $select = clone $select; |
263 | 263 | $select->_order = ''; |
264 | 264 | $select->_limit = ''; |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | * |
277 | 277 | * @return Predicate |
278 | 278 | */ |
279 | - public function isEmpty () { |
|
279 | + public function isEmpty() { |
|
280 | 280 | return new Predicate("NOT EXISTS ({$this->toSql()})"); |
281 | 281 | } |
282 | 282 | |
@@ -285,7 +285,7 @@ discard block |
||
285 | 285 | * |
286 | 286 | * @return Predicate |
287 | 287 | */ |
288 | - public function isNotEmpty () { |
|
288 | + public function isNotEmpty() { |
|
289 | 289 | return new Predicate("EXISTS ({$this->toSql()})"); |
290 | 290 | } |
291 | 291 | |
@@ -297,7 +297,7 @@ discard block |
||
297 | 297 | * @param string $type |
298 | 298 | * @return $this |
299 | 299 | */ |
300 | - public function join ($table, string $condition, string $type = 'INNER') { |
|
300 | + public function join($table, string $condition, string $type = 'INNER') { |
|
301 | 301 | if ($table instanceof Select) { |
302 | 302 | $table = $table->toSubquery(); |
303 | 303 | } |
@@ -312,7 +312,7 @@ discard block |
||
312 | 312 | * @param int $offset |
313 | 313 | * @return $this |
314 | 314 | */ |
315 | - public function limit (int $limit, int $offset = 0) { |
|
315 | + public function limit(int $limit, int $offset = 0) { |
|
316 | 316 | if ($limit == 0) { |
317 | 317 | $this->_limit = ''; |
318 | 318 | } |
@@ -331,7 +331,7 @@ discard block |
||
331 | 331 | * @param mixed $offset Ordinal or reference name. |
332 | 332 | * @return bool |
333 | 333 | */ |
334 | - public function offsetExists ($offset): bool { |
|
334 | + public function offsetExists($offset): bool { |
|
335 | 335 | return isset($this->refs[$offset]); |
336 | 336 | } |
337 | 337 | |
@@ -341,7 +341,7 @@ discard block |
||
341 | 341 | * @param mixed $offset Ordinal or reference name. |
342 | 342 | * @return Column |
343 | 343 | */ |
344 | - public function offsetGet ($offset) { |
|
344 | + public function offsetGet($offset) { |
|
345 | 345 | return $this->refs[$offset]; |
346 | 346 | } |
347 | 347 | |
@@ -351,7 +351,7 @@ discard block |
||
351 | 351 | * @param string $order |
352 | 352 | * @return $this |
353 | 353 | */ |
354 | - public function order (string $order) { |
|
354 | + public function order(string $order) { |
|
355 | 355 | if (strlen($order)) { |
356 | 356 | $order = " ORDER BY {$order}"; |
357 | 357 | } |
@@ -362,7 +362,7 @@ discard block |
||
362 | 362 | /** |
363 | 363 | * @return Statement |
364 | 364 | */ |
365 | - public function prepare () { |
|
365 | + public function prepare() { |
|
366 | 366 | return $this->db->prepare($this->toSql()); |
367 | 367 | } |
368 | 368 | |
@@ -370,7 +370,7 @@ discard block |
||
370 | 370 | * @param string $alias |
371 | 371 | * @return $this |
372 | 372 | */ |
373 | - public function setAlias (string $alias) { |
|
373 | + public function setAlias(string $alias) { |
|
374 | 374 | $this->alias = $alias; |
375 | 375 | return $this; |
376 | 376 | } |
@@ -381,7 +381,7 @@ discard block |
||
381 | 381 | * @param string[] $columns |
382 | 382 | * @return $this |
383 | 383 | */ |
384 | - public function setColumns (array $columns) { |
|
384 | + public function setColumns(array $columns) { |
|
385 | 385 | $this->refs = []; |
386 | 386 | $_columns = []; |
387 | 387 | $i = 0; |
@@ -410,7 +410,7 @@ discard block |
||
410 | 410 | * @param Closure $fetcher |
411 | 411 | * @return $this |
412 | 412 | */ |
413 | - public function setFetcher (Closure $fetcher) { |
|
413 | + public function setFetcher(Closure $fetcher) { |
|
414 | 414 | $this->fetcher = $fetcher; |
415 | 415 | return $this; |
416 | 416 | } |
@@ -420,7 +420,7 @@ discard block |
||
420 | 420 | * |
421 | 421 | * @return string |
422 | 422 | */ |
423 | - public function toSql (): string { |
|
423 | + public function toSql(): string { |
|
424 | 424 | $sql = "SELECT {$this->_columns} FROM {$this->table}"; |
425 | 425 | $sql .= $this->_join; |
426 | 426 | $sql .= $this->_where; |
@@ -437,7 +437,7 @@ discard block |
||
437 | 437 | * |
438 | 438 | * @return string |
439 | 439 | */ |
440 | - public function toSubquery (): string { |
|
440 | + public function toSubquery(): string { |
|
441 | 441 | return "({$this->toSql()}) AS {$this->alias}"; |
442 | 442 | } |
443 | 443 | |
@@ -448,7 +448,7 @@ discard block |
||
448 | 448 | * @param bool $all |
449 | 449 | * @return $this |
450 | 450 | */ |
451 | - public function union (Select $select, $all = false) { |
|
451 | + public function union(Select $select, $all = false) { |
|
452 | 452 | $select = clone $select; |
453 | 453 | $select->_order = ''; |
454 | 454 | $select->_limit = ''; |
@@ -467,7 +467,7 @@ discard block |
||
467 | 467 | * @param string $condition |
468 | 468 | * @return $this |
469 | 469 | */ |
470 | - public function where (string $condition) { |
|
470 | + public function where(string $condition) { |
|
471 | 471 | if (!strlen($this->_where)) { |
472 | 472 | $this->_where = " WHERE {$condition}"; |
473 | 473 | } |
@@ -117,8 +117,7 @@ discard block |
||
117 | 117 | if ($table instanceof Select) { |
118 | 118 | $this->table = $table->toSubquery(); |
119 | 119 | $this->alias = uniqid('_') . "_{$table->alias}"; |
120 | - } |
|
121 | - else { |
|
120 | + } else { |
|
122 | 121 | $this->table = (string)$table; |
123 | 122 | $this->alias = uniqid('_') . "__{$table}"; |
124 | 123 | } |
@@ -228,8 +227,7 @@ discard block |
||
228 | 227 | public function group (string $column) { |
229 | 228 | if (!strlen($this->_group)) { |
230 | 229 | $this->_group = " GROUP BY {$column}"; |
231 | - } |
|
232 | - else { |
|
230 | + } else { |
|
233 | 231 | $this->_group .= ", {$column}"; |
234 | 232 | } |
235 | 233 | return $this; |
@@ -244,8 +242,7 @@ discard block |
||
244 | 242 | public function having (string $condition) { |
245 | 243 | if (!strlen($this->_having)) { |
246 | 244 | $this->_having = " HAVING {$condition}"; |
247 | - } |
|
248 | - else { |
|
245 | + } else { |
|
249 | 246 | $this->_having .= " AND {$condition}"; |
250 | 247 | } |
251 | 248 | return $this; |
@@ -264,8 +261,7 @@ discard block |
||
264 | 261 | $select->_limit = ''; |
265 | 262 | if ($all) { |
266 | 263 | $this->_import .= " INTERSECT ALL {$select->toSql()}"; |
267 | - } |
|
268 | - else { |
|
264 | + } else { |
|
269 | 265 | $this->_import .= " INTERSECT {$select->toSql()}"; |
270 | 266 | } |
271 | 267 | return $this; |
@@ -315,8 +311,7 @@ discard block |
||
315 | 311 | public function limit (int $limit, int $offset = 0) { |
316 | 312 | if ($limit == 0) { |
317 | 313 | $this->_limit = ''; |
318 | - } |
|
319 | - else { |
|
314 | + } else { |
|
320 | 315 | $this->_limit = " LIMIT {$limit}"; |
321 | 316 | if ($offset > 1) { |
322 | 317 | $this->_limit .= " OFFSET {$offset}"; |
@@ -454,8 +449,7 @@ discard block |
||
454 | 449 | $select->_limit = ''; |
455 | 450 | if ($all) { |
456 | 451 | $this->_import .= " UNION ALL {$select->toSql()}"; |
457 | - } |
|
458 | - else { |
|
452 | + } else { |
|
459 | 453 | $this->_import .= " UNION {$select->toSql()}"; |
460 | 454 | } |
461 | 455 | return $this; |
@@ -470,8 +464,7 @@ discard block |
||
470 | 464 | public function where (string $condition) { |
471 | 465 | if (!strlen($this->_where)) { |
472 | 466 | $this->_where = " WHERE {$condition}"; |
473 | - } |
|
474 | - else { |
|
467 | + } else { |
|
475 | 468 | $this->_where .= " AND {$condition}"; |
476 | 469 | } |
477 | 470 | return $this; |