@@ -301,13 +301,4 @@ |
||
301 | 301 | */ |
302 | 302 | public function down (\$schema) |
303 | 303 | { |
304 | - {$down} |
|
305 | - } |
|
306 | - |
|
307 | - }; |
|
308 | - |
|
309 | - MIGRATION |
|
310 | - ); |
|
311 | - } |
|
312 | - |
|
313 | -})->_exec(); |
|
304 | + {$down} |
|
314 | 305 | \ No newline at end of file |
@@ -301,13 +301,4 @@ |
||
301 | 301 | */ |
302 | 302 | public function down (\$schema) |
303 | 303 | { |
304 | - {$down} |
|
305 | - } |
|
306 | - |
|
307 | - }; |
|
308 | - |
|
309 | - MIGRATION |
|
310 | - ); |
|
311 | - } |
|
312 | - |
|
313 | -})->_exec(); |
|
304 | + {$down} |
|
314 | 305 | \ No newline at end of file |
@@ -301,13 +301,4 @@ |
||
301 | 301 | */ |
302 | 302 | public function down (\$schema) |
303 | 303 | { |
304 | - {$down} |
|
305 | - } |
|
306 | - |
|
307 | - }; |
|
308 | - |
|
309 | - MIGRATION |
|
310 | - ); |
|
311 | - } |
|
312 | - |
|
313 | -})->_exec(); |
|
304 | + {$down} |
|
314 | 305 | \ No newline at end of file |
@@ -301,13 +301,4 @@ |
||
301 | 301 | */ |
302 | 302 | public function down (\$schema) |
303 | 303 | { |
304 | - {$down} |
|
305 | - } |
|
306 | - |
|
307 | - }; |
|
308 | - |
|
309 | - MIGRATION |
|
310 | - ); |
|
311 | - } |
|
312 | - |
|
313 | -})->_exec(); |
|
304 | + {$down} |
|
314 | 305 | \ No newline at end of file |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | |
29 | 29 | private Schema $schema; |
30 | 30 | |
31 | - public function __construct (array $argv, array $opt) { |
|
31 | + public function __construct(array $argv, array $opt) { |
|
32 | 32 | $this->argv = $argv; |
33 | 33 | $opt['connection'] ??= 'default'; |
34 | 34 | $opt['config'] ??= 'db.config.php'; |
@@ -39,15 +39,15 @@ discard block |
||
39 | 39 | $this->schema = $this->db->getSchema(); |
40 | 40 | } |
41 | 41 | |
42 | - private function _stderr (string $text): void { |
|
42 | + private function _stderr(string $text): void { |
|
43 | 43 | fputs(STDERR, "{$text}\n\n"); |
44 | 44 | } |
45 | 45 | |
46 | - private function _stdout (string $text): void { |
|
46 | + private function _stdout(string $text): void { |
|
47 | 47 | echo "{$text}\n\n"; |
48 | 48 | } |
49 | 49 | |
50 | - private function _usage_exit (): void { |
|
50 | + private function _usage_exit(): void { |
|
51 | 51 | $this->_stderr(<<< USAGE |
52 | 52 | |
53 | 53 | $ php {$this->argv[0]} [OPTIONS] ACTION |
@@ -337,13 +337,4 @@ discard block |
||
337 | 337 | */ |
338 | 338 | public function down (\$schema) |
339 | 339 | { |
340 | - {$down} |
|
341 | - } |
|
342 | - |
|
343 | - }; |
|
344 | - |
|
345 | - MIGRATION |
|
346 | - ); |
|
347 | - } |
|
348 | - |
|
349 | -})->_exec(); |
|
340 | + {$down} |
|
350 | 341 | \ No newline at end of file |
@@ -356,8 +356,7 @@ |
||
356 | 356 | if ($this->db->isSQLite()) { |
357 | 357 | $info = $this->db->query("PRAGMA table_info({$name})")->fetchAll(); |
358 | 358 | $cols = array_column($info, 'name'); |
359 | - } |
|
360 | - else { |
|
359 | + } else { |
|
361 | 360 | $cols = $this->db->query("SELECT column_name FROM information_schema.tables WHERE table_name = \"{$name}\"")->fetchAll(DB::FETCH_COLUMN); |
362 | 361 | } |
363 | 362 | if (!$cols) { |
@@ -143,16 +143,16 @@ discard block |
||
143 | 143 | // bool |
144 | 144 | 'BOOLEAN' => 'bool', |
145 | 145 | // int |
146 | - 'BIGINT' => 'int', // mysql |
|
146 | + 'BIGINT' => 'int', // mysql |
|
147 | 147 | 'INTEGER' => 'int', // sqlite (must be this type to allow AUTOINCREMENT) |
148 | 148 | // float |
149 | 149 | 'DOUBLE PRECISION' => 'float', |
150 | 150 | // string <= 255 |
151 | 151 | 'VARCHAR(255)' => 'string', |
152 | 152 | // string <= 64k |
153 | - 'TEXT' => 'String', // @var String |
|
153 | + 'TEXT' => 'String', // @var String |
|
154 | 154 | // string > 64k |
155 | - 'BLOB' => 'STRING', // @var STRING (sqlite) |
|
155 | + 'BLOB' => 'STRING', // @var STRING (sqlite) |
|
156 | 156 | 'LONGBLOB' => 'STRING', // @var STRING (mysql) |
157 | 157 | // DateTime |
158 | 158 | 'DATETIME' => 'DateTime', |
@@ -220,7 +220,7 @@ discard block |
||
220 | 220 | /** |
221 | 221 | * @param DB $db |
222 | 222 | */ |
223 | - public function __construct (DB $db) { |
|
223 | + public function __construct(DB $db) { |
|
224 | 224 | $this->db = $db; |
225 | 225 | $this->colDefs ??= self::COLUMN_DEFINITIONS[$db->getDriver()]; |
226 | 226 | } |
@@ -233,7 +233,7 @@ discard block |
||
233 | 233 | * @param int $type |
234 | 234 | * @return $this |
235 | 235 | */ |
236 | - public function addColumn (string $table, string $column, int $type = self::T_STRING_NULL) { |
|
236 | + public function addColumn(string $table, string $column, int $type = self::T_STRING_NULL) { |
|
237 | 237 | $type = $this->colDefs[$type & self::T_MASK]; |
238 | 238 | $this->db->exec("ALTER TABLE {$table} ADD COLUMN {$column} {$type}"); |
239 | 239 | unset($this->tables[$table]); |
@@ -259,7 +259,7 @@ discard block |
||
259 | 259 | * @param array[] $constraints `[ <TABLE_CONST> => spec ]` |
260 | 260 | * @return $this |
261 | 261 | */ |
262 | - public function createTable (string $table, array $columns, array $constraints = []) { |
|
262 | + public function createTable(string $table, array $columns, array $constraints = []) { |
|
263 | 263 | $defs = $this->toColumnDefinitions($columns); |
264 | 264 | |
265 | 265 | /** @var string[] $pk */ |
@@ -295,7 +295,7 @@ discard block |
||
295 | 295 | * @param string $column |
296 | 296 | * @return $this |
297 | 297 | */ |
298 | - public function dropColumn (string $table, string $column) { |
|
298 | + public function dropColumn(string $table, string $column) { |
|
299 | 299 | $this->db->exec("ALTER TABLE {$table} DROP COLUMN {$column}"); |
300 | 300 | unset($this->tables[$table]); |
301 | 301 | return $this; |
@@ -306,7 +306,7 @@ discard block |
||
306 | 306 | * |
307 | 307 | * @param string $table |
308 | 308 | */ |
309 | - public function dropTable (string $table): void { |
|
309 | + public function dropTable(string $table): void { |
|
310 | 310 | $this->db->exec("DROP TABLE IF EXISTS {$table}"); |
311 | 311 | unset($this->tables[$table]); |
312 | 312 | } |
@@ -325,7 +325,7 @@ discard block |
||
325 | 325 | * @param string $column |
326 | 326 | * @return array[] Keyed by name. |
327 | 327 | */ |
328 | - public function getColumnInfo (string $table): array { |
|
328 | + public function getColumnInfo(string $table): array { |
|
329 | 329 | if ($this->db->isSQLite()) { |
330 | 330 | $info = $this->db->query("PRAGMA table_info({$table})")->fetchAll(); |
331 | 331 | return array_combine(array_column($info, 'name'), array_map(fn(array $each) => [ |
@@ -345,7 +345,7 @@ discard block |
||
345 | 345 | /** |
346 | 346 | * @return DB |
347 | 347 | */ |
348 | - public function getDb () { |
|
348 | + public function getDb() { |
|
349 | 349 | return $this->db; |
350 | 350 | } |
351 | 351 | |
@@ -353,7 +353,7 @@ discard block |
||
353 | 353 | * @param string $name |
354 | 354 | * @return null|Table |
355 | 355 | */ |
356 | - public function getTable (string $name) { |
|
356 | + public function getTable(string $name) { |
|
357 | 357 | if (!isset($this->tables[$name])) { |
358 | 358 | if ($this->db->isSQLite()) { |
359 | 359 | $info = $this->db->query("PRAGMA table_info({$name})")->fetchAll(); |
@@ -376,7 +376,7 @@ discard block |
||
376 | 376 | * @param string $table |
377 | 377 | * @return bool |
378 | 378 | */ |
379 | - final public function offsetExists ($table): bool { |
|
379 | + final public function offsetExists($table): bool { |
|
380 | 380 | return (bool)$this->offsetGet($table); |
381 | 381 | } |
382 | 382 | |
@@ -386,7 +386,7 @@ discard block |
||
386 | 386 | * @param string $table |
387 | 387 | * @return null|Table |
388 | 388 | */ |
389 | - public function offsetGet ($table) { |
|
389 | + public function offsetGet($table) { |
|
390 | 390 | return $this->getTable($table); |
391 | 391 | } |
392 | 392 | |
@@ -395,7 +395,7 @@ discard block |
||
395 | 395 | * @param $value |
396 | 396 | * @throws LogicException |
397 | 397 | */ |
398 | - final public function offsetSet ($offset, $value) { |
|
398 | + final public function offsetSet($offset, $value) { |
|
399 | 399 | throw new LogicException('The schema cannot be altered this way.'); |
400 | 400 | } |
401 | 401 | |
@@ -403,7 +403,7 @@ discard block |
||
403 | 403 | * @param $offset |
404 | 404 | * @throws LogicException |
405 | 405 | */ |
406 | - final public function offsetUnset ($offset) { |
|
406 | + final public function offsetUnset($offset) { |
|
407 | 407 | throw new LogicException('The schema cannot be altered this way.'); |
408 | 408 | } |
409 | 409 | |
@@ -415,7 +415,7 @@ discard block |
||
415 | 415 | * @param string $newName |
416 | 416 | * @return $this |
417 | 417 | */ |
418 | - public function renameColumn (string $table, string $oldName, string $newName) { |
|
418 | + public function renameColumn(string $table, string $oldName, string $newName) { |
|
419 | 419 | $this->db->exec("ALTER TABLE {$table} RENAME COLUMN {$oldName} TO {$newName}"); |
420 | 420 | unset($this->tables[$table]); |
421 | 421 | return $this; |
@@ -428,7 +428,7 @@ discard block |
||
428 | 428 | * @param string $newName |
429 | 429 | * @return $this |
430 | 430 | */ |
431 | - public function renameTable (string $oldName, string $newName) { |
|
431 | + public function renameTable(string $oldName, string $newName) { |
|
432 | 432 | $this->db->exec("ALTER TABLE {$oldName} RENAME TO {$newName}"); |
433 | 433 | unset($this->tables[$oldName]); |
434 | 434 | return $this; |
@@ -440,7 +440,7 @@ discard block |
||
440 | 440 | * @param int[] $types |
441 | 441 | * @return int[] |
442 | 442 | */ |
443 | - protected function sortColumns (array $types): array { |
|
443 | + protected function sortColumns(array $types): array { |
|
444 | 444 | uksort($types, function(string $a, string $b) use ($types) { |
445 | 445 | // descending type constant, ascending name |
446 | 446 | return $types[$b] <=> $types[$a] ?: $a <=> $b; |
@@ -452,7 +452,7 @@ discard block |
||
452 | 452 | * @param int[] $columns `[ name => <I_CONST> | <T_CONST> ]` |
453 | 453 | * @return string[] |
454 | 454 | */ |
455 | - protected function toColumnDefinitions (array $columns): array { |
|
455 | + protected function toColumnDefinitions(array $columns): array { |
|
456 | 456 | assert(count($columns) > 0); |
457 | 457 | $columns = $this->sortColumns($columns); |
458 | 458 | $defs = []; |
@@ -478,7 +478,7 @@ discard block |
||
478 | 478 | * @param Column $foreign |
479 | 479 | * @return string |
480 | 480 | */ |
481 | - protected function toForeignKeyConstraint (string $table, string $local, int $type, Column $foreign): string { |
|
481 | + protected function toForeignKeyConstraint(string $table, string $local, int $type, Column $foreign): string { |
|
482 | 482 | return sprintf( |
483 | 483 | 'CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s(%s) ON UPDATE CASCADE ON DELETE %s', |
484 | 484 | $this->toForeignKeyConstraint_name($table, $local), |
@@ -496,7 +496,7 @@ discard block |
||
496 | 496 | * @param string $column |
497 | 497 | * @return string |
498 | 498 | */ |
499 | - protected function toForeignKeyConstraint_name (string $table, string $column): string { |
|
499 | + protected function toForeignKeyConstraint_name(string $table, string $column): string { |
|
500 | 500 | return 'FK_' . $table . '__' . $column; |
501 | 501 | } |
502 | 502 | |
@@ -505,7 +505,7 @@ discard block |
||
505 | 505 | * @param string[] $columns |
506 | 506 | * @return string |
507 | 507 | */ |
508 | - protected function toPrimaryKeyConstraint (string $table, array $columns): string { |
|
508 | + protected function toPrimaryKeyConstraint(string $table, array $columns): string { |
|
509 | 509 | return sprintf( |
510 | 510 | 'CONSTRAINT %s PRIMARY KEY (%s)', |
511 | 511 | $this->toPrimaryKeyConstraint_name($table, $columns), |
@@ -520,7 +520,7 @@ discard block |
||
520 | 520 | * @param string[] $columns |
521 | 521 | * @return string |
522 | 522 | */ |
523 | - protected function toPrimaryKeyConstraint_name (string $table, array $columns): string { |
|
523 | + protected function toPrimaryKeyConstraint_name(string $table, array $columns): string { |
|
524 | 524 | sort($columns, SORT_STRING); |
525 | 525 | return 'PK_' . $table . '__' . implode('__', $columns); |
526 | 526 | } |
@@ -530,7 +530,7 @@ discard block |
||
530 | 530 | * @param string[] $columns |
531 | 531 | * @return string |
532 | 532 | */ |
533 | - protected function toUniqueKeyConstraint (string $table, array $columns): string { |
|
533 | + protected function toUniqueKeyConstraint(string $table, array $columns): string { |
|
534 | 534 | return sprintf( |
535 | 535 | 'CONSTRAINT %s UNIQUE (%s)', |
536 | 536 | $this->toUniqueKeyConstraint_name($table, $columns), |
@@ -545,7 +545,7 @@ discard block |
||
545 | 545 | * @param string[] $columns |
546 | 546 | * @return string |
547 | 547 | */ |
548 | - protected function toUniqueKeyConstraint_name (string $table, array $columns): string { |
|
548 | + protected function toUniqueKeyConstraint_name(string $table, array $columns): string { |
|
549 | 549 | sort($columns, SORT_STRING); |
550 | 550 | return 'UQ_' . $table . '__' . implode('__', $columns); |
551 | 551 | } |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | * @param DB $db |
35 | 35 | * @param string $dir |
36 | 36 | */ |
37 | - public function __construct (DB $db, string $dir) { |
|
37 | + public function __construct(DB $db, string $dir) { |
|
38 | 38 | $this->db = $db; |
39 | 39 | $this->dir = $dir; |
40 | 40 | } |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | * @param string $to Migration sequence identifier, or `null` to step down once. |
46 | 46 | * @return null|string The resulting current sequence identifier. |
47 | 47 | */ |
48 | - public function down (string $to = null): ?string { |
|
48 | + public function down(string $to = null): ?string { |
|
49 | 49 | return $this->db->transact(function() use ($to) { |
50 | 50 | $current = $this->getCurrent(); |
51 | 51 | // walk newest to oldest |
@@ -72,14 +72,14 @@ discard block |
||
72 | 72 | * |
73 | 73 | * @return null|string |
74 | 74 | */ |
75 | - public function getCurrent (): ?string { |
|
75 | + public function getCurrent(): ?string { |
|
76 | 76 | return $this->getTable()['sequence']['max']; |
77 | 77 | } |
78 | 78 | |
79 | 79 | /** |
80 | 80 | * @return string |
81 | 81 | */ |
82 | - final public function getDir (): string { |
|
82 | + final public function getDir(): string { |
|
83 | 83 | return $this->dir; |
84 | 84 | } |
85 | 85 | |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | * @param array $spec |
88 | 88 | * @return MigrationInterface |
89 | 89 | */ |
90 | - protected function getMigration (string $file) { |
|
90 | + protected function getMigration(string $file) { |
|
91 | 91 | $migration = include "{$file}"; |
92 | 92 | assert($migration instanceof MigrationInterface); |
93 | 93 | return $migration; |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | * |
99 | 99 | * @return Table |
100 | 100 | */ |
101 | - public function getTable () { |
|
101 | + public function getTable() { |
|
102 | 102 | return $this->table ??= ($this->db['__migrations__'] ?? |
103 | 103 | $this->db->getSchema()->createTable('__migrations__', [ |
104 | 104 | 'sequence' => Schema::T_STRING | Schema::I_PRIMARY |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | * |
112 | 112 | * @return string[] [ sequence => file ] |
113 | 113 | */ |
114 | - protected function glob () { |
|
114 | + protected function glob() { |
|
115 | 115 | $files = []; |
116 | 116 | foreach (glob("{$this->dir}/*.php") as $file) { |
117 | 117 | $files[basename($file, '.php')] = $file; |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | * @param null|string $to Migration sequence identifier, or `null` for all upgrades. |
126 | 126 | * @return null|string The resulting current sequence identifier. |
127 | 127 | */ |
128 | - public function up (string $to = null): ?string { |
|
128 | + public function up(string $to = null): ?string { |
|
129 | 129 | return $this->db->transact(function() use ($to) { |
130 | 130 | $current = $this->getCurrent(); |
131 | 131 | // walk oldest to newest |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | /** |
35 | 35 | * @return scalar[] |
36 | 36 | */ |
37 | - public function getAttributes (): array { |
|
37 | + public function getAttributes(): array { |
|
38 | 38 | return $this->attributes ?? []; |
39 | 39 | } |
40 | 40 | |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | * @param mixed $attr |
43 | 43 | * @return bool |
44 | 44 | */ |
45 | - public function offsetExists ($attr): bool { |
|
45 | + public function offsetExists($attr): bool { |
|
46 | 46 | return isset($this->attributes[$attr]); |
47 | 47 | } |
48 | 48 | |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | * @param mixed $attr |
51 | 51 | * @return null|scalar |
52 | 52 | */ |
53 | - public function offsetGet ($attr) { |
|
53 | + public function offsetGet($attr) { |
|
54 | 54 | return $this->attributes[$attr] ?? null; |
55 | 55 | } |
56 | 56 | |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | * @param mixed $attr |
59 | 59 | * @param null|scalar $value |
60 | 60 | */ |
61 | - public function offsetSet ($attr, $value): void { |
|
61 | + public function offsetSet($attr, $value): void { |
|
62 | 62 | if (isset($attr)) { |
63 | 63 | if (isset($value)) { |
64 | 64 | assert(is_scalar($value)); |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | /** |
81 | 81 | * @param mixed $attr |
82 | 82 | */ |
83 | - public function offsetUnset ($attr): void { |
|
83 | + public function offsetUnset($attr): void { |
|
84 | 84 | unset($this->attributes[$attr]); |
85 | 85 | } |
86 | 86 | |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | * @param scalar[] $attributes |
89 | 89 | * @return $this |
90 | 90 | */ |
91 | - public function setAttributes (array $attributes) { |
|
91 | + public function setAttributes(array $attributes) { |
|
92 | 92 | $this->attributes = array_filter($attributes, 'is_scalar'); |
93 | 93 | return $this; |
94 | 94 | } |
@@ -63,12 +63,10 @@ |
||
63 | 63 | if (isset($value)) { |
64 | 64 | assert(is_scalar($value)); |
65 | 65 | $this->attributes[$attr] = $value; |
66 | - } |
|
67 | - else { |
|
66 | + } else { |
|
68 | 67 | $this->offsetUnset($attr); |
69 | 68 | } |
70 | - } |
|
71 | - else { |
|
69 | + } else { |
|
72 | 70 | // appending must not be null. |
73 | 71 | // even though missing numeric offsets would yield null when fetched individually, |
74 | 72 | // getAttributes() would not have them. |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | * @param string|EntityInterface $class Class or prototype instance. |
139 | 139 | * @return Record |
140 | 140 | */ |
141 | - public static function fromClass (DB $db, $class) { |
|
141 | + public static function fromClass(DB $db, $class) { |
|
142 | 142 | $rClass = new ReflectionClass($class); |
143 | 143 | assert($rClass->isInstantiable()); |
144 | 144 | $columns = []; |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | * @param string[] $properties Property names. |
170 | 170 | * @param EAV[] $eav Keyed by property name. |
171 | 171 | */ |
172 | - public function __construct (DB $db, EntityInterface $proto, string $table, array $properties, array $eav = []) { |
|
172 | + public function __construct(DB $db, EntityInterface $proto, string $table, array $properties, array $eav = []) { |
|
173 | 173 | parent::__construct($db, $table, $properties); |
174 | 174 | $this->proto = $proto; |
175 | 175 | $this->utc = new DateTimeZone('UTC'); |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | * @param ReflectionProperty $rProp |
209 | 209 | * @return null|string Storage type, or `null` for unknown. |
210 | 210 | */ |
211 | - protected function __construct_getType (string $prop, ReflectionProperty $rProp): ?string { |
|
211 | + protected function __construct_getType(string $prop, ReflectionProperty $rProp): ?string { |
|
212 | 212 | return $this->__construct_getType_fromReflection($prop, $rProp) |
213 | 213 | ?? $this->__construct_getType_fromVar($prop, $rProp); |
214 | 214 | } |
@@ -220,7 +220,7 @@ discard block |
||
220 | 220 | * @param ReflectionProperty $rProp |
221 | 221 | * @return null|string |
222 | 222 | */ |
223 | - protected function __construct_getType_fromReflection (string $prop, ReflectionProperty $rProp): ?string { |
|
223 | + protected function __construct_getType_fromReflection(string $prop, ReflectionProperty $rProp): ?string { |
|
224 | 224 | if ($rType = $rProp->getType() and $rType instanceof ReflectionNamedType) { |
225 | 225 | $type = $rType->getName(); |
226 | 226 | if (isset(static::SCALARS[$type])) { |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | * @param ReflectionProperty $rProp |
241 | 241 | * @return null|string |
242 | 242 | */ |
243 | - protected function __construct_getType_fromVar (string $prop, ReflectionProperty $rProp): ?string { |
|
243 | + protected function __construct_getType_fromVar(string $prop, ReflectionProperty $rProp): ?string { |
|
244 | 244 | if (preg_match(static::RX_VAR, $rProp->getDocComment(), $var)) { |
245 | 245 | $type = preg_replace(static::RX_NULL, '', $var['type']); // remove null |
246 | 246 | if (isset(static::SCALARS[$type])) { |
@@ -266,7 +266,7 @@ discard block |
||
266 | 266 | * @param ReflectionProperty $rProp |
267 | 267 | * @return null|bool |
268 | 268 | */ |
269 | - protected function __construct_isNullable (string $prop, ReflectionProperty $rProp): ?bool { |
|
269 | + protected function __construct_isNullable(string $prop, ReflectionProperty $rProp): ?bool { |
|
270 | 270 | return $this->__construct_isNullable_fromReflection($prop, $rProp) |
271 | 271 | ?? $this->__construct_isNullable_fromVar($prop, $rProp); |
272 | 272 | } |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | * @param ReflectionProperty $rProp |
277 | 277 | * @return null|bool |
278 | 278 | */ |
279 | - protected function __construct_isNullable_fromReflection (string $prop, ReflectionProperty $rProp): ?bool { |
|
279 | + protected function __construct_isNullable_fromReflection(string $prop, ReflectionProperty $rProp): ?bool { |
|
280 | 280 | if ($rType = $rProp->getType()) { |
281 | 281 | return $rType->allowsNull(); |
282 | 282 | } |
@@ -288,7 +288,7 @@ discard block |
||
288 | 288 | * @param ReflectionProperty $rProp |
289 | 289 | * @return null|bool |
290 | 290 | */ |
291 | - protected function __construct_isNullable_fromVar (string $prop, ReflectionProperty $rProp): ?bool { |
|
291 | + protected function __construct_isNullable_fromVar(string $prop, ReflectionProperty $rProp): ?bool { |
|
292 | 292 | if (preg_match(static::RX_VAR, $rProp->getDocComment(), $var)) { |
293 | 293 | preg_replace(static::RX_NULL, '', $var['type'], -1, $nullable); |
294 | 294 | return (bool)$nullable; |
@@ -302,7 +302,7 @@ discard block |
||
302 | 302 | * @param Statement $statement |
303 | 303 | * @return EntityInterface[] Keyed by ID |
304 | 304 | */ |
305 | - public function fetchAll (Statement $statement): array { |
|
305 | + public function fetchAll(Statement $statement): array { |
|
306 | 306 | return iterator_to_array($this->fetchEach($statement)); |
307 | 307 | } |
308 | 308 | |
@@ -313,7 +313,7 @@ discard block |
||
313 | 313 | * @param Statement $statement |
314 | 314 | * @return Generator|EntityInterface[] Keyed by ID |
315 | 315 | */ |
316 | - public function fetchEach (Statement $statement) { |
|
316 | + public function fetchEach(Statement $statement) { |
|
317 | 317 | do { |
318 | 318 | $entities = []; |
319 | 319 | for ($i = 0; $i < 256 and false !== $row = $statement->fetch(); $i++) { |
@@ -335,7 +335,7 @@ discard block |
||
335 | 335 | * @param array[] $eavMatch `[eav property => attribute => value]` |
336 | 336 | * @return Select|EntityInterface[] |
337 | 337 | */ |
338 | - public function findAll (array $match, array $eavMatch = []) { |
|
338 | + public function findAll(array $match, array $eavMatch = []) { |
|
339 | 339 | $select = $this->loadAll(); |
340 | 340 | foreach ($match as $a => $b) { |
341 | 341 | $select->where($this->db->match($this[$a] ?? $a, $b)); |
@@ -354,21 +354,21 @@ discard block |
||
354 | 354 | * @param array $eavMatch `[eav property => attribute => value]` |
355 | 355 | * @return null|EntityInterface |
356 | 356 | */ |
357 | - public function findFirst (array $match, array $eavMatch = []) { |
|
357 | + public function findFirst(array $match, array $eavMatch = []) { |
|
358 | 358 | return $this->findAll($match, $eavMatch)->limit(1)->getFirst(); |
359 | 359 | } |
360 | 360 | |
361 | 361 | /** |
362 | 362 | * @return string |
363 | 363 | */ |
364 | - final public function getClass (): string { |
|
364 | + final public function getClass(): string { |
|
365 | 365 | return get_class($this->proto); |
366 | 366 | } |
367 | 367 | |
368 | 368 | /** |
369 | 369 | * @return EAV[] |
370 | 370 | */ |
371 | - public function getEav () { |
|
371 | + public function getEav() { |
|
372 | 372 | return $this->eav; |
373 | 373 | } |
374 | 374 | |
@@ -377,14 +377,14 @@ discard block |
||
377 | 377 | * |
378 | 378 | * @return string[] |
379 | 379 | */ |
380 | - final public function getProperties (): array { |
|
380 | + final public function getProperties(): array { |
|
381 | 381 | return array_keys($this->properties); |
382 | 382 | } |
383 | 383 | |
384 | 384 | /** |
385 | 385 | * @return EntityInterface |
386 | 386 | */ |
387 | - public function getProto () { |
|
387 | + public function getProto() { |
|
388 | 388 | return $this->proto; |
389 | 389 | } |
390 | 390 | |
@@ -396,7 +396,7 @@ discard block |
||
396 | 396 | * @param string $property |
397 | 397 | * @return string |
398 | 398 | */ |
399 | - final public function getType (string $property): string { |
|
399 | + final public function getType(string $property): string { |
|
400 | 400 | return $this->types[$property]; |
401 | 401 | } |
402 | 402 | |
@@ -407,7 +407,7 @@ discard block |
||
407 | 407 | * |
408 | 408 | * @return string[] |
409 | 409 | */ |
410 | - final public function getTypes (): array { |
|
410 | + final public function getTypes(): array { |
|
411 | 411 | return $this->types; |
412 | 412 | } |
413 | 413 | |
@@ -415,7 +415,7 @@ discard block |
||
415 | 415 | * @param EntityInterface $entity |
416 | 416 | * @return array |
417 | 417 | */ |
418 | - protected function getValues (EntityInterface $entity): array { |
|
418 | + protected function getValues(EntityInterface $entity): array { |
|
419 | 419 | $values = []; |
420 | 420 | foreach (array_keys($this->columns) as $name) { |
421 | 421 | $value = $this->properties[$name]->getValue($entity); |
@@ -439,7 +439,7 @@ discard block |
||
439 | 439 | * @param array|object $hydrated |
440 | 440 | * @return scalar |
441 | 441 | */ |
442 | - protected function getValues_dehydrate (string $to, string $from, $hydrated) { |
|
442 | + protected function getValues_dehydrate(string $to, string $from, $hydrated) { |
|
443 | 443 | unset($from); // we don't need it here but it's given for posterity |
444 | 444 | switch ($to) { |
445 | 445 | case 'DateTime': |
@@ -454,7 +454,7 @@ discard block |
||
454 | 454 | * @param string $property |
455 | 455 | * @return bool |
456 | 456 | */ |
457 | - final public function isNullable (string $property): bool { |
|
457 | + final public function isNullable(string $property): bool { |
|
458 | 458 | return $this->nullable[$property]; |
459 | 459 | } |
460 | 460 | |
@@ -464,7 +464,7 @@ discard block |
||
464 | 464 | * @param int $id |
465 | 465 | * @return null|EntityInterface |
466 | 466 | */ |
467 | - public function load (int $id) { |
|
467 | + public function load(int $id) { |
|
468 | 468 | $statement = $this->cache(__FUNCTION__, function() { |
469 | 469 | return $this->select()->where('id = ?')->prepare(); |
470 | 470 | }); |
@@ -484,7 +484,7 @@ discard block |
||
484 | 484 | * |
485 | 485 | * @return Select|EntityInterface[] |
486 | 486 | */ |
487 | - public function loadAll () { |
|
487 | + public function loadAll() { |
|
488 | 488 | return $this->select()->setFetcher(function(Statement $statement) { |
489 | 489 | yield from $this->fetchEach($statement); |
490 | 490 | }); |
@@ -495,7 +495,7 @@ discard block |
||
495 | 495 | * |
496 | 496 | * @param EntityInterface[] $entities |
497 | 497 | */ |
498 | - protected function loadEav (array $entities): void { |
|
498 | + protected function loadEav(array $entities): void { |
|
499 | 499 | $ids = array_keys($entities); |
500 | 500 | foreach ($this->eav as $name => $eav) { |
501 | 501 | foreach ($eav->loadAll($ids) as $id => $values) { |
@@ -510,7 +510,7 @@ discard block |
||
510 | 510 | * @param EntityInterface $entity |
511 | 511 | * @return int ID |
512 | 512 | */ |
513 | - public function save (EntityInterface $entity): int { |
|
513 | + public function save(EntityInterface $entity): int { |
|
514 | 514 | if (!$entity->getId()) { |
515 | 515 | $this->saveInsert($entity); |
516 | 516 | } |
@@ -524,7 +524,7 @@ discard block |
||
524 | 524 | /** |
525 | 525 | * @param EntityInterface $entity |
526 | 526 | */ |
527 | - protected function saveEav (EntityInterface $entity): void { |
|
527 | + protected function saveEav(EntityInterface $entity): void { |
|
528 | 528 | $id = $entity->getId(); |
529 | 529 | foreach ($this->eav as $name => $eav) { |
530 | 530 | // may be null to skip |
@@ -540,7 +540,7 @@ discard block |
||
540 | 540 | * |
541 | 541 | * @param EntityInterface $entity |
542 | 542 | */ |
543 | - protected function saveInsert (EntityInterface $entity): void { |
|
543 | + protected function saveInsert(EntityInterface $entity): void { |
|
544 | 544 | $statement = $this->cache(__FUNCTION__, function() { |
545 | 545 | $slots = $this->db->slots(array_keys($this->columns)); |
546 | 546 | unset($slots['id']); |
@@ -559,7 +559,7 @@ discard block |
||
559 | 559 | * |
560 | 560 | * @param EntityInterface $entity |
561 | 561 | */ |
562 | - protected function saveUpdate (EntityInterface $entity): void { |
|
562 | + protected function saveUpdate(EntityInterface $entity): void { |
|
563 | 563 | $statement = $this->cache(__FUNCTION__, function() { |
564 | 564 | $slots = $this->db->slotsEqual(array_keys($this->columns)); |
565 | 565 | unset($slots['id']); |
@@ -574,7 +574,7 @@ discard block |
||
574 | 574 | * @param EntityInterface $proto |
575 | 575 | * @return $this |
576 | 576 | */ |
577 | - public function setProto (EntityInterface $proto) { |
|
577 | + public function setProto(EntityInterface $proto) { |
|
578 | 578 | $this->proto = $proto; |
579 | 579 | return $this; |
580 | 580 | } |
@@ -586,7 +586,7 @@ discard block |
||
586 | 586 | * @param mixed $value |
587 | 587 | * @return mixed |
588 | 588 | */ |
589 | - protected function setType (string $property, $value) { |
|
589 | + protected function setType(string $property, $value) { |
|
590 | 590 | if (isset($value)) { |
591 | 591 | // complex? |
592 | 592 | if (isset($this->hydration[$property])) { |
@@ -610,7 +610,7 @@ discard block |
||
610 | 610 | * @param scalar $dehydrated |
611 | 611 | * @return array|object |
612 | 612 | */ |
613 | - protected function setType_hydrate (string $to, string $from, $dehydrated) { |
|
613 | + protected function setType_hydrate(string $to, string $from, $dehydrated) { |
|
614 | 614 | switch ($from) { |
615 | 615 | case 'DateTime': |
616 | 616 | /** |
@@ -633,7 +633,7 @@ discard block |
||
633 | 633 | * @param EntityInterface $entity |
634 | 634 | * @param array $values |
635 | 635 | */ |
636 | - protected function setValues (EntityInterface $entity, array $values): void { |
|
636 | + protected function setValues(EntityInterface $entity, array $values): void { |
|
637 | 637 | foreach ($values as $name => $value) { |
638 | 638 | if (isset($this->properties[$name])) { |
639 | 639 | $this->properties[$name]->setValue($entity, $this->setType($name, $value)); |
@@ -147,8 +147,7 @@ discard block |
||
147 | 147 | $doc = $rProp->getDocComment(); |
148 | 148 | if (preg_match(static::RX_IS_COLUMN, $doc)) { |
149 | 149 | $columns[] = $rProp->getName(); |
150 | - } |
|
151 | - elseif (preg_match(static::RX_EAV, $doc, $eav)) { |
|
150 | + } elseif (preg_match(static::RX_EAV, $doc, $eav)) { |
|
152 | 151 | preg_match(static::RX_EAV_VAR, $doc, $var); |
153 | 152 | $type = $var['type'] ?? 'string'; |
154 | 153 | $type = static::SCALARS[$type] ?? 'string'; |
@@ -513,8 +512,7 @@ discard block |
||
513 | 512 | public function save (EntityInterface $entity): int { |
514 | 513 | if (!$entity->getId()) { |
515 | 514 | $this->saveInsert($entity); |
516 | - } |
|
517 | - else { |
|
515 | + } else { |
|
518 | 516 | $this->saveUpdate($entity); |
519 | 517 | } |
520 | 518 | $this->saveEav($entity); |
@@ -637,8 +635,7 @@ discard block |
||
637 | 635 | foreach ($values as $name => $value) { |
638 | 636 | if (isset($this->properties[$name])) { |
639 | 637 | $this->properties[$name]->setValue($entity, $this->setType($name, $value)); |
640 | - } |
|
641 | - else { |
|
638 | + } else { |
|
642 | 639 | // attempt to set unknown fields directly on the instance. |
643 | 640 | $entity->{$name} = $value; |
644 | 641 | } |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | * @param string $name |
24 | 24 | * @param string $type |
25 | 25 | */ |
26 | - public function __construct (DB $db, string $name, string $type = 'string') { |
|
26 | + public function __construct(DB $db, string $name, string $type = 'string') { |
|
27 | 27 | parent::__construct($db, $name, ['entity', 'attribute', 'value']); |
28 | 28 | $this->type = $type; |
29 | 29 | } |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | * @param string $attribute |
36 | 36 | * @return bool |
37 | 37 | */ |
38 | - public function exists (int $id, string $attribute): bool { |
|
38 | + public function exists(int $id, string $attribute): bool { |
|
39 | 39 | $statement = $this->cache(__FUNCTION__, function() { |
40 | 40 | return $this->select(['COUNT(*) > 0'])->where('entity = ? AND attribute = ?')->prepare(); |
41 | 41 | }); |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | * @param array $match `[attribute => value]`. If empty, selects all IDs for entities having at least one attribute. |
54 | 54 | * @return Select |
55 | 55 | */ |
56 | - public function findAll (array $match) { |
|
56 | + public function findAll(array $match) { |
|
57 | 57 | $select = $this->select([$this['entity']]); |
58 | 58 | $prior = $this; |
59 | 59 | foreach ($match as $attribute => $value) { |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | /** |
73 | 73 | * @return string |
74 | 74 | */ |
75 | - final public function getType (): string { |
|
75 | + final public function getType(): string { |
|
76 | 76 | return $this->type; |
77 | 77 | } |
78 | 78 | |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | * @param int $id |
83 | 83 | * @return scalar[] `[attribute => value]` |
84 | 84 | */ |
85 | - public function load (int $id): array { |
|
85 | + public function load(int $id): array { |
|
86 | 86 | $statement = $this->cache(__FUNCTION__, function() { |
87 | 87 | $select = $this->select(['attribute', 'value']); |
88 | 88 | $select->where('entity = ?'); |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | * @param int[] $ids |
99 | 99 | * @return scalar[][] `[id => attribute => value] |
100 | 100 | */ |
101 | - public function loadAll (array $ids): array { |
|
101 | + public function loadAll(array $ids): array { |
|
102 | 102 | if (empty($ids)) { |
103 | 103 | return []; |
104 | 104 | } |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | * @param array $values `[attribute => value]` |
127 | 127 | * @return $this |
128 | 128 | */ |
129 | - public function save (int $id, array $values) { |
|
129 | + public function save(int $id, array $values) { |
|
130 | 130 | // delete stale |
131 | 131 | $this->delete([ |
132 | 132 | $this['entity']->isEqual($id), |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | * @param scalar $value |
167 | 167 | * @return scalar |
168 | 168 | */ |
169 | - protected function setType ($value) { |
|
169 | + protected function setType($value) { |
|
170 | 170 | settype($value, $this->type); |
171 | 171 | return $value; |
172 | 172 | } |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | * @param string $file |
84 | 84 | * @return static |
85 | 85 | */ |
86 | - public static function fromConfig (string $connection = 'default', string $file = 'db.config.php') { |
|
86 | + public static function fromConfig(string $connection = 'default', string $file = 'db.config.php') { |
|
87 | 87 | $config = (include "{$file}")[$connection]; |
88 | 88 | $args = [ |
89 | 89 | $config['dsn'], |
@@ -103,11 +103,11 @@ discard block |
||
103 | 103 | * @param int|array|Countable $count |
104 | 104 | * @return ExpressionInterface[] |
105 | 105 | */ |
106 | - public static function marks ($count): array { |
|
106 | + public static function marks($count): array { |
|
107 | 107 | static $mark; |
108 | 108 | $mark ??= new class implements ExpressionInterface { |
109 | 109 | |
110 | - public function __toString () { |
|
110 | + public function __toString() { |
|
111 | 111 | return '?'; |
112 | 112 | } |
113 | 113 | }; |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | * @param string[] $columns |
126 | 126 | * @return string[] `["column" => ":column"]` |
127 | 127 | */ |
128 | - public static function slots (array $columns): array { |
|
128 | + public static function slots(array $columns): array { |
|
129 | 129 | return array_combine($columns, array_map(function(string $column) { |
130 | 130 | return ':' . str_replace('.', '__', $column); |
131 | 131 | }, $columns)); |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | * @param string[] $columns |
136 | 136 | * @return string[] `["column" => "column=:column"]` |
137 | 137 | */ |
138 | - public static function slotsEqual (array $columns): array { |
|
138 | + public static function slotsEqual(array $columns): array { |
|
139 | 139 | $slots = static::slots($columns); |
140 | 140 | foreach ($slots as $column => $slot) { |
141 | 141 | $slots[$column] = "{$column} = {$slot}"; |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | * @param string $password |
154 | 154 | * @param array $options |
155 | 155 | */ |
156 | - public function __construct ($dsn, $username = null, $password = null, array $options = []) { |
|
156 | + public function __construct($dsn, $username = null, $password = null, array $options = []) { |
|
157 | 157 | $options[self::ATTR_STATEMENT_CLASS] ??= [Statement::class, [$this]]; |
158 | 158 | parent::__construct($dsn, $username, $password, $options); |
159 | 159 | $this->setAttribute(self::ATTR_DEFAULT_FETCH_MODE, self::FETCH_ASSOC); |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | } |
170 | 170 | elseif ($this->isSQLite()) { |
171 | 171 | // polyfill sqlite functions |
172 | - $this->sqliteCreateFunctions([ // deterministic functions |
|
172 | + $this->sqliteCreateFunctions([// deterministic functions |
|
173 | 173 | // https://www.sqlite.org/lang_mathfunc.html |
174 | 174 | 'ACOS' => 'acos', |
175 | 175 | 'ASIN' => 'asin', |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | 'SIGN' => fn($x) => ($x > 0) - ($x < 0), |
196 | 196 | ]); |
197 | 197 | |
198 | - $this->sqliteCreateFunctions([ // non-deterministic |
|
198 | + $this->sqliteCreateFunctions([// non-deterministic |
|
199 | 199 | 'RAND' => fn() => mt_rand() / mt_getrandmax(), |
200 | 200 | ], false); |
201 | 201 | } |
@@ -206,7 +206,7 @@ discard block |
||
206 | 206 | * |
207 | 207 | * @return string |
208 | 208 | */ |
209 | - final public function __toString () { |
|
209 | + final public function __toString() { |
|
210 | 210 | return $this->driver; |
211 | 211 | } |
212 | 212 | |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | * |
218 | 218 | * @return true |
219 | 219 | */ |
220 | - public function beginTransaction () { |
|
220 | + public function beginTransaction() { |
|
221 | 221 | assert($this->transactions >= 0); |
222 | 222 | if ($this->transactions === 0) { |
223 | 223 | $this->logger->__invoke("BEGIN TRANSACTION"); |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | * |
238 | 238 | * @return true |
239 | 239 | */ |
240 | - public function commit () { |
|
240 | + public function commit() { |
|
241 | 241 | assert($this->transactions > 0); |
242 | 242 | if ($this->transactions === 1) { |
243 | 243 | $this->logger->__invoke("COMMIT TRANSACTION"); |
@@ -257,7 +257,7 @@ discard block |
||
257 | 257 | * @param string $sql |
258 | 258 | * @return int |
259 | 259 | */ |
260 | - public function exec ($sql): int { |
|
260 | + public function exec($sql): int { |
|
261 | 261 | $this->logger->__invoke($sql); |
262 | 262 | return parent::exec($sql); |
263 | 263 | } |
@@ -273,14 +273,14 @@ discard block |
||
273 | 273 | * @param mixed ...$args |
274 | 274 | * @return mixed |
275 | 275 | */ |
276 | - public function factory (string $class, ...$args) { |
|
276 | + public function factory(string $class, ...$args) { |
|
277 | 277 | return new $class($this, ...$args); |
278 | 278 | } |
279 | 279 | |
280 | 280 | /** |
281 | 281 | * @return string |
282 | 282 | */ |
283 | - final public function getDriver (): string { |
|
283 | + final public function getDriver(): string { |
|
284 | 284 | return $this->driver; |
285 | 285 | } |
286 | 286 | |
@@ -290,14 +290,14 @@ discard block |
||
290 | 290 | * @param string $interface |
291 | 291 | * @return Junction |
292 | 292 | */ |
293 | - public function getJunction ($interface) { |
|
293 | + public function getJunction($interface) { |
|
294 | 294 | return $this->junctions[$interface] ??= Junction::fromInterface($this, $interface); |
295 | 295 | } |
296 | 296 | |
297 | 297 | /** |
298 | 298 | * @return Closure |
299 | 299 | */ |
300 | - public function getLogger () { |
|
300 | + public function getLogger() { |
|
301 | 301 | return $this->logger; |
302 | 302 | } |
303 | 303 | |
@@ -305,7 +305,7 @@ discard block |
||
305 | 305 | * @param string $dir |
306 | 306 | * @return Migrator |
307 | 307 | */ |
308 | - public function getMigrator () { |
|
308 | + public function getMigrator() { |
|
309 | 309 | return Migrator::factory($this, $this->migrations); |
310 | 310 | } |
311 | 311 | |
@@ -315,7 +315,7 @@ discard block |
||
315 | 315 | * @param string|EntityInterface $class |
316 | 316 | * @return Record |
317 | 317 | */ |
318 | - public function getRecord ($class) { |
|
318 | + public function getRecord($class) { |
|
319 | 319 | if (is_object($class)) { |
320 | 320 | $class = get_class($class); |
321 | 321 | } |
@@ -325,28 +325,28 @@ discard block |
||
325 | 325 | /** |
326 | 326 | * @return Schema |
327 | 327 | */ |
328 | - public function getSchema () { |
|
328 | + public function getSchema() { |
|
329 | 329 | return $this->schema; |
330 | 330 | } |
331 | 331 | |
332 | 332 | /** |
333 | 333 | * @return bool |
334 | 334 | */ |
335 | - final public function isMySQL (): bool { |
|
335 | + final public function isMySQL(): bool { |
|
336 | 336 | return $this->driver === 'mysql'; |
337 | 337 | } |
338 | 338 | |
339 | 339 | /** |
340 | 340 | * @return bool |
341 | 341 | */ |
342 | - final public function isPostgreSQL (): bool { |
|
342 | + final public function isPostgreSQL(): bool { |
|
343 | 343 | return $this->driver === 'pgsql'; |
344 | 344 | } |
345 | 345 | |
346 | 346 | /** |
347 | 347 | * @return bool |
348 | 348 | */ |
349 | - final public function isSQLite (): bool { |
|
349 | + final public function isSQLite(): bool { |
|
350 | 350 | return $this->driver === 'sqlite'; |
351 | 351 | } |
352 | 352 | |
@@ -369,7 +369,7 @@ discard block |
||
369 | 369 | * @param mixed $b |
370 | 370 | * @return Predicate |
371 | 371 | */ |
372 | - public function match ($a, $b) { |
|
372 | + public function match($a, $b) { |
|
373 | 373 | if ($b instanceof Closure) { |
374 | 374 | return $b->__invoke($a, $this); |
375 | 375 | } |
@@ -390,7 +390,7 @@ discard block |
||
390 | 390 | * |
391 | 391 | * @return Transaction |
392 | 392 | */ |
393 | - public function newTransaction () { |
|
393 | + public function newTransaction() { |
|
394 | 394 | return Transaction::factory($this); |
395 | 395 | } |
396 | 396 | |
@@ -400,7 +400,7 @@ discard block |
||
400 | 400 | * @param string $table |
401 | 401 | * @return bool |
402 | 402 | */ |
403 | - final public function offsetExists ($table): bool { |
|
403 | + final public function offsetExists($table): bool { |
|
404 | 404 | return (bool)$this->offsetGet($table); |
405 | 405 | } |
406 | 406 | |
@@ -410,7 +410,7 @@ discard block |
||
410 | 410 | * @param string $table |
411 | 411 | * @return null|Table |
412 | 412 | */ |
413 | - public function offsetGet ($table) { |
|
413 | + public function offsetGet($table) { |
|
414 | 414 | return $this->schema->getTable($table); |
415 | 415 | } |
416 | 416 | |
@@ -419,7 +419,7 @@ discard block |
||
419 | 419 | * @param $value |
420 | 420 | * @throws LogicException |
421 | 421 | */ |
422 | - final public function offsetSet ($offset, $value) { |
|
422 | + final public function offsetSet($offset, $value) { |
|
423 | 423 | throw new LogicException('The schema cannot be altered this way.'); |
424 | 424 | } |
425 | 425 | |
@@ -427,7 +427,7 @@ discard block |
||
427 | 427 | * @param $offset |
428 | 428 | * @throws LogicException |
429 | 429 | */ |
430 | - final public function offsetUnset ($offset) { |
|
430 | + final public function offsetUnset($offset) { |
|
431 | 431 | throw new LogicException('The schema cannot be altered this way.'); |
432 | 432 | } |
433 | 433 | |
@@ -436,7 +436,7 @@ discard block |
||
436 | 436 | * |
437 | 437 | * @return Num |
438 | 438 | */ |
439 | - public function pi () { |
|
439 | + public function pi() { |
|
440 | 440 | return Num::factory($this, "PI()"); |
441 | 441 | } |
442 | 442 | |
@@ -447,7 +447,7 @@ discard block |
||
447 | 447 | * @param array $options |
448 | 448 | * @return Statement |
449 | 449 | */ |
450 | - public function prepare ($sql, $options = []) { |
|
450 | + public function prepare($sql, $options = []) { |
|
451 | 451 | $this->logger->__invoke($sql); |
452 | 452 | /** @var Statement $statement */ |
453 | 453 | $statement = parent::prepare($sql, $options); |
@@ -463,7 +463,7 @@ discard block |
||
463 | 463 | * @param array $ctorargs Optional. |
464 | 464 | * @return Statement |
465 | 465 | */ |
466 | - public function query ($sql, $mode = PDO::ATTR_DEFAULT_FETCH_MODE, $arg3 = null, array $ctorargs = []) { |
|
466 | + public function query($sql, $mode = PDO::ATTR_DEFAULT_FETCH_MODE, $arg3 = null, array $ctorargs = []) { |
|
467 | 467 | $this->logger->__invoke($sql); |
468 | 468 | /** @var Statement $statement */ |
469 | 469 | $statement = parent::query(...func_get_args()); |
@@ -481,7 +481,7 @@ discard block |
||
481 | 481 | * @param int $type Ignored. |
482 | 482 | * @return string|ExpressionInterface |
483 | 483 | */ |
484 | - public function quote ($value, $type = self::PARAM_STR) { |
|
484 | + public function quote($value, $type = self::PARAM_STR) { |
|
485 | 485 | if ($value instanceof ExpressionInterface) { |
486 | 486 | return $value; |
487 | 487 | } |
@@ -501,7 +501,7 @@ discard block |
||
501 | 501 | * @param array $values |
502 | 502 | * @return string[] |
503 | 503 | */ |
504 | - public function quoteArray (array $values) { |
|
504 | + public function quoteArray(array $values) { |
|
505 | 505 | return array_map([$this, 'quote'], $values); |
506 | 506 | } |
507 | 507 | |
@@ -511,7 +511,7 @@ discard block |
||
511 | 511 | * @param array $values |
512 | 512 | * @return string |
513 | 513 | */ |
514 | - public function quoteList (array $values): string { |
|
514 | + public function quoteList(array $values): string { |
|
515 | 515 | return implode(',', $this->quoteArray($values)); |
516 | 516 | } |
517 | 517 | |
@@ -520,7 +520,7 @@ discard block |
||
520 | 520 | * |
521 | 521 | * @return Num |
522 | 522 | */ |
523 | - public function rand () { |
|
523 | + public function rand() { |
|
524 | 524 | return Num::factory($this, "RAND()"); |
525 | 525 | } |
526 | 526 | |
@@ -531,7 +531,7 @@ discard block |
||
531 | 531 | * |
532 | 532 | * @return true |
533 | 533 | */ |
534 | - public function rollBack () { |
|
534 | + public function rollBack() { |
|
535 | 535 | assert($this->transactions > 0); |
536 | 536 | if ($this->transactions === 1) { |
537 | 537 | $this->logger->__invoke("ROLLBACK TRANSACTION"); |
@@ -551,7 +551,7 @@ discard block |
||
551 | 551 | * @param EntityInterface $entity |
552 | 552 | * @return int ID |
553 | 553 | */ |
554 | - public function save (EntityInterface $entity): int { |
|
554 | + public function save(EntityInterface $entity): int { |
|
555 | 555 | return $this->getRecord($entity)->save($entity); |
556 | 556 | } |
557 | 557 | |
@@ -560,7 +560,7 @@ discard block |
||
560 | 560 | * @param Junction $junction |
561 | 561 | * @return $this |
562 | 562 | */ |
563 | - public function setJunction (string $interface, Junction $junction) { |
|
563 | + public function setJunction(string $interface, Junction $junction) { |
|
564 | 564 | $this->junctions[$interface] = $junction; |
565 | 565 | return $this; |
566 | 566 | } |
@@ -569,7 +569,7 @@ discard block |
||
569 | 569 | * @param Closure $logger |
570 | 570 | * @return $this |
571 | 571 | */ |
572 | - public function setLogger (Closure $logger) { |
|
572 | + public function setLogger(Closure $logger) { |
|
573 | 573 | $this->logger = $logger; |
574 | 574 | return $this; |
575 | 575 | } |
@@ -579,7 +579,7 @@ discard block |
||
579 | 579 | * @param Record $record |
580 | 580 | * @return $this |
581 | 581 | */ |
582 | - public function setRecord (string $class, Record $record) { |
|
582 | + public function setRecord(string $class, Record $record) { |
|
583 | 583 | $this->records[$class] = $record; |
584 | 584 | return $this; |
585 | 585 | } |
@@ -588,7 +588,7 @@ discard block |
||
588 | 588 | * @param callable[] $callbacks Keyed by function name. |
589 | 589 | * @param bool $deterministic Whether the callbacks aren't random / are without side-effects. |
590 | 590 | */ |
591 | - public function sqliteCreateFunctions (array $callbacks, bool $deterministic = true): void { |
|
591 | + public function sqliteCreateFunctions(array $callbacks, bool $deterministic = true): void { |
|
592 | 592 | $deterministic = $deterministic ? self::SQLITE_DETERMINISTIC : 0; |
593 | 593 | foreach ($callbacks as $name => $callback) { |
594 | 594 | $argc = (new ReflectionFunction($callback))->getNumberOfRequiredParameters(); |
@@ -604,7 +604,7 @@ discard block |
||
604 | 604 | * @param callable $work |
605 | 605 | * @return mixed The return value of `$work` |
606 | 606 | */ |
607 | - public function transact (callable $work) { |
|
607 | + public function transact(callable $work) { |
|
608 | 608 | $transaction = $this->newTransaction(); |
609 | 609 | $return = call_user_func($work); |
610 | 610 | $transaction->commit(); |
@@ -166,8 +166,7 @@ discard block |
||
166 | 166 | |
167 | 167 | if ($this->isMySQL()) { |
168 | 168 | $this->exec("SET time_zone = 'UTC'"); |
169 | - } |
|
170 | - elseif ($this->isSQLite()) { |
|
169 | + } elseif ($this->isSQLite()) { |
|
171 | 170 | // polyfill sqlite functions |
172 | 171 | $this->sqliteCreateFunctions([ // deterministic functions |
173 | 172 | // https://www.sqlite.org/lang_mathfunc.html |
@@ -222,8 +221,7 @@ discard block |
||
222 | 221 | if ($this->transactions === 0) { |
223 | 222 | $this->logger->__invoke("BEGIN TRANSACTION"); |
224 | 223 | parent::beginTransaction(); |
225 | - } |
|
226 | - else { |
|
224 | + } else { |
|
227 | 225 | $this->exec("SAVEPOINT SAVEPOINT_{$this->transactions}"); |
228 | 226 | } |
229 | 227 | $this->transactions++; |
@@ -242,8 +240,7 @@ discard block |
||
242 | 240 | if ($this->transactions === 1) { |
243 | 241 | $this->logger->__invoke("COMMIT TRANSACTION"); |
244 | 242 | parent::commit(); |
245 | - } |
|
246 | - else { |
|
243 | + } else { |
|
247 | 244 | $savepoint = $this->transactions - 1; |
248 | 245 | $this->exec("RELEASE SAVEPOINT SAVEPOINT_{$savepoint}"); |
249 | 246 | } |
@@ -536,8 +533,7 @@ discard block |
||
536 | 533 | if ($this->transactions === 1) { |
537 | 534 | $this->logger->__invoke("ROLLBACK TRANSACTION"); |
538 | 535 | parent::rollBack(); |
539 | - } |
|
540 | - else { |
|
536 | + } else { |
|
541 | 537 | $savepoint = $this->transactions - 1; |
542 | 538 | $this->exec("ROLLBACK TO SAVEPOINT SAVEPOINT_{$savepoint}"); |
543 | 539 | } |
@@ -14,7 +14,7 @@ |
||
14 | 14 | /** |
15 | 15 | * @return string |
16 | 16 | */ |
17 | - abstract public function __toString (); |
|
17 | + abstract public function __toString(); |
|
18 | 18 | |
19 | 19 | /** |
20 | 20 | * @var DB |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | * @return Predicate |
26 | 26 | * @internal |
27 | 27 | */ |
28 | - protected function _isRelational ($arg, string $oper, string $multi) { |
|
28 | + protected function _isRelational($arg, string $oper, string $multi) { |
|
29 | 29 | static $inverse = [ |
30 | 30 | '<' => '>=', |
31 | 31 | '<=' => '>', |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | * @param null|scalar|Select $arg |
55 | 55 | * @return Predicate |
56 | 56 | */ |
57 | - public function is ($arg): Predicate { |
|
57 | + public function is($arg): Predicate { |
|
58 | 58 | if ($arg instanceof Select) { |
59 | 59 | if ($this->db->isSQLite()) { |
60 | 60 | return Select::factory($this->db, $arg, [$arg[0]]) |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | * @param number $max |
83 | 83 | * @return Predicate |
84 | 84 | */ |
85 | - public function isBetween ($min, $max) { |
|
85 | + public function isBetween($min, $max) { |
|
86 | 86 | $min = $this->db->quote($min); |
87 | 87 | $max = $this->db->quote($max); |
88 | 88 | return Predicate::factory($this->db, "{$this} BETWEEN {$min} AND {$max}"); |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | * @param scalar|array|Select $arg |
95 | 95 | * @return Predicate |
96 | 96 | */ |
97 | - public function isEqual ($arg) { |
|
97 | + public function isEqual($arg) { |
|
98 | 98 | return $this->db->match($this, $arg); |
99 | 99 | } |
100 | 100 | |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | * |
104 | 104 | * @return Predicate |
105 | 105 | */ |
106 | - public function isFalse () { |
|
106 | + public function isFalse() { |
|
107 | 107 | return Predicate::factory($this->db, "{$this} IS FALSE"); |
108 | 108 | } |
109 | 109 | |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | * @param number|string|Select $arg |
114 | 114 | * @return Predicate |
115 | 115 | */ |
116 | - public function isGt ($arg) { |
|
116 | + public function isGt($arg) { |
|
117 | 117 | return $this->_isRelational($arg, '>', 'ALL'); |
118 | 118 | } |
119 | 119 | |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | * @param Select $select |
124 | 124 | * @return Predicate |
125 | 125 | */ |
126 | - public function isGtAny (Select $select) { |
|
126 | + public function isGtAny(Select $select) { |
|
127 | 127 | return $this->_isRelational($select, '>', 'ANY'); |
128 | 128 | } |
129 | 129 | |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | * @param number|string|Select $arg |
134 | 134 | * @return Predicate |
135 | 135 | */ |
136 | - public function isGte ($arg) { |
|
136 | + public function isGte($arg) { |
|
137 | 137 | return $this->_isRelational($arg, '>=', 'ALL'); |
138 | 138 | } |
139 | 139 | |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | * @param Select $select |
144 | 144 | * @return Predicate |
145 | 145 | */ |
146 | - public function isGteAny (Select $select) { |
|
146 | + public function isGteAny(Select $select) { |
|
147 | 147 | return $this->_isRelational($select, '>=', 'ANY'); |
148 | 148 | } |
149 | 149 | |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | * @param string $pattern |
154 | 154 | * @return Predicate |
155 | 155 | */ |
156 | - public function isLike (string $pattern) { |
|
156 | + public function isLike(string $pattern) { |
|
157 | 157 | $pattern = $this->db->quote($pattern); |
158 | 158 | return Predicate::factory($this->db, "{$this} LIKE {$pattern}"); |
159 | 159 | } |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | * @param number|string|Select $arg |
165 | 165 | * @return Predicate |
166 | 166 | */ |
167 | - public function isLt ($arg) { |
|
167 | + public function isLt($arg) { |
|
168 | 168 | return $this->_isRelational($arg, '<', 'ALL'); |
169 | 169 | } |
170 | 170 | |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | * @param Select $select |
175 | 175 | * @return Predicate |
176 | 176 | */ |
177 | - public function isLtAny (Select $select) { |
|
177 | + public function isLtAny(Select $select) { |
|
178 | 178 | return $this->_isRelational($select, '<', 'ANY'); |
179 | 179 | } |
180 | 180 | |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | * @param number|string|Select $arg |
185 | 185 | * @return Predicate |
186 | 186 | */ |
187 | - public function isLte ($arg) { |
|
187 | + public function isLte($arg) { |
|
188 | 188 | return $this->_isRelational($arg, '<=', 'ALL'); |
189 | 189 | } |
190 | 190 | |
@@ -194,7 +194,7 @@ discard block |
||
194 | 194 | * @param Select $select |
195 | 195 | * @return Predicate |
196 | 196 | */ |
197 | - public function isLteAny (Select $select) { |
|
197 | + public function isLteAny(Select $select) { |
|
198 | 198 | return $this->_isRelational($select, '<=', 'ANY'); |
199 | 199 | } |
200 | 200 | |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | * @param null|scalar|Select $arg |
205 | 205 | * @return Predicate |
206 | 206 | */ |
207 | - public function isNot ($arg) { |
|
207 | + public function isNot($arg) { |
|
208 | 208 | return $this->is($arg)->not(); |
209 | 209 | } |
210 | 210 | |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | * @param number $max |
216 | 216 | * @return Predicate |
217 | 217 | */ |
218 | - public function isNotBetween ($min, $max) { |
|
218 | + public function isNotBetween($min, $max) { |
|
219 | 219 | $min = $this->db->quote($min); |
220 | 220 | $max = $this->db->quote($max); |
221 | 221 | return Predicate::factory($this->db, "{$this} NOT BETWEEN {$min} AND {$max}"); |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | * @param scalar|array|Select $arg |
228 | 228 | * @return Predicate |
229 | 229 | */ |
230 | - public function isNotEqual ($arg) { |
|
230 | + public function isNotEqual($arg) { |
|
231 | 231 | if ($arg instanceof Select) { |
232 | 232 | return Predicate::factory($this->db, "{$this} NOT IN ({$arg->toSql()})"); |
233 | 233 | } |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | * @param string $pattern |
244 | 244 | * @return Predicate |
245 | 245 | */ |
246 | - public function isNotLike (string $pattern) { |
|
246 | + public function isNotLike(string $pattern) { |
|
247 | 247 | $pattern = $this->db->quote($pattern); |
248 | 248 | return Predicate::factory($this->db, "{$this} NOT LIKE {$pattern}"); |
249 | 249 | } |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | * |
254 | 254 | * @return Predicate |
255 | 255 | */ |
256 | - public function isNotNull () { |
|
256 | + public function isNotNull() { |
|
257 | 257 | return Predicate::factory($this->db, "{$this} IS NOT NULL"); |
258 | 258 | } |
259 | 259 | |
@@ -263,7 +263,7 @@ discard block |
||
263 | 263 | * @param string $pattern |
264 | 264 | * @return Predicate |
265 | 265 | */ |
266 | - public function isNotRegExp (string $pattern) { |
|
266 | + public function isNotRegExp(string $pattern) { |
|
267 | 267 | $pattern = $this->db->quote($pattern); |
268 | 268 | return Predicate::factory($this->db, "{$this} NOT REGEXP {$pattern}"); |
269 | 269 | } |
@@ -273,7 +273,7 @@ discard block |
||
273 | 273 | * |
274 | 274 | * @return Predicate |
275 | 275 | */ |
276 | - public function isNull () { |
|
276 | + public function isNull() { |
|
277 | 277 | return Predicate::factory($this->db, "{$this} IS NULL"); |
278 | 278 | } |
279 | 279 | |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | * @param string $pattern |
284 | 284 | * @return Predicate |
285 | 285 | */ |
286 | - public function isRegExp (string $pattern) { |
|
286 | + public function isRegExp(string $pattern) { |
|
287 | 287 | $pattern = $this->db->quote($pattern); |
288 | 288 | return Predicate::factory($this->db, "{$this} REGEXP {$pattern}"); |
289 | 289 | } |
@@ -64,8 +64,7 @@ |
||
64 | 64 | } |
65 | 65 | if ($arg === null or is_bool($arg)) { |
66 | 66 | $arg = ['' => 'NULL', 1 => 'TRUE', 0 => 'FALSE'][$arg]; |
67 | - } |
|
68 | - else { |
|
67 | + } else { |
|
69 | 68 | $arg = $this->db->quote($arg); |
70 | 69 | } |
71 | 70 | if ($this->db->isMySQL()) { |