@@ -137,8 +137,7 @@ discard block |
||
137 | 137 | if ($this->transactions === 0) { |
138 | 138 | $this->logger->__invoke("BEGIN TRANSACTION"); |
139 | 139 | parent::beginTransaction(); |
140 | - } |
|
141 | - else { |
|
140 | + } else { |
|
142 | 141 | $this->exec("SAVEPOINT SAVEPOINT_{$this->transactions}"); |
143 | 142 | } |
144 | 143 | $this->transactions++; |
@@ -157,8 +156,7 @@ discard block |
||
157 | 156 | if ($this->transactions === 1) { |
158 | 157 | $this->logger->__invoke("COMMIT TRANSACTION"); |
159 | 158 | parent::commit(); |
160 | - } |
|
161 | - else { |
|
159 | + } else { |
|
162 | 160 | $savepoint = $this->transactions - 1; |
163 | 161 | $this->exec("RELEASE SAVEPOINT SAVEPOINT_{$savepoint}"); |
164 | 162 | } |
@@ -238,8 +236,7 @@ discard block |
||
238 | 236 | if ($this->isSQLite()) { |
239 | 237 | $info = $this->query("PRAGMA table_info({$this->quote($name)})")->fetchAll(); |
240 | 238 | $cols = array_column($info, 'name'); |
241 | - } |
|
242 | - else { |
|
239 | + } else { |
|
243 | 240 | $cols = $this->query( |
244 | 241 | "SELECT column_name FROM information_schema.tables WHERE table_name = {$this->quote($name)}" |
245 | 242 | )->fetchAll(self::FETCH_COLUMN); |
@@ -457,8 +454,7 @@ discard block |
||
457 | 454 | if ($this->transactions === 1) { |
458 | 455 | $this->logger->__invoke("ROLLBACK TRANSACTION"); |
459 | 456 | parent::rollBack(); |
460 | - } |
|
461 | - else { |
|
457 | + } else { |
|
462 | 458 | $savepoint = $this->transactions - 1; |
463 | 459 | $this->exec("ROLLBACK TO SAVEPOINT SAVEPOINT_{$savepoint}"); |
464 | 460 | } |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | * @param string $file |
70 | 70 | * @return static |
71 | 71 | */ |
72 | - public static function fromConfig (string $connection = 'default', string $file = 'db.config.php') { |
|
72 | + public static function fromConfig(string $connection = 'default', string $file = 'db.config.php') { |
|
73 | 73 | $config = (include "{$file}")[$connection]; |
74 | 74 | return new static($config['dsn'], $config['username'] ?? null, $config['password'] ?? null, $config['options'] ?? []); |
75 | 75 | } |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | * @param string $password |
85 | 85 | * @param array $options |
86 | 86 | */ |
87 | - public function __construct ($dsn, $username = null, $password = null, array $options = []) { |
|
87 | + public function __construct($dsn, $username = null, $password = null, array $options = []) { |
|
88 | 88 | $options[self::ATTR_STATEMENT_CLASS] ??= [Statement::class, [$this]]; |
89 | 89 | parent::__construct($dsn, $username, $password, $options); |
90 | 90 | $this->setAttribute(self::ATTR_DEFAULT_FETCH_MODE, self::FETCH_ASSOC); |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | |
97 | 97 | if ($this->isSQLite()) { |
98 | 98 | // polyfill sqlite functions |
99 | - $this->sqliteCreateFunctions([ // deterministic functions |
|
99 | + $this->sqliteCreateFunctions([// deterministic functions |
|
100 | 100 | // https://www.sqlite.org/lang_mathfunc.html |
101 | 101 | 'ACOS' => 'acos', |
102 | 102 | 'ASIN' => 'asin', |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | 'SIGN' => fn($x) => ($x > 0) - ($x < 0), |
123 | 123 | ]); |
124 | 124 | |
125 | - $this->sqliteCreateFunctions([ // non-deterministic |
|
125 | + $this->sqliteCreateFunctions([// non-deterministic |
|
126 | 126 | 'RAND' => fn() => mt_rand() / mt_getrandmax(), |
127 | 127 | ], false); |
128 | 128 | } |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | * |
134 | 134 | * @return string |
135 | 135 | */ |
136 | - final public function __toString () { |
|
136 | + final public function __toString() { |
|
137 | 137 | return $this->driver; |
138 | 138 | } |
139 | 139 | |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | * |
145 | 145 | * @return true |
146 | 146 | */ |
147 | - public function beginTransaction () { |
|
147 | + public function beginTransaction() { |
|
148 | 148 | assert($this->transactions >= 0); |
149 | 149 | if ($this->transactions === 0) { |
150 | 150 | $this->logger->__invoke("BEGIN TRANSACTION"); |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | * |
165 | 165 | * @return true |
166 | 166 | */ |
167 | - public function commit () { |
|
167 | + public function commit() { |
|
168 | 168 | assert($this->transactions > 0); |
169 | 169 | if ($this->transactions === 1) { |
170 | 170 | $this->logger->__invoke("COMMIT TRANSACTION"); |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | * @param string $sql |
185 | 185 | * @return int |
186 | 186 | */ |
187 | - public function exec ($sql): int { |
|
187 | + public function exec($sql): int { |
|
188 | 188 | $this->logger->__invoke($sql); |
189 | 189 | return parent::exec($sql); |
190 | 190 | } |
@@ -200,14 +200,14 @@ discard block |
||
200 | 200 | * @param mixed ...$args |
201 | 201 | * @return mixed |
202 | 202 | */ |
203 | - public function factory (string $class, ...$args) { |
|
203 | + public function factory(string $class, ...$args) { |
|
204 | 204 | return new $class($this, ...$args); |
205 | 205 | } |
206 | 206 | |
207 | 207 | /** |
208 | 208 | * @return string |
209 | 209 | */ |
210 | - final public function getDriver (): string { |
|
210 | + final public function getDriver(): string { |
|
211 | 211 | return $this->driver; |
212 | 212 | } |
213 | 213 | |
@@ -217,14 +217,14 @@ discard block |
||
217 | 217 | * @param string $interface |
218 | 218 | * @return Junction |
219 | 219 | */ |
220 | - public function getJunction ($interface) { |
|
220 | + public function getJunction($interface) { |
|
221 | 221 | return $this->junctions[$interface] ??= Junction::fromInterface($this, $interface); |
222 | 222 | } |
223 | 223 | |
224 | 224 | /** |
225 | 225 | * @return Closure |
226 | 226 | */ |
227 | - public function getLogger () { |
|
227 | + public function getLogger() { |
|
228 | 228 | return $this->logger; |
229 | 229 | } |
230 | 230 | |
@@ -234,7 +234,7 @@ discard block |
||
234 | 234 | * @param string|EntityInterface $class |
235 | 235 | * @return Record |
236 | 236 | */ |
237 | - public function getRecord ($class) { |
|
237 | + public function getRecord($class) { |
|
238 | 238 | if (is_object($class)) { |
239 | 239 | $class = get_class($class); |
240 | 240 | } |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | * @param string $name |
246 | 246 | * @return null|Table |
247 | 247 | */ |
248 | - public function getTable (string $name) { |
|
248 | + public function getTable(string $name) { |
|
249 | 249 | if (!isset($this->tables[$name])) { |
250 | 250 | if ($this->isSQLite()) { |
251 | 251 | $info = $this->query("PRAGMA table_info({$this->quote($name)})")->fetchAll(); |
@@ -267,21 +267,21 @@ discard block |
||
267 | 267 | /** |
268 | 268 | * @return bool |
269 | 269 | */ |
270 | - final public function isMySQL (): bool { |
|
270 | + final public function isMySQL(): bool { |
|
271 | 271 | return $this->driver === 'mysql'; |
272 | 272 | } |
273 | 273 | |
274 | 274 | /** |
275 | 275 | * @return bool |
276 | 276 | */ |
277 | - final public function isPostgreSQL (): bool { |
|
277 | + final public function isPostgreSQL(): bool { |
|
278 | 278 | return $this->driver === 'pgsql'; |
279 | 279 | } |
280 | 280 | |
281 | 281 | /** |
282 | 282 | * @return bool |
283 | 283 | */ |
284 | - final public function isSQLite (): bool { |
|
284 | + final public function isSQLite(): bool { |
|
285 | 285 | return $this->driver === 'sqlite'; |
286 | 286 | } |
287 | 287 | |
@@ -302,7 +302,7 @@ discard block |
||
302 | 302 | * @param mixed $b |
303 | 303 | * @return Predicate |
304 | 304 | */ |
305 | - public function match ($a, $b) { |
|
305 | + public function match($a, $b) { |
|
306 | 306 | if ($b instanceof Closure) { |
307 | 307 | return $b->__invoke($a, $this); |
308 | 308 | } |
@@ -323,7 +323,7 @@ discard block |
||
323 | 323 | * |
324 | 324 | * @return Transaction |
325 | 325 | */ |
326 | - public function newTransaction () { |
|
326 | + public function newTransaction() { |
|
327 | 327 | return Transaction::factory($this); |
328 | 328 | } |
329 | 329 | |
@@ -333,7 +333,7 @@ discard block |
||
333 | 333 | * @param string $table |
334 | 334 | * @return bool |
335 | 335 | */ |
336 | - final public function offsetExists ($table): bool { |
|
336 | + final public function offsetExists($table): bool { |
|
337 | 337 | return (bool)$this->getTable($table); |
338 | 338 | } |
339 | 339 | |
@@ -343,7 +343,7 @@ discard block |
||
343 | 343 | * @param string $table |
344 | 344 | * @return null|Table |
345 | 345 | */ |
346 | - final public function offsetGet ($table) { |
|
346 | + final public function offsetGet($table) { |
|
347 | 347 | return $this->getTable($table); |
348 | 348 | } |
349 | 349 | |
@@ -352,7 +352,7 @@ discard block |
||
352 | 352 | * @param $value |
353 | 353 | * @throws LogicException |
354 | 354 | */ |
355 | - final public function offsetSet ($offset, $value) { |
|
355 | + final public function offsetSet($offset, $value) { |
|
356 | 356 | throw new LogicException('Raw table access is immutable.'); |
357 | 357 | } |
358 | 358 | |
@@ -360,7 +360,7 @@ discard block |
||
360 | 360 | * @param $offset |
361 | 361 | * @throws LogicException |
362 | 362 | */ |
363 | - final public function offsetUnset ($offset) { |
|
363 | + final public function offsetUnset($offset) { |
|
364 | 364 | throw new LogicException('Raw table access is immutable.'); |
365 | 365 | } |
366 | 366 | |
@@ -369,7 +369,7 @@ discard block |
||
369 | 369 | * |
370 | 370 | * @return Num |
371 | 371 | */ |
372 | - public function pi () { |
|
372 | + public function pi() { |
|
373 | 373 | return Num::factory($this, "PI()"); |
374 | 374 | } |
375 | 375 | |
@@ -380,7 +380,7 @@ discard block |
||
380 | 380 | * @param array $options |
381 | 381 | * @return Statement |
382 | 382 | */ |
383 | - public function prepare ($sql, $options = []) { |
|
383 | + public function prepare($sql, $options = []) { |
|
384 | 384 | $this->logger->__invoke($sql); |
385 | 385 | /** @var Statement $statement */ |
386 | 386 | $statement = parent::prepare($sql, $options); |
@@ -396,7 +396,7 @@ discard block |
||
396 | 396 | * @param array $ctorargs Optional. |
397 | 397 | * @return Statement |
398 | 398 | */ |
399 | - public function query ($sql, $mode = PDO::ATTR_DEFAULT_FETCH_MODE, $arg3 = null, array $ctorargs = []) { |
|
399 | + public function query($sql, $mode = PDO::ATTR_DEFAULT_FETCH_MODE, $arg3 = null, array $ctorargs = []) { |
|
400 | 400 | $this->logger->__invoke($sql); |
401 | 401 | /** @var Statement $statement */ |
402 | 402 | $statement = parent::query(...func_get_args()); |
@@ -414,7 +414,7 @@ discard block |
||
414 | 414 | * @param int $type Ignored. |
415 | 415 | * @return string|ExpressionInterface |
416 | 416 | */ |
417 | - public function quote ($value, $type = self::PARAM_STR) { |
|
417 | + public function quote($value, $type = self::PARAM_STR) { |
|
418 | 418 | if ($value instanceof ExpressionInterface) { |
419 | 419 | return $value; |
420 | 420 | } |
@@ -434,7 +434,7 @@ discard block |
||
434 | 434 | * @param array $values |
435 | 435 | * @return string[] |
436 | 436 | */ |
437 | - public function quoteArray (array $values) { |
|
437 | + public function quoteArray(array $values) { |
|
438 | 438 | return array_map([$this, 'quote'], $values); |
439 | 439 | } |
440 | 440 | |
@@ -444,7 +444,7 @@ discard block |
||
444 | 444 | * @param array $values |
445 | 445 | * @return string |
446 | 446 | */ |
447 | - public function quoteList (array $values): string { |
|
447 | + public function quoteList(array $values): string { |
|
448 | 448 | return implode(',', $this->quoteArray($values)); |
449 | 449 | } |
450 | 450 | |
@@ -453,7 +453,7 @@ discard block |
||
453 | 453 | * |
454 | 454 | * @return Num |
455 | 455 | */ |
456 | - public function rand () { |
|
456 | + public function rand() { |
|
457 | 457 | return Num::factory($this, "RAND()"); |
458 | 458 | } |
459 | 459 | |
@@ -464,7 +464,7 @@ discard block |
||
464 | 464 | * |
465 | 465 | * @return true |
466 | 466 | */ |
467 | - public function rollBack () { |
|
467 | + public function rollBack() { |
|
468 | 468 | assert($this->transactions > 0); |
469 | 469 | if ($this->transactions === 1) { |
470 | 470 | $this->logger->__invoke("ROLLBACK TRANSACTION"); |
@@ -484,7 +484,7 @@ discard block |
||
484 | 484 | * @param EntityInterface $entity |
485 | 485 | * @return int ID |
486 | 486 | */ |
487 | - public function save (EntityInterface $entity): int { |
|
487 | + public function save(EntityInterface $entity): int { |
|
488 | 488 | return $this->getRecord($entity)->save($entity); |
489 | 489 | } |
490 | 490 | |
@@ -493,7 +493,7 @@ discard block |
||
493 | 493 | * @param Junction $junction |
494 | 494 | * @return $this |
495 | 495 | */ |
496 | - public function setJunction (string $interface, Junction $junction) { |
|
496 | + public function setJunction(string $interface, Junction $junction) { |
|
497 | 497 | $this->junctions[$interface] = $junction; |
498 | 498 | return $this; |
499 | 499 | } |
@@ -502,7 +502,7 @@ discard block |
||
502 | 502 | * @param Closure $logger |
503 | 503 | * @return $this |
504 | 504 | */ |
505 | - public function setLogger (Closure $logger) { |
|
505 | + public function setLogger(Closure $logger) { |
|
506 | 506 | $this->logger = $logger; |
507 | 507 | return $this; |
508 | 508 | } |
@@ -512,7 +512,7 @@ discard block |
||
512 | 512 | * @param Record $record |
513 | 513 | * @return $this |
514 | 514 | */ |
515 | - public function setRecord (string $class, Record $record) { |
|
515 | + public function setRecord(string $class, Record $record) { |
|
516 | 516 | $this->records[$class] = $record; |
517 | 517 | return $this; |
518 | 518 | } |
@@ -521,7 +521,7 @@ discard block |
||
521 | 521 | * @param callable[] $callbacks Keyed by function name. |
522 | 522 | * @param bool $deterministic Whether the callbacks aren't random / are without side-effects. |
523 | 523 | */ |
524 | - public function sqliteCreateFunctions (array $callbacks, bool $deterministic = true): void { |
|
524 | + public function sqliteCreateFunctions(array $callbacks, bool $deterministic = true): void { |
|
525 | 525 | $deterministic = $deterministic ? self::SQLITE_DETERMINISTIC : 0; |
526 | 526 | foreach ($callbacks as $name => $callback) { |
527 | 527 | $argc = (new ReflectionFunction($callback))->getNumberOfRequiredParameters(); |
@@ -537,7 +537,7 @@ discard block |
||
537 | 537 | * @param callable $work |
538 | 538 | * @return mixed The return value of `$work` |
539 | 539 | */ |
540 | - public function transact (callable $work) { |
|
540 | + public function transact(callable $work) { |
|
541 | 541 | $transaction = $this->newTransaction(); |
542 | 542 | $return = call_user_func($work); |
543 | 543 | $transaction->commit(); |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | * |
34 | 34 | * @param DB $db |
35 | 35 | */ |
36 | - public function __construct (DB $db) { |
|
36 | + public function __construct(DB $db) { |
|
37 | 37 | $this->db = $db; |
38 | 38 | $db->beginTransaction(); |
39 | 39 | } |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | /** |
42 | 42 | * Rolls back if the instance wasn't committed. |
43 | 43 | */ |
44 | - public function __destruct () { |
|
44 | + public function __destruct() { |
|
45 | 45 | if (!$this->committed) { |
46 | 46 | $this->db->rollBack(); |
47 | 47 | } |
@@ -54,14 +54,14 @@ discard block |
||
54 | 54 | * |
55 | 55 | * @return true |
56 | 56 | */ |
57 | - public function commit (): bool { |
|
57 | + public function commit(): bool { |
|
58 | 58 | return $this->committed or $this->committed = $this->db->commit(); |
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |
62 | 62 | * @return bool |
63 | 63 | */ |
64 | - final public function wasCommitted (): bool { |
|
64 | + final public function wasCommitted(): bool { |
|
65 | 65 | return $this->committed; |
66 | 66 | } |
67 | 67 | } |
68 | 68 | \ No newline at end of file |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | * @param string|AbstractTable $table |
125 | 125 | * @param string[] $columns |
126 | 126 | */ |
127 | - public function __construct (DB $db, $table, array $columns = ['*']) { |
|
127 | + public function __construct(DB $db, $table, array $columns = ['*']) { |
|
128 | 128 | static $autoAlias = 0; |
129 | 129 | $autoAlias++; |
130 | 130 | parent::__construct($db); |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | * @param array $args |
152 | 152 | * @return Statement |
153 | 153 | */ |
154 | - public function __invoke (array $args = []) { |
|
154 | + public function __invoke(array $args = []) { |
|
155 | 155 | return $this->execute($args); |
156 | 156 | } |
157 | 157 | |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | * |
161 | 161 | * @return string |
162 | 162 | */ |
163 | - final public function __toString () { |
|
163 | + final public function __toString() { |
|
164 | 164 | return $this->alias; |
165 | 165 | } |
166 | 166 | |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | * @param array $args Execution arguments. |
171 | 171 | * @return int |
172 | 172 | */ |
173 | - public function count (array $args = []): int { |
|
173 | + public function count(array $args = []): int { |
|
174 | 174 | $clone = clone $this; |
175 | 175 | $clone->_columns = 'COUNT(*)'; |
176 | 176 | $clone->_order = ''; |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | * @param array $args |
184 | 184 | * @return Statement |
185 | 185 | */ |
186 | - public function execute (array $args = []) { |
|
186 | + public function execute(array $args = []) { |
|
187 | 187 | if (empty($args)) { |
188 | 188 | return $this->db->query($this->toSql()); |
189 | 189 | } |
@@ -198,14 +198,14 @@ discard block |
||
198 | 198 | * @param array $args Execution arguments. |
199 | 199 | * @return array |
200 | 200 | */ |
201 | - public function getAll (array $args = []): array { |
|
201 | + public function getAll(array $args = []): array { |
|
202 | 202 | return iterator_to_array($this->fetcher->__invoke($this->execute($args))); |
203 | 203 | } |
204 | 204 | |
205 | 205 | /** |
206 | 206 | * @return Column[] |
207 | 207 | */ |
208 | - public function getColumns () { |
|
208 | + public function getColumns() { |
|
209 | 209 | return $this->refs; |
210 | 210 | } |
211 | 211 | |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | * @param array $args Execution arguments. |
219 | 219 | * @return Generator |
220 | 220 | */ |
221 | - public function getEach (array $args = []) { |
|
221 | + public function getEach(array $args = []) { |
|
222 | 222 | yield from $this->fetcher->__invoke($this->execute($args)); |
223 | 223 | } |
224 | 224 | |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | * @param array $args |
231 | 231 | * @return mixed |
232 | 232 | */ |
233 | - public function getFirst (array $args = []) { |
|
233 | + public function getFirst(array $args = []) { |
|
234 | 234 | return $this->getEach($args)->current(); |
235 | 235 | } |
236 | 236 | |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | * |
242 | 242 | * @return Generator |
243 | 243 | */ |
244 | - public function getIterator () { |
|
244 | + public function getIterator() { |
|
245 | 245 | yield from $this->getEach(); |
246 | 246 | } |
247 | 247 | |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | * |
252 | 252 | * @return mixed |
253 | 253 | */ |
254 | - public function getResult (array $args = []) { |
|
254 | + public function getResult(array $args = []) { |
|
255 | 255 | return $this->execute($args)->fetchColumn(); |
256 | 256 | } |
257 | 257 | |
@@ -261,7 +261,7 @@ discard block |
||
261 | 261 | * @param string $column |
262 | 262 | * @return $this |
263 | 263 | */ |
264 | - public function group (string $column) { |
|
264 | + public function group(string $column) { |
|
265 | 265 | if (!strlen($this->_group)) { |
266 | 266 | $this->_group = " GROUP BY {$column}"; |
267 | 267 | } |
@@ -277,7 +277,7 @@ discard block |
||
277 | 277 | * @param string ...$conditions |
278 | 278 | * @return $this |
279 | 279 | */ |
280 | - public function having (string ...$conditions) { |
|
280 | + public function having(string ...$conditions) { |
|
281 | 281 | assert(count($conditions) > 0); |
282 | 282 | $conditions = implode(' AND ', $conditions); |
283 | 283 | if (!strlen($this->_having)) { |
@@ -297,7 +297,7 @@ discard block |
||
297 | 297 | * @param Select $select |
298 | 298 | * @return $this |
299 | 299 | */ |
300 | - public function intersect (Select $select) { |
|
300 | + public function intersect(Select $select) { |
|
301 | 301 | if ($this->db->isMySQL()) { |
302 | 302 | // to be standards compliant, this hack must fail if they don't have the same cols. |
303 | 303 | assert(count($this->refs) === count($select->refs) and !array_diff_key($this->refs, $select->refs)); |
@@ -318,7 +318,7 @@ discard block |
||
318 | 318 | * |
319 | 319 | * @return Predicate |
320 | 320 | */ |
321 | - public function isEmpty () { |
|
321 | + public function isEmpty() { |
|
322 | 322 | return Predicate::factory($this->db, "NOT EXISTS ({$this->toSql()})"); |
323 | 323 | } |
324 | 324 | |
@@ -327,7 +327,7 @@ discard block |
||
327 | 327 | * |
328 | 328 | * @return Predicate |
329 | 329 | */ |
330 | - public function isNotEmpty () { |
|
330 | + public function isNotEmpty() { |
|
331 | 331 | return Predicate::factory($this->db, "EXISTS ({$this->toSql()})"); |
332 | 332 | } |
333 | 333 | |
@@ -338,7 +338,7 @@ discard block |
||
338 | 338 | * @param string ...$conditions |
339 | 339 | * @return $this |
340 | 340 | */ |
341 | - public function join ($table, string ...$conditions) { |
|
341 | + public function join($table, string ...$conditions) { |
|
342 | 342 | assert(count($conditions) > 0); |
343 | 343 | if ($table instanceof Select) { |
344 | 344 | $table = $table->toSubquery(); |
@@ -355,7 +355,7 @@ discard block |
||
355 | 355 | * @param string ...$conditions |
356 | 356 | * @return $this |
357 | 357 | */ |
358 | - public function joinLeft ($table, string ...$conditions) { |
|
358 | + public function joinLeft($table, string ...$conditions) { |
|
359 | 359 | assert(count($conditions) > 0); |
360 | 360 | if ($table instanceof Select) { |
361 | 361 | $table = $table->toSubquery(); |
@@ -372,7 +372,7 @@ discard block |
||
372 | 372 | * @param int $offset |
373 | 373 | * @return $this |
374 | 374 | */ |
375 | - public function limit (int $limit, int $offset = 0) { |
|
375 | + public function limit(int $limit, int $offset = 0) { |
|
376 | 376 | if ($limit == 0) { |
377 | 377 | $this->_limit = ''; |
378 | 378 | } |
@@ -391,7 +391,7 @@ discard block |
||
391 | 391 | * @param int|string $ref Ordinal or reference name. |
392 | 392 | * @return null|Column |
393 | 393 | */ |
394 | - public function offsetGet ($ref) { |
|
394 | + public function offsetGet($ref) { |
|
395 | 395 | if (is_int($ref)) { |
396 | 396 | return current(array_slice($this->refs, $ref, 1)) ?: null; |
397 | 397 | } |
@@ -404,7 +404,7 @@ discard block |
||
404 | 404 | * @param string $order |
405 | 405 | * @return $this |
406 | 406 | */ |
407 | - public function order (string $order) { |
|
407 | + public function order(string $order) { |
|
408 | 408 | if (strlen($order)) { |
409 | 409 | $order = " ORDER BY {$order}"; |
410 | 410 | } |
@@ -415,7 +415,7 @@ discard block |
||
415 | 415 | /** |
416 | 416 | * @return Statement |
417 | 417 | */ |
418 | - public function prepare () { |
|
418 | + public function prepare() { |
|
419 | 419 | return $this->db->prepare($this->toSql()); |
420 | 420 | } |
421 | 421 | |
@@ -423,7 +423,7 @@ discard block |
||
423 | 423 | * @param string $alias |
424 | 424 | * @return $this |
425 | 425 | */ |
426 | - public function setAlias (string $alias) { |
|
426 | + public function setAlias(string $alias) { |
|
427 | 427 | $this->alias = $alias; |
428 | 428 | foreach ($this->refs as $k => $column) { |
429 | 429 | $this->refs[$k] = $column->setQualifier($alias); |
@@ -440,7 +440,7 @@ discard block |
||
440 | 440 | * @param string[] $expressions Keyed by alias if applicable. |
441 | 441 | * @return $this |
442 | 442 | */ |
443 | - public function setColumns (array $expressions = ['*']) { |
|
443 | + public function setColumns(array $expressions = ['*']) { |
|
444 | 444 | if ($expressions === ['*']) { |
445 | 445 | $expressions = array_keys($this->table->getColumns()); |
446 | 446 | } |
@@ -468,7 +468,7 @@ discard block |
||
468 | 468 | * @param Closure $fetcher |
469 | 469 | * @return $this |
470 | 470 | */ |
471 | - public function setFetcher (Closure $fetcher) { |
|
471 | + public function setFetcher(Closure $fetcher) { |
|
472 | 472 | $this->fetcher = $fetcher; |
473 | 473 | return $this; |
474 | 474 | } |
@@ -478,7 +478,7 @@ discard block |
||
478 | 478 | * |
479 | 479 | * @return string |
480 | 480 | */ |
481 | - public function toSql (): string { |
|
481 | + public function toSql(): string { |
|
482 | 482 | $sql = "SELECT {$this->_columns} FROM {$this->_table}"; |
483 | 483 | $sql .= $this->_join; |
484 | 484 | $sql .= $this->_where; |
@@ -495,7 +495,7 @@ discard block |
||
495 | 495 | * |
496 | 496 | * @return string |
497 | 497 | */ |
498 | - public function toSubquery (): string { |
|
498 | + public function toSubquery(): string { |
|
499 | 499 | return "({$this->toSql()}) AS {$this->alias}"; |
500 | 500 | } |
501 | 501 | |
@@ -505,7 +505,7 @@ discard block |
||
505 | 505 | * @param Select $select |
506 | 506 | * @return $this |
507 | 507 | */ |
508 | - public function union (Select $select) { |
|
508 | + public function union(Select $select) { |
|
509 | 509 | $select = clone $select; |
510 | 510 | $select->_order = ''; |
511 | 511 | $select->_limit = ''; |
@@ -519,7 +519,7 @@ discard block |
||
519 | 519 | * @param Select $select |
520 | 520 | * @return $this |
521 | 521 | */ |
522 | - public function unionAll (Select $select) { |
|
522 | + public function unionAll(Select $select) { |
|
523 | 523 | $select = clone $select; |
524 | 524 | $select->_order = ''; |
525 | 525 | $select->_limit = ''; |
@@ -533,7 +533,7 @@ discard block |
||
533 | 533 | * @param string ...$conditions |
534 | 534 | * @return $this |
535 | 535 | */ |
536 | - public function where (string ...$conditions) { |
|
536 | + public function where(string ...$conditions) { |
|
537 | 537 | assert(count($conditions) > 0); |
538 | 538 | $conditions = implode(' AND ', $conditions); |
539 | 539 | if (!strlen($this->_where)) { |
@@ -131,8 +131,7 @@ discard block |
||
131 | 131 | if ($table instanceof Select) { |
132 | 132 | $this->_table = $table->toSubquery(); |
133 | 133 | $this->alias = "_anon{$autoAlias}_{$table->alias}"; |
134 | - } |
|
135 | - else { |
|
134 | + } else { |
|
136 | 135 | if (is_string($table)) { |
137 | 136 | $table = $db->getTable($table); |
138 | 137 | assert(isset($table)); |
@@ -264,8 +263,7 @@ discard block |
||
264 | 263 | public function group (string $column) { |
265 | 264 | if (!strlen($this->_group)) { |
266 | 265 | $this->_group = " GROUP BY {$column}"; |
267 | - } |
|
268 | - else { |
|
266 | + } else { |
|
269 | 267 | $this->_group .= ", {$column}"; |
270 | 268 | } |
271 | 269 | return $this; |
@@ -282,8 +280,7 @@ discard block |
||
282 | 280 | $conditions = implode(' AND ', $conditions); |
283 | 281 | if (!strlen($this->_having)) { |
284 | 282 | $this->_having = " HAVING {$conditions}"; |
285 | - } |
|
286 | - else { |
|
283 | + } else { |
|
287 | 284 | $this->_having .= " AND {$conditions}"; |
288 | 285 | } |
289 | 286 | return $this; |
@@ -375,8 +372,7 @@ discard block |
||
375 | 372 | public function limit (int $limit, int $offset = 0) { |
376 | 373 | if ($limit == 0) { |
377 | 374 | $this->_limit = ''; |
378 | - } |
|
379 | - else { |
|
375 | + } else { |
|
380 | 376 | $this->_limit = " LIMIT {$limit}"; |
381 | 377 | if ($offset > 1) { |
382 | 378 | $this->_limit .= " OFFSET {$offset}"; |
@@ -451,8 +447,7 @@ discard block |
||
451 | 447 | $name = $match['name'] ?? null; |
452 | 448 | if (is_int($alias)) { |
453 | 449 | $alias = $name; |
454 | - } |
|
455 | - elseif ($alias !== $name) { |
|
450 | + } elseif ($alias !== $name) { |
|
456 | 451 | $expr .= " AS {$alias}"; |
457 | 452 | } |
458 | 453 | if (isset($alias)) { |
@@ -538,8 +533,7 @@ discard block |
||
538 | 533 | $conditions = implode(' AND ', $conditions); |
539 | 534 | if (!strlen($this->_where)) { |
540 | 535 | $this->_where = " WHERE {$conditions}"; |
541 | - } |
|
542 | - else { |
|
536 | + } else { |
|
543 | 537 | $this->_where .= " AND {$conditions}"; |
544 | 538 | } |
545 | 539 | return $this; |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | * @param string $name |
43 | 43 | * @param string[] $columns |
44 | 44 | */ |
45 | - public function __construct (DB $db, string $name, array $columns) { |
|
45 | + public function __construct(DB $db, string $name, array $columns) { |
|
46 | 46 | parent::__construct($db); |
47 | 47 | $this->name = $name; |
48 | 48 | foreach ($columns as $column) { |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | * |
56 | 56 | * @return string |
57 | 57 | */ |
58 | - final public function __toString () { |
|
58 | + final public function __toString() { |
|
59 | 59 | return $this->name; |
60 | 60 | } |
61 | 61 | |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | * @param array $values |
66 | 66 | * @return int Rows affected. |
67 | 67 | */ |
68 | - public function apply (array $values): int { |
|
68 | + public function apply(array $values): int { |
|
69 | 69 | $columns = implode(',', array_keys($values)); |
70 | 70 | $values = $this->db->quoteList($values); |
71 | 71 | if ($this->db->isSQLite()) { |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | * @param Closure $prepare `():Statement` |
86 | 86 | * @return Statement |
87 | 87 | */ |
88 | - protected function cache (string $key, Closure $prepare) { |
|
88 | + protected function cache(string $key, Closure $prepare) { |
|
89 | 89 | return $this->_cache[$key] ??= $prepare->__invoke(); |
90 | 90 | } |
91 | 91 | |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | * @param array $match `[a => b]` |
94 | 94 | * @return int |
95 | 95 | */ |
96 | - public function count (array $match = []) { |
|
96 | + public function count(array $match = []) { |
|
97 | 97 | $select = $this->select(['COUNT(*)']); |
98 | 98 | foreach ($match as $a => $b) { |
99 | 99 | $select->where($this->db->match($this[$a] ?? $a, $b)); |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | * @param array $match |
110 | 110 | * @return int Rows affected. |
111 | 111 | */ |
112 | - public function delete (array $match): int { |
|
112 | + public function delete(array $match): int { |
|
113 | 113 | foreach ($match as $a => $b) { |
114 | 114 | $match[$a] = $this->db->match($this[$a] ?? $a, $b); |
115 | 115 | } |
@@ -120,14 +120,14 @@ discard block |
||
120 | 120 | /** |
121 | 121 | * @return Column[] |
122 | 122 | */ |
123 | - public function getColumns () { |
|
123 | + public function getColumns() { |
|
124 | 124 | return $this->columns; |
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
128 | 128 | * @return string |
129 | 129 | */ |
130 | - final public function getName (): string { |
|
130 | + final public function getName(): string { |
|
131 | 131 | return $this->name; |
132 | 132 | } |
133 | 133 | |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | * @param array $values |
138 | 138 | * @return Statement |
139 | 139 | */ |
140 | - public function insert (array $values) { |
|
140 | + public function insert(array $values) { |
|
141 | 141 | $columns = implode(',', array_keys($values)); |
142 | 142 | $values = $this->db->quoteList($values); |
143 | 143 | return $this->db->query("INSERT INTO {$this} ($columns) VALUES ($values)"); |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | * @param int|string $column |
148 | 148 | * @return Column |
149 | 149 | */ |
150 | - public function offsetGet ($column) { |
|
150 | + public function offsetGet($column) { |
|
151 | 151 | if (is_int($column)) { |
152 | 152 | return current(array_slice($this->columns, $column, 1)) ?: null; |
153 | 153 | } |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | * @param string[] $columns |
161 | 161 | * @return Select|array[] |
162 | 162 | */ |
163 | - public function select (array $columns = ['*']) { |
|
163 | + public function select(array $columns = ['*']) { |
|
164 | 164 | return Select::factory($this->db, $this, $columns); |
165 | 165 | } |
166 | 166 | |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | * @param string $name |
171 | 171 | * @return Table |
172 | 172 | */ |
173 | - public function setName (string $name) { |
|
173 | + public function setName(string $name) { |
|
174 | 174 | $clone = clone $this; |
175 | 175 | $clone->name = $name; |
176 | 176 | foreach ($this->columns as $name => $column) { |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | * @param array $match |
189 | 189 | * @return int Rows affected. |
190 | 190 | */ |
191 | - public function update (array $values, array $match): int { |
|
191 | + public function update(array $values, array $match): int { |
|
192 | 192 | foreach ($this->db->quoteArray($values) as $key => $value) { |
193 | 193 | $values[$key] = "{$key} = {$value}"; |
194 | 194 | } |
@@ -16,20 +16,20 @@ discard block |
||
16 | 16 | * |
17 | 17 | * @return string |
18 | 18 | */ |
19 | - abstract public function __toString (); |
|
19 | + abstract public function __toString(); |
|
20 | 20 | |
21 | 21 | /** |
22 | 22 | * Columns keyed by name/alias. |
23 | 23 | * |
24 | 24 | * @return Column[] |
25 | 25 | */ |
26 | - abstract public function getColumns (); |
|
26 | + abstract public function getColumns(); |
|
27 | 27 | |
28 | 28 | /** |
29 | 29 | * @param int|string $column |
30 | 30 | * @return null|Column |
31 | 31 | */ |
32 | - abstract public function offsetGet ($column); |
|
32 | + abstract public function offsetGet($column); |
|
33 | 33 | |
34 | 34 | /** |
35 | 35 | * @var DB |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | /** |
40 | 40 | * @param DB $db |
41 | 41 | */ |
42 | - public function __construct (DB $db) { |
|
42 | + public function __construct(DB $db) { |
|
43 | 43 | $this->db = $db; |
44 | 44 | } |
45 | 45 | |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | * @param int|string $column |
48 | 48 | * @return bool |
49 | 49 | */ |
50 | - public function offsetExists ($column): bool { |
|
50 | + public function offsetExists($column): bool { |
|
51 | 51 | return $this->offsetGet($column) !== null; |
52 | 52 | } |
53 | 53 | |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | * @param void $value |
59 | 59 | * @throws Exception |
60 | 60 | */ |
61 | - final public function offsetSet ($offset, $value): void { |
|
61 | + final public function offsetSet($offset, $value): void { |
|
62 | 62 | throw new Exception('Tables are immutable.'); |
63 | 63 | } |
64 | 64 | |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | * @param void $name |
69 | 69 | * @throws Exception |
70 | 70 | */ |
71 | - final public function offsetUnset ($name): void { |
|
71 | + final public function offsetUnset($name): void { |
|
72 | 72 | $this->offsetSet($name, null); |
73 | 73 | } |
74 | 74 | } |
75 | 75 | \ No newline at end of file |