Passed
Push — master ( f39217...bc6df6 )
by y
02:20
created
bin/helix.db.migrate.php 5 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -99,4 +99,4 @@
 block discarded – undo
99 99
 }
100 100
 
101 101
 $current = $current ?: 'NONE';
102
-$stdout("Current Migration State: \"{$current}\"");
102
+$stdout("Current Migration State: \"{$current}
103 103
\ No newline at end of file
Please login to merge, or discard this patch.
Switch Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -99,4 +99,4 @@
 block discarded – undo
99 99
 }
100 100
 
101 101
 $current = $current ?: 'NONE';
102
-$stdout("Current Migration State: \"{$current}\"");
102
+$stdout("Current Migration State: \"{$current}
103 103
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -99,4 +99,4 @@
 block discarded – undo
99 99
 }
100 100
 
101 101
 $current = $current ?: 'NONE';
102
-$stdout("Current Migration State: \"{$current}\"");
102
+$stdout("Current Migration State: \"{$current}
103 103
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -99,4 +99,4 @@
 block discarded – undo
99 99
 }
100 100
 
101 101
 $current = $current ?: 'NONE';
102
-$stdout("Current Migration State: \"{$current}\"");
102
+$stdout("Current Migration State: \"{$current}
103 103
\ No newline at end of file
Please login to merge, or discard this patch.
Upper-Lower-Casing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -99,4 +99,4 @@
 block discarded – undo
99 99
 }
100 100
 
101 101
 $current = $current ?: 'NONE';
102
-$stdout("Current Migration State: \"{$current}\"");
102
+$stdout("Current Migration State: \"{$current}
103 103
\ No newline at end of file
Please login to merge, or discard this patch.
src/DB.php 2 patches
Spacing   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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);
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
 
167 167
         if ($this->isSQLite()) {
168 168
             // polyfill sqlite functions
169
-            $this->sqliteCreateFunctions([ // deterministic functions
169
+            $this->sqliteCreateFunctions([// deterministic functions
170 170
                 // https://www.sqlite.org/lang_mathfunc.html
171 171
                 'ACOS' => 'acos',
172 172
                 'ASIN' => 'asin',
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
                 'SIGN' => fn($x) => ($x > 0) - ($x < 0),
193 193
             ]);
194 194
 
195
-            $this->sqliteCreateFunctions([ // non-deterministic
195
+            $this->sqliteCreateFunctions([// non-deterministic
196 196
                 'RAND' => fn() => mt_rand() / mt_getrandmax(),
197 197
             ], false);
198 198
         }
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
      *
204 204
      * @return string
205 205
      */
206
-    final public function __toString () {
206
+    final public function __toString() {
207 207
         return $this->driver;
208 208
     }
209 209
 
@@ -214,7 +214,7 @@  discard block
 block discarded – undo
214 214
      *
215 215
      * @return true
216 216
      */
217
-    public function beginTransaction () {
217
+    public function beginTransaction() {
218 218
         assert($this->transactions >= 0);
219 219
         if ($this->transactions === 0) {
220 220
             $this->logger->__invoke("BEGIN TRANSACTION");
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
      *
235 235
      * @return true
236 236
      */
237
-    public function commit () {
237
+    public function commit() {
238 238
         assert($this->transactions > 0);
239 239
         if ($this->transactions === 1) {
240 240
             $this->logger->__invoke("COMMIT TRANSACTION");
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
      * @param string $sql
255 255
      * @return int
256 256
      */
257
-    public function exec ($sql): int {
257
+    public function exec($sql): int {
258 258
         $this->logger->__invoke($sql);
259 259
         return parent::exec($sql);
260 260
     }
@@ -270,14 +270,14 @@  discard block
 block discarded – undo
270 270
      * @param mixed ...$args
271 271
      * @return mixed
272 272
      */
273
-    public function factory (string $class, ...$args) {
273
+    public function factory(string $class, ...$args) {
274 274
         return new $class($this, ...$args);
275 275
     }
276 276
 
277 277
     /**
278 278
      * @return string
279 279
      */
280
-    final public function getDriver (): string {
280
+    final public function getDriver(): string {
281 281
         return $this->driver;
282 282
     }
283 283
 
@@ -287,14 +287,14 @@  discard block
 block discarded – undo
287 287
      * @param string $interface
288 288
      * @return Junction
289 289
      */
290
-    public function getJunction ($interface) {
290
+    public function getJunction($interface) {
291 291
         return $this->junctions[$interface] ??= Junction::fromInterface($this, $interface);
292 292
     }
293 293
 
294 294
     /**
295 295
      * @return Closure
296 296
      */
297
-    public function getLogger () {
297
+    public function getLogger() {
298 298
         return $this->logger;
299 299
     }
300 300
 
@@ -302,7 +302,7 @@  discard block
 block discarded – undo
302 302
      * @param string $dir
303 303
      * @return Migrator
304 304
      */
305
-    public function getMigrator () {
305
+    public function getMigrator() {
306 306
         return Migrator::factory($this, $this->migrations);
307 307
     }
308 308
 
@@ -312,7 +312,7 @@  discard block
 block discarded – undo
312 312
      * @param string|EntityInterface $class
313 313
      * @return Record
314 314
      */
315
-    public function getRecord ($class) {
315
+    public function getRecord($class) {
316 316
         if (is_object($class)) {
317 317
             $class = get_class($class);
318 318
         }
@@ -322,28 +322,28 @@  discard block
 block discarded – undo
322 322
     /**
323 323
      * @return Schema
324 324
      */
325
-    public function getSchema () {
325
+    public function getSchema() {
326 326
         return $this->schema;
327 327
     }
328 328
 
329 329
     /**
330 330
      * @return bool
331 331
      */
332
-    final public function isMySQL (): bool {
332
+    final public function isMySQL(): bool {
333 333
         return $this->driver === 'mysql';
334 334
     }
335 335
 
336 336
     /**
337 337
      * @return bool
338 338
      */
339
-    final public function isPostgreSQL (): bool {
339
+    final public function isPostgreSQL(): bool {
340 340
         return $this->driver === 'pgsql';
341 341
     }
342 342
 
343 343
     /**
344 344
      * @return bool
345 345
      */
346
-    final public function isSQLite (): bool {
346
+    final public function isSQLite(): bool {
347 347
         return $this->driver === 'sqlite';
348 348
     }
349 349
 
@@ -366,7 +366,7 @@  discard block
 block discarded – undo
366 366
      * @param mixed $b
367 367
      * @return Predicate
368 368
      */
369
-    public function match ($a, $b) {
369
+    public function match($a, $b) {
370 370
         if ($b instanceof Closure) {
371 371
             return $b->__invoke($a, $this);
372 372
         }
@@ -387,7 +387,7 @@  discard block
 block discarded – undo
387 387
      *
388 388
      * @return Transaction
389 389
      */
390
-    public function newTransaction () {
390
+    public function newTransaction() {
391 391
         return Transaction::factory($this);
392 392
     }
393 393
 
@@ -397,7 +397,7 @@  discard block
 block discarded – undo
397 397
      * @param string $table
398 398
      * @return bool
399 399
      */
400
-    final public function offsetExists ($table): bool {
400
+    final public function offsetExists($table): bool {
401 401
         return (bool)$this->offsetGet($table);
402 402
     }
403 403
 
@@ -407,7 +407,7 @@  discard block
 block discarded – undo
407 407
      * @param string $table
408 408
      * @return null|Table
409 409
      */
410
-    public function offsetGet ($table) {
410
+    public function offsetGet($table) {
411 411
         return $this->schema->getTable($table);
412 412
     }
413 413
 
@@ -416,7 +416,7 @@  discard block
 block discarded – undo
416 416
      * @param $value
417 417
      * @throws LogicException
418 418
      */
419
-    final public function offsetSet ($offset, $value) {
419
+    final public function offsetSet($offset, $value) {
420 420
         throw new LogicException('The schema cannot be altered this way.');
421 421
     }
422 422
 
@@ -424,7 +424,7 @@  discard block
 block discarded – undo
424 424
      * @param $offset
425 425
      * @throws LogicException
426 426
      */
427
-    final public function offsetUnset ($offset) {
427
+    final public function offsetUnset($offset) {
428 428
         throw new LogicException('The schema cannot be altered this way.');
429 429
     }
430 430
 
@@ -433,7 +433,7 @@  discard block
 block discarded – undo
433 433
      *
434 434
      * @return Num
435 435
      */
436
-    public function pi () {
436
+    public function pi() {
437 437
         return Num::factory($this, "PI()");
438 438
     }
439 439
 
@@ -444,7 +444,7 @@  discard block
 block discarded – undo
444 444
      * @param array $options
445 445
      * @return Statement
446 446
      */
447
-    public function prepare ($sql, $options = []) {
447
+    public function prepare($sql, $options = []) {
448 448
         $this->logger->__invoke($sql);
449 449
         /** @var Statement $statement */
450 450
         $statement = parent::prepare($sql, $options);
@@ -460,7 +460,7 @@  discard block
 block discarded – undo
460 460
      * @param array $ctorargs Optional.
461 461
      * @return Statement
462 462
      */
463
-    public function query ($sql, $mode = PDO::ATTR_DEFAULT_FETCH_MODE, $arg3 = null, array $ctorargs = []) {
463
+    public function query($sql, $mode = PDO::ATTR_DEFAULT_FETCH_MODE, $arg3 = null, array $ctorargs = []) {
464 464
         $this->logger->__invoke($sql);
465 465
         /** @var Statement $statement */
466 466
         $statement = parent::query(...func_get_args());
@@ -478,7 +478,7 @@  discard block
 block discarded – undo
478 478
      * @param int $type Ignored.
479 479
      * @return string|ExpressionInterface
480 480
      */
481
-    public function quote ($value, $type = self::PARAM_STR) {
481
+    public function quote($value, $type = self::PARAM_STR) {
482 482
         if ($value instanceof ExpressionInterface) {
483 483
             return $value;
484 484
         }
@@ -498,7 +498,7 @@  discard block
 block discarded – undo
498 498
      * @param array $values
499 499
      * @return string[]
500 500
      */
501
-    public function quoteArray (array $values) {
501
+    public function quoteArray(array $values) {
502 502
         return array_map([$this, 'quote'], $values);
503 503
     }
504 504
 
@@ -508,7 +508,7 @@  discard block
 block discarded – undo
508 508
      * @param array $values
509 509
      * @return string
510 510
      */
511
-    public function quoteList (array $values): string {
511
+    public function quoteList(array $values): string {
512 512
         return implode(',', $this->quoteArray($values));
513 513
     }
514 514
 
@@ -517,7 +517,7 @@  discard block
 block discarded – undo
517 517
      *
518 518
      * @return Num
519 519
      */
520
-    public function rand () {
520
+    public function rand() {
521 521
         return Num::factory($this, "RAND()");
522 522
     }
523 523
 
@@ -528,7 +528,7 @@  discard block
 block discarded – undo
528 528
      *
529 529
      * @return true
530 530
      */
531
-    public function rollBack () {
531
+    public function rollBack() {
532 532
         assert($this->transactions > 0);
533 533
         if ($this->transactions === 1) {
534 534
             $this->logger->__invoke("ROLLBACK TRANSACTION");
@@ -548,7 +548,7 @@  discard block
 block discarded – undo
548 548
      * @param EntityInterface $entity
549 549
      * @return int ID
550 550
      */
551
-    public function save (EntityInterface $entity): int {
551
+    public function save(EntityInterface $entity): int {
552 552
         return $this->getRecord($entity)->save($entity);
553 553
     }
554 554
 
@@ -557,7 +557,7 @@  discard block
 block discarded – undo
557 557
      * @param Junction $junction
558 558
      * @return $this
559 559
      */
560
-    public function setJunction (string $interface, Junction $junction) {
560
+    public function setJunction(string $interface, Junction $junction) {
561 561
         $this->junctions[$interface] = $junction;
562 562
         return $this;
563 563
     }
@@ -566,7 +566,7 @@  discard block
 block discarded – undo
566 566
      * @param Closure $logger
567 567
      * @return $this
568 568
      */
569
-    public function setLogger (Closure $logger) {
569
+    public function setLogger(Closure $logger) {
570 570
         $this->logger = $logger;
571 571
         return $this;
572 572
     }
@@ -576,7 +576,7 @@  discard block
 block discarded – undo
576 576
      * @param Record $record
577 577
      * @return $this
578 578
      */
579
-    public function setRecord (string $class, Record $record) {
579
+    public function setRecord(string $class, Record $record) {
580 580
         $this->records[$class] = $record;
581 581
         return $this;
582 582
     }
@@ -585,7 +585,7 @@  discard block
 block discarded – undo
585 585
      * @param callable[] $callbacks Keyed by function name.
586 586
      * @param bool $deterministic Whether the callbacks aren't random / are without side-effects.
587 587
      */
588
-    public function sqliteCreateFunctions (array $callbacks, bool $deterministic = true): void {
588
+    public function sqliteCreateFunctions(array $callbacks, bool $deterministic = true): void {
589 589
         $deterministic = $deterministic ? self::SQLITE_DETERMINISTIC : 0;
590 590
         foreach ($callbacks as $name => $callback) {
591 591
             $argc = (new ReflectionFunction($callback))->getNumberOfRequiredParameters();
@@ -601,7 +601,7 @@  discard block
 block discarded – undo
601 601
      * @param callable $work
602 602
      * @return mixed The return value of `$work`
603 603
      */
604
-    public function transact (callable $work) {
604
+    public function transact(callable $work) {
605 605
         $transaction = $this->newTransaction();
606 606
         $return = call_user_func($work);
607 607
         $transaction->commit();
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -219,8 +219,7 @@  discard block
 block discarded – undo
219 219
         if ($this->transactions === 0) {
220 220
             $this->logger->__invoke("BEGIN TRANSACTION");
221 221
             parent::beginTransaction();
222
-        }
223
-        else {
222
+        } else {
224 223
             $this->exec("SAVEPOINT SAVEPOINT_{$this->transactions}");
225 224
         }
226 225
         $this->transactions++;
@@ -239,8 +238,7 @@  discard block
 block discarded – undo
239 238
         if ($this->transactions === 1) {
240 239
             $this->logger->__invoke("COMMIT TRANSACTION");
241 240
             parent::commit();
242
-        }
243
-        else {
241
+        } else {
244 242
             $savepoint = $this->transactions - 1;
245 243
             $this->exec("RELEASE SAVEPOINT SAVEPOINT_{$savepoint}");
246 244
         }
@@ -533,8 +531,7 @@  discard block
 block discarded – undo
533 531
         if ($this->transactions === 1) {
534 532
             $this->logger->__invoke("ROLLBACK TRANSACTION");
535 533
             parent::rollBack();
536
-        }
537
-        else {
534
+        } else {
538 535
             $savepoint = $this->transactions - 1;
539 536
             $this->exec("ROLLBACK TO SAVEPOINT SAVEPOINT_{$savepoint}");
540 537
         }
Please login to merge, or discard this patch.
src/DB/Migrator.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
      * @param DB $db
31 31
      * @param string $dir
32 32
      */
33
-    public function __construct (DB $db, string $dir) {
33
+    public function __construct(DB $db, string $dir) {
34 34
         $this->db = $db;
35 35
         $this->dir = $dir;
36 36
         $this->table ??= $db['__migrations__'] ?? $db->getSchema()->createTable('__migrations__', [
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
      * @param string $to Migration sequence identifier, or `null` to step down once.
45 45
      * @return false|string The resulting current sequence identifier.
46 46
      */
47
-    public function down (string $to = null) {
47
+    public function down(string $to = null) {
48 48
         return $this->db->transact(function() use ($to) {
49 49
             $current = $this->getCurrent();
50 50
             // walk newest to oldest
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
      *
74 74
      * @return null|string
75 75
      */
76
-    public function getCurrent (): ?string {
76
+    public function getCurrent(): ?string {
77 77
         return $this->table->select([$this->table['sequence']->max()])->getResult();
78 78
     }
79 79
 
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
      * @param array $spec
82 82
      * @return MigrationInterface
83 83
      */
84
-    protected function getMigration (array $spec) {
84
+    protected function getMigration(array $spec) {
85 85
         include_once "{$spec['file']}";
86 86
         $migration = new $spec['class'];
87 87
         assert($migration instanceof MigrationInterface);
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
      *
94 94
      * @return array[] [ file => spec array ]
95 95
      */
96
-    protected function glob () {
96
+    protected function glob() {
97 97
         $specs = [];
98 98
         $files = glob("{$this->dir}/?*_?*.php");
99 99
         foreach ($files as $file) {
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
      * @param null|string $to Migration sequence identifier, or `null` for all upgrades.
113 113
      * @return false|string The resulting current sequence identifier.
114 114
      */
115
-    public function up (string $to = null) {
115
+    public function up(string $to = null) {
116 116
         return $this->db->transact(function() use ($to) {
117 117
             $current = $this->getCurrent();
118 118
             // walk oldest to newest
Please login to merge, or discard this patch.
src/DB/EAV.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
      * @param string $name
22 22
      * @param string $valueType PHP-native scalar type (implied nullable).
23 23
      */
24
-    public function __construct (DB $db, string $name, string $valueType = 'string') {
24
+    public function __construct(DB $db, string $name, string $valueType = 'string') {
25 25
         parent::__construct($db, $name, ['entity', 'attribute', 'value']);
26 26
         $this->valueType = $valueType;
27 27
     }
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
      * @param string $attribute
34 34
      * @return bool
35 35
      */
36
-    public function exists (int $id, string $attribute): bool {
36
+    public function exists(int $id, string $attribute): bool {
37 37
         $statement = $this->cache(__FUNCTION__, function() {
38 38
             return $this->select(['COUNT(*) > 0'])->where('entity = ? AND attribute = ?')->prepare();
39 39
         });
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
      * @param array $match `[attribute => value]`. If empty, selects all IDs for entities having at least one attribute.
52 52
      * @return Select
53 53
      */
54
-    public function find (array $match) {
54
+    public function find(array $match) {
55 55
         $select = $this->select([$this['entity']]);
56 56
         $prior = $this;
57 57
         foreach ($match as $attribute => $value) {
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
     /**
71 71
      * @return string
72 72
      */
73
-    final public function getValueType (): string {
73
+    final public function getValueType(): string {
74 74
         return $this->valueType;
75 75
     }
76 76
 
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
      * @param int $id
81 81
      * @return array `[attribute => value]`
82 82
      */
83
-    public function load (int $id): array {
83
+    public function load(int $id): array {
84 84
         $statement = $this->cache(__FUNCTION__, function() {
85 85
             $select = $this->select(['attribute', 'value']);
86 86
             $select->where('entity = ?');
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
      * @param int[] $ids
97 97
      * @return array[] `[id => attribute => value]
98 98
      */
99
-    public function loadAll (array $ids): array {
99
+    public function loadAll(array $ids): array {
100 100
         if (empty($ids)) {
101 101
             return [];
102 102
         }
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
      * @param array $values `[attribute => value]`
122 122
      * @return $this
123 123
      */
124
-    public function save (int $id, array $values) {
124
+    public function save(int $id, array $values) {
125 125
         $this->delete([
126 126
             $this['entity']->isEqual($id),
127 127
             $this['attribute']->isNotEqual(array_keys($values))
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
      * @param mixed $value
150 150
      * @return null|scalar
151 151
      */
152
-    protected function setType ($value) {
152
+    protected function setType($value) {
153 153
         if (isset($value)) {
154 154
             settype($value, $this->valueType);
155 155
         }
Please login to merge, or discard this patch.
src/DB/MigrationInterface.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -33,11 +33,11 @@
 block discarded – undo
33 33
      * @param DB $db
34 34
      * @return void
35 35
      */
36
-    public function down ($db);
36
+    public function down($db);
37 37
 
38 38
     /**
39 39
      * @param DB $db
40 40
      * @return void
41 41
      */
42
-    public function up ($db);
42
+    public function up($db);
43 43
 }
44 44
\ No newline at end of file
Please login to merge, or discard this patch.
src/DB/Record.php 2 patches
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
      * @param string|EntityInterface $class
78 78
      * @return Record
79 79
      */
80
-    public static function fromClass (DB $db, $class) {
80
+    public static function fromClass(DB $db, $class) {
81 81
         $rClass = new ReflectionClass($class);
82 82
         assert($rClass->isInstantiable());
83 83
         $columns = [];
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
      * @param string[] $columns Property names.
106 106
      * @param EAV[] $eav Keyed by property name.
107 107
      */
108
-    public function __construct (DB $db, EntityInterface $proto, string $table, array $columns, array $eav = []) {
108
+    public function __construct(DB $db, EntityInterface $proto, string $table, array $columns, array $eav = []) {
109 109
         parent::__construct($db, $table, $columns);
110 110
         $this->proto = $proto;
111 111
         $rClass = new ReflectionClass($proto);
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
      * @param array[] $eavMatch `[eav property => attribute => mixed]`
159 159
      * @return Select|EntityInterface[]
160 160
      */
161
-    public function find (array $match, array $eavMatch = []) {
161
+    public function find(array $match, array $eavMatch = []) {
162 162
         $select = $this->loadAll();
163 163
         foreach ($match as $a => $b) {
164 164
             $select->where($this->db->match($this[$a] ?? $a, $b));
@@ -176,14 +176,14 @@  discard block
 block discarded – undo
176 176
      * @param Statement $statement
177 177
      * @return EntityInterface[] Keyed by ID
178 178
      */
179
-    public function getAll (Statement $statement): array {
179
+    public function getAll(Statement $statement): array {
180 180
         return iterator_to_array($this->getEach($statement));
181 181
     }
182 182
 
183 183
     /**
184 184
      * @return string
185 185
      */
186
-    final public function getClass (): string {
186
+    final public function getClass(): string {
187 187
         return get_class($this->proto);
188 188
     }
189 189
 
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
      * @param Statement $statement
195 195
      * @return Generator|EntityInterface[] Keyed by ID
196 196
      */
197
-    public function getEach (Statement $statement) {
197
+    public function getEach(Statement $statement) {
198 198
         do {
199 199
             $entities = [];
200 200
             for ($i = 0; $i < 256 and false !== $row = $statement->fetch(); $i++) {
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
      * @param string $property
212 212
      * @return EAV
213 213
      */
214
-    final public function getEav (string $property) {
214
+    final public function getEav(string $property) {
215 215
         return $this->eav[$property];
216 216
     }
217 217
 
@@ -220,14 +220,14 @@  discard block
 block discarded – undo
220 220
      *
221 221
      * @return string[]
222 222
      */
223
-    final public function getProperties (): array {
223
+    final public function getProperties(): array {
224 224
         return array_keys($this->properties);
225 225
     }
226 226
 
227 227
     /**
228 228
      * @return EntityInterface
229 229
      */
230
-    public function getProto () {
230
+    public function getProto() {
231 231
         return $this->proto;
232 232
     }
233 233
 
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
      *
239 239
      * @return string[]
240 240
      */
241
-    final public function getTypes (): array {
241
+    final public function getTypes(): array {
242 242
         return $this->types;
243 243
     }
244 244
 
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
      * @param EntityInterface $entity
247 247
      * @return array
248 248
      */
249
-    protected function getValues (EntityInterface $entity): array {
249
+    protected function getValues(EntityInterface $entity): array {
250 250
         $values = [];
251 251
         foreach (array_keys($this->columns) as $name) {
252 252
             $values[$name] = $this->properties[$name]->getValue($entity);
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
      * @param string $property
259 259
      * @return bool
260 260
      */
261
-    final public function isNullable (string $property): bool {
261
+    final public function isNullable(string $property): bool {
262 262
         return $this->nullable[$property];
263 263
     }
264 264
 
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
      * @param int $id
269 269
      * @return null|EntityInterface
270 270
      */
271
-    public function load (int $id) {
271
+    public function load(int $id) {
272 272
         $statement = $this->cache(__FUNCTION__, function() {
273 273
             return $this->select()->where('id = ?')->prepare();
274 274
         });
@@ -288,7 +288,7 @@  discard block
 block discarded – undo
288 288
      *
289 289
      * @return Select|EntityInterface[]
290 290
      */
291
-    public function loadAll () {
291
+    public function loadAll() {
292 292
         return $this->select()->setFetcher(function(Statement $statement) {
293 293
             yield from $this->getEach($statement);
294 294
         });
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
      *
300 300
      * @param EntityInterface[] $entities
301 301
      */
302
-    protected function loadEav (array $entities): void {
302
+    protected function loadEav(array $entities): void {
303 303
         $ids = array_keys($entities);
304 304
         foreach ($this->eav as $name => $eav) {
305 305
             foreach ($eav->loadAll($ids) as $id => $values) {
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
      * @param EntityInterface $entity
315 315
      * @return int ID
316 316
      */
317
-    public function save (EntityInterface $entity): int {
317
+    public function save(EntityInterface $entity): int {
318 318
         if (!$entity->getId()) {
319 319
             $this->saveInsert($entity);
320 320
         }
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
     /**
329 329
      * @param EntityInterface $entity
330 330
      */
331
-    protected function saveEav (EntityInterface $entity): void {
331
+    protected function saveEav(EntityInterface $entity): void {
332 332
         $id = $entity->getId();
333 333
         foreach ($this->eav as $name => $eav) {
334 334
             // may be null to skip
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
      *
345 345
      * @param EntityInterface $entity
346 346
      */
347
-    protected function saveInsert (EntityInterface $entity): void {
347
+    protected function saveInsert(EntityInterface $entity): void {
348 348
         $statement = $this->cache(__FUNCTION__, function() {
349 349
             $slots = $this->db->slots(array_keys($this->columns));
350 350
             unset($slots['id']);
@@ -363,7 +363,7 @@  discard block
 block discarded – undo
363 363
      *
364 364
      * @param EntityInterface $entity
365 365
      */
366
-    protected function saveUpdate (EntityInterface $entity): void {
366
+    protected function saveUpdate(EntityInterface $entity): void {
367 367
         $statement = $this->cache(__FUNCTION__, function() {
368 368
             $slots = $this->db->slotsEqual(array_keys($this->columns));
369 369
             unset($slots['id']);
@@ -378,7 +378,7 @@  discard block
 block discarded – undo
378 378
      * @param EntityInterface $proto
379 379
      * @return $this
380 380
      */
381
-    public function setProto (EntityInterface $proto) {
381
+    public function setProto(EntityInterface $proto) {
382 382
         $this->proto = $proto;
383 383
         return $this;
384 384
     }
@@ -387,7 +387,7 @@  discard block
 block discarded – undo
387 387
      * @param EntityInterface $entity
388 388
      * @param array $values
389 389
      */
390
-    protected function setValues (EntityInterface $entity, array $values): void {
390
+    protected function setValues(EntityInterface $entity, array $values): void {
391 391
         foreach ($values as $name => $value) {
392 392
             if (isset($this->properties[$name])) {
393 393
                 settype($value, $this->types[$name]); // doesn't care about letter case
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -86,8 +86,7 @@  discard block
 block discarded – undo
86 86
         foreach ($rClass->getProperties() as $rProp) {
87 87
             if (preg_match('/@col(umn)?[\s$]/', $rProp->getDocComment())) {
88 88
                 $columns[] = $rProp->getName();
89
-            }
90
-            elseif (preg_match('/@eav\s+(?<table>\S+)/', $rProp->getDocComment(), $attr)) {
89
+            } elseif (preg_match('/@eav\s+(?<table>\S+)/', $rProp->getDocComment(), $attr)) {
91 90
                 $eav[$rProp->getName()] = EAV::factory($db, $attr['table']);
92 91
             }
93 92
         }
@@ -317,8 +316,7 @@  discard block
 block discarded – undo
317 316
     public function save (EntityInterface $entity): int {
318 317
         if (!$entity->getId()) {
319 318
             $this->saveInsert($entity);
320
-        }
321
-        else {
319
+        } else {
322 320
             $this->saveUpdate($entity);
323 321
         }
324 322
         $this->saveEav($entity);
@@ -392,8 +390,7 @@  discard block
 block discarded – undo
392 390
             if (isset($this->properties[$name])) {
393 391
                 settype($value, $this->types[$name]); // doesn't care about letter case
394 392
                 $this->properties[$name]->setValue($entity, $value);
395
-            }
396
-            else {
393
+            } else {
397 394
                 $entity->{$name} = $value;
398 395
             }
399 396
         }
Please login to merge, or discard this patch.
src/DB/Schema.php 2 patches
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
     /**
182 182
      * @param DB $db
183 183
      */
184
-    public function __construct (DB $db) {
184
+    public function __construct(DB $db) {
185 185
         $this->db = $db;
186 186
         $this->colDefs ??= self::COLUMN_DEFINITIONS[$db->getDriver()];
187 187
     }
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
      * @param int $type
195 195
      * @return $this
196 196
      */
197
-    public function addColumn (string $table, string $column, int $type = self::T_STRING) {
197
+    public function addColumn(string $table, string $column, int $type = self::T_STRING) {
198 198
         $type = $this->colDefs[$type & self::T_MASK];
199 199
         $this->db->exec("ALTER TABLE {$table} ADD COLUMN {$column} {$type}");
200 200
         unset($this->tables[$table]);
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
      * @param string $property The EAV property name in the record.
209 209
      * @return $this
210 210
      */
211
-    public function createEavTable (Record $record, string $property) {
211
+    public function createEavTable(Record $record, string $property) {
212 212
         $eav = $record->getEav($property);
213 213
         return $this->createTable($eav, [
214 214
             'entity' => self::T_INT_STRICT,
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
      * @param Junction $junction From {@link DB::getJunction()}
227 227
      * @return $this
228 228
      */
229
-    public function createJunctionTable (Junction $junction) {
229
+    public function createJunctionTable(Junction $junction) {
230 230
         $records = $junction->getRecords();
231 231
         return $this->createTable($junction, array_map(fn() => self::T_INT_STRICT, $records), [
232 232
             self::TABLE_PRIMARY => array_keys($records),
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
      * @param array[] $constraints See {@link Schema::createTable()}
242 242
      * @return $this
243 243
      */
244
-    public function createRecordTable (Record $record, array $constraints = []) {
244
+    public function createRecordTable(Record $record, array $constraints = []) {
245 245
         $columns = $record->getTypes();
246 246
         array_walk($columns, function(string &$type, string $property) use ($record) {
247 247
             $type = self::PHP_TYPES[$type] | ($record->isNullable($property) ? 0 : self::T_STRICT);
@@ -269,7 +269,7 @@  discard block
 block discarded – undo
269 269
      * @param array[] $constraints `[ <TABLE_CONST> => table constraint spec ]`
270 270
      * @return $this
271 271
      */
272
-    public function createTable (string $table, array $columns, array $constraints = []) {
272
+    public function createTable(string $table, array $columns, array $constraints = []) {
273 273
         $defs = $this->toColumnDefinitions($columns);
274 274
 
275 275
         /** @var string[] $pk */
@@ -305,7 +305,7 @@  discard block
 block discarded – undo
305 305
      * @param string $column
306 306
      * @return $this
307 307
      */
308
-    public function dropColumn (string $table, string $column) {
308
+    public function dropColumn(string $table, string $column) {
309 309
         $this->db->exec("ALTER TABLE {$table} DROP COLUMN {$column}");
310 310
         unset($this->tables[$table]);
311 311
         return $this;
@@ -316,7 +316,7 @@  discard block
 block discarded – undo
316 316
      *
317 317
      * @param string $table
318 318
      */
319
-    public function dropTable (string $table): void {
319
+    public function dropTable(string $table): void {
320 320
         $this->db->exec("DROP TABLE IF EXISTS {$table}");
321 321
         unset($this->tables[$table]);
322 322
     }
@@ -325,7 +325,7 @@  discard block
 block discarded – undo
325 325
      * @param string $name
326 326
      * @return null|Table
327 327
      */
328
-    public function getTable (string $name) {
328
+    public function getTable(string $name) {
329 329
         if (!isset($this->tables[$name])) {
330 330
             if ($this->db->isSQLite()) {
331 331
                 $info = $this->db->query("PRAGMA table_info({$name})")->fetchAll();
@@ -350,7 +350,7 @@  discard block
 block discarded – undo
350 350
      * @param string $table
351 351
      * @return bool
352 352
      */
353
-    final public function offsetExists ($table): bool {
353
+    final public function offsetExists($table): bool {
354 354
         return (bool)$this->offsetGet($table);
355 355
     }
356 356
 
@@ -360,7 +360,7 @@  discard block
 block discarded – undo
360 360
      * @param string $table
361 361
      * @return null|Table
362 362
      */
363
-    public function offsetGet ($table) {
363
+    public function offsetGet($table) {
364 364
         return $this->getTable($table);
365 365
     }
366 366
 
@@ -369,7 +369,7 @@  discard block
 block discarded – undo
369 369
      * @param $value
370 370
      * @throws LogicException
371 371
      */
372
-    final public function offsetSet ($offset, $value) {
372
+    final public function offsetSet($offset, $value) {
373 373
         throw new LogicException('The schema cannot be altered this way.');
374 374
     }
375 375
 
@@ -377,7 +377,7 @@  discard block
 block discarded – undo
377 377
      * @param $offset
378 378
      * @throws LogicException
379 379
      */
380
-    final public function offsetUnset ($offset) {
380
+    final public function offsetUnset($offset) {
381 381
         throw new LogicException('The schema cannot be altered this way.');
382 382
     }
383 383
 
@@ -389,7 +389,7 @@  discard block
 block discarded – undo
389 389
      * @param string $newName
390 390
      * @return $this
391 391
      */
392
-    public function renameColumn (string $table, string $oldName, string $newName) {
392
+    public function renameColumn(string $table, string $oldName, string $newName) {
393 393
         $this->db->exec("ALTER TABLE {$table} RENAME COLUMN {$oldName} TO {$newName}");
394 394
         unset($this->tables[$table]);
395 395
         return $this;
@@ -402,7 +402,7 @@  discard block
 block discarded – undo
402 402
      * @param string $newName
403 403
      * @return $this
404 404
      */
405
-    public function renameTable (string $oldName, string $newName) {
405
+    public function renameTable(string $oldName, string $newName) {
406 406
         $this->db->exec("ALTER TABLE {$oldName} RENAME TO {$newName}");
407 407
         unset($this->tables[$oldName]);
408 408
         return $this;
@@ -414,7 +414,7 @@  discard block
 block discarded – undo
414 414
      * @param int[] $types
415 415
      * @return int[]
416 416
      */
417
-    protected function sortColumns (array $types): array {
417
+    protected function sortColumns(array $types): array {
418 418
         uksort($types, function(string $a, string $b) use ($types) {
419 419
             // descending index priority, increasing size, name
420 420
             return $types[$b] <=> $types[$a] ?: $a <=> $b;
@@ -426,7 +426,7 @@  discard block
 block discarded – undo
426 426
      * @param int[] $columns `[ name => <I_CONST> | <T_CONST> ]`
427 427
      * @return string[]
428 428
      */
429
-    protected function toColumnDefinitions (array $columns): array {
429
+    protected function toColumnDefinitions(array $columns): array {
430 430
         assert(count($columns) > 0);
431 431
         $columns = $this->sortColumns($columns);
432 432
         $defs = [];
@@ -451,7 +451,7 @@  discard block
 block discarded – undo
451 451
      * @param Column $foreign
452 452
      * @return string
453 453
      */
454
-    protected function toForeignKeyConstraint (string $table, string $local, Column $foreign): string {
454
+    protected function toForeignKeyConstraint(string $table, string $local, Column $foreign): string {
455 455
         return sprintf(
456 456
             'CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s(%s) ON DELETE CASCADE',
457 457
             $this->toForeignKeyConstraint_name($table, $local),
@@ -468,7 +468,7 @@  discard block
 block discarded – undo
468 468
      * @param string $column
469 469
      * @return string
470 470
      */
471
-    protected function toForeignKeyConstraint_name (string $table, string $column): string {
471
+    protected function toForeignKeyConstraint_name(string $table, string $column): string {
472 472
         return 'FK_' . $table . '__' . $column;
473 473
     }
474 474
 
@@ -477,7 +477,7 @@  discard block
 block discarded – undo
477 477
      * @param string[] $columns
478 478
      * @return string
479 479
      */
480
-    protected function toPrimaryKeyConstraint (string $table, array $columns): string {
480
+    protected function toPrimaryKeyConstraint(string $table, array $columns): string {
481 481
         return sprintf(
482 482
             'CONSTRAINT %s PRIMARY KEY (%s)',
483 483
             $this->toPrimaryKeyConstraint_name($table, $columns),
@@ -492,7 +492,7 @@  discard block
 block discarded – undo
492 492
      * @param string[] $columns
493 493
      * @return string
494 494
      */
495
-    protected function toPrimaryKeyConstraint_name (string $table, array $columns): string {
495
+    protected function toPrimaryKeyConstraint_name(string $table, array $columns): string {
496 496
         sort($columns, SORT_STRING);
497 497
         return 'PK_' . $table . '__' . implode('__', $columns);
498 498
     }
@@ -502,7 +502,7 @@  discard block
 block discarded – undo
502 502
      * @param string[] $columns
503 503
      * @return string
504 504
      */
505
-    protected function toUniqueKeyConstraint (string $table, array $columns): string {
505
+    protected function toUniqueKeyConstraint(string $table, array $columns): string {
506 506
         return sprintf(
507 507
             'CONSTRAINT %s UNIQUE (%s)',
508 508
             $this->toUniqueKeyConstraint_name($table, $columns),
@@ -517,7 +517,7 @@  discard block
 block discarded – undo
517 517
      * @param string[] $columns
518 518
      * @return string
519 519
      */
520
-    protected function toUniqueKeyConstraint_name (string $table, array $columns): string {
520
+    protected function toUniqueKeyConstraint_name(string $table, array $columns): string {
521 521
         sort($columns, SORT_STRING);
522 522
         return 'UQ_' . $table . '__' . implode('__', $columns);
523 523
     }
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -330,8 +330,7 @@
 block discarded – undo
330 330
             if ($this->db->isSQLite()) {
331 331
                 $info = $this->db->query("PRAGMA table_info({$name})")->fetchAll();
332 332
                 $cols = array_column($info, 'name');
333
-            }
334
-            else {
333
+            } else {
335 334
                 $cols = $this->db->query(
336 335
                     "SELECT column_name FROM information_schema.tables WHERE table_name = \"{$name}\""
337 336
                 )->fetchAll(DB::FETCH_COLUMN);
Please login to merge, or discard this patch.
src/DB/Select.php 2 patches
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
      * @param string|AbstractTable $table
126 126
      * @param string[] $columns
127 127
      */
128
-    public function __construct (DB $db, $table, array $columns = ['*']) {
128
+    public function __construct(DB $db, $table, array $columns = ['*']) {
129 129
         static $autoAlias = 0;
130 130
         $autoAlias++;
131 131
         parent::__construct($db);
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
      * @param array $args
153 153
      * @return Statement
154 154
      */
155
-    public function __invoke (array $args = []) {
155
+    public function __invoke(array $args = []) {
156 156
         return $this->execute($args);
157 157
     }
158 158
 
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
      *
162 162
      * @return string
163 163
      */
164
-    final public function __toString () {
164
+    final public function __toString() {
165 165
         return $this->alias;
166 166
     }
167 167
 
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
      * @param array $args Execution arguments.
172 172
      * @return int
173 173
      */
174
-    public function count (array $args = []): int {
174
+    public function count(array $args = []): int {
175 175
         $clone = clone $this;
176 176
         $clone->_columns = 'COUNT(*)';
177 177
         $clone->_order = '';
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
      * @param array $args
185 185
      * @return Statement
186 186
      */
187
-    public function execute (array $args = []) {
187
+    public function execute(array $args = []) {
188 188
         if (empty($args)) {
189 189
             return $this->db->query($this->toSql());
190 190
         }
@@ -199,14 +199,14 @@  discard block
 block discarded – undo
199 199
      * @param array $args Execution arguments.
200 200
      * @return array
201 201
      */
202
-    public function getAll (array $args = []): array {
202
+    public function getAll(array $args = []): array {
203 203
         return iterator_to_array($this->fetcher->__invoke($this->execute($args)));
204 204
     }
205 205
 
206 206
     /**
207 207
      * @return Column[]
208 208
      */
209
-    public function getColumns () {
209
+    public function getColumns() {
210 210
         return $this->refs;
211 211
     }
212 212
 
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
      * @param array $args Execution arguments.
220 220
      * @return Generator
221 221
      */
222
-    public function getEach (array $args = []) {
222
+    public function getEach(array $args = []) {
223 223
         yield from $this->fetcher->__invoke($this->execute($args));
224 224
     }
225 225
 
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
      * @param array $args
232 232
      * @return mixed
233 233
      */
234
-    public function getFirst (array $args = []) {
234
+    public function getFirst(array $args = []) {
235 235
         return $this->getEach($args)->current();
236 236
     }
237 237
 
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
      *
243 243
      * @return Generator
244 244
      */
245
-    public function getIterator () {
245
+    public function getIterator() {
246 246
         yield from $this->getEach();
247 247
     }
248 248
 
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
      *
253 253
      * @return null|mixed
254 254
      */
255
-    public function getResult (array $args = []) {
255
+    public function getResult(array $args = []) {
256 256
         return $this->execute($args)->fetchColumn();
257 257
     }
258 258
 
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
      * @param string $column
263 263
      * @return $this
264 264
      */
265
-    public function group (string $column) {
265
+    public function group(string $column) {
266 266
         if (!strlen($this->_group)) {
267 267
             $this->_group = " GROUP BY {$column}";
268 268
         }
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
      * @param string ...$conditions
279 279
      * @return $this
280 280
      */
281
-    public function having (string ...$conditions) {
281
+    public function having(string ...$conditions) {
282 282
         assert(count($conditions) > 0);
283 283
         $conditions = implode(' AND ', $conditions);
284 284
         if (!strlen($this->_having)) {
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
      * @param Select $select
299 299
      * @return $this
300 300
      */
301
-    public function intersect (Select $select) {
301
+    public function intersect(Select $select) {
302 302
         if ($this->db->isMySQL()) {
303 303
             // to be standards compliant, this hack must fail if they don't have the same cols.
304 304
             assert(count($this->refs) === count($select->refs) and !array_diff_key($this->refs, $select->refs));
@@ -319,7 +319,7 @@  discard block
 block discarded – undo
319 319
      *
320 320
      * @return Predicate
321 321
      */
322
-    public function isEmpty () {
322
+    public function isEmpty() {
323 323
         return Predicate::factory($this->db, "NOT EXISTS ({$this->toSql()})");
324 324
     }
325 325
 
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
      *
329 329
      * @return Predicate
330 330
      */
331
-    public function isNotEmpty () {
331
+    public function isNotEmpty() {
332 332
         return Predicate::factory($this->db, "EXISTS ({$this->toSql()})");
333 333
     }
334 334
 
@@ -339,7 +339,7 @@  discard block
 block discarded – undo
339 339
      * @param string ...$conditions
340 340
      * @return $this
341 341
      */
342
-    public function join ($table, string ...$conditions) {
342
+    public function join($table, string ...$conditions) {
343 343
         assert(count($conditions) > 0);
344 344
         if ($table instanceof Select) {
345 345
             $table = $table->toSubquery();
@@ -356,7 +356,7 @@  discard block
 block discarded – undo
356 356
      * @param string ...$conditions
357 357
      * @return $this
358 358
      */
359
-    public function joinLeft ($table, string ...$conditions) {
359
+    public function joinLeft($table, string ...$conditions) {
360 360
         assert(count($conditions) > 0);
361 361
         if ($table instanceof Select) {
362 362
             $table = $table->toSubquery();
@@ -373,7 +373,7 @@  discard block
 block discarded – undo
373 373
      * @param int $offset
374 374
      * @return $this
375 375
      */
376
-    public function limit (int $limit, int $offset = 0) {
376
+    public function limit(int $limit, int $offset = 0) {
377 377
         if ($limit == 0) {
378 378
             $this->_limit = '';
379 379
         }
@@ -392,7 +392,7 @@  discard block
 block discarded – undo
392 392
      * @param int|string $ref Ordinal or reference name.
393 393
      * @return null|Column
394 394
      */
395
-    public function offsetGet ($ref) {
395
+    public function offsetGet($ref) {
396 396
         if (is_int($ref)) {
397 397
             return current(array_slice($this->refs, $ref, 1)) ?: null;
398 398
         }
@@ -405,7 +405,7 @@  discard block
 block discarded – undo
405 405
      * @param string $order
406 406
      * @return $this
407 407
      */
408
-    public function order (string $order) {
408
+    public function order(string $order) {
409 409
         if (strlen($order)) {
410 410
             $order = " ORDER BY {$order}";
411 411
         }
@@ -416,7 +416,7 @@  discard block
 block discarded – undo
416 416
     /**
417 417
      * @return Statement
418 418
      */
419
-    public function prepare () {
419
+    public function prepare() {
420 420
         return $this->db->prepare($this->toSql());
421 421
     }
422 422
 
@@ -424,7 +424,7 @@  discard block
 block discarded – undo
424 424
      * @param string $alias
425 425
      * @return $this
426 426
      */
427
-    public function setAlias (string $alias) {
427
+    public function setAlias(string $alias) {
428 428
         $this->alias = $alias;
429 429
         foreach ($this->refs as $k => $column) {
430 430
             $this->refs[$k] = $column->setQualifier($alias);
@@ -441,7 +441,7 @@  discard block
 block discarded – undo
441 441
      * @param string[] $expressions Keyed by alias if applicable.
442 442
      * @return $this
443 443
      */
444
-    public function setColumns (array $expressions = ['*']) {
444
+    public function setColumns(array $expressions = ['*']) {
445 445
         if ($expressions === ['*']) {
446 446
             $expressions = array_keys($this->table->getColumns());
447 447
         }
@@ -469,7 +469,7 @@  discard block
 block discarded – undo
469 469
      * @param Closure $fetcher
470 470
      * @return $this
471 471
      */
472
-    public function setFetcher (Closure $fetcher) {
472
+    public function setFetcher(Closure $fetcher) {
473 473
         $this->fetcher = $fetcher;
474 474
         return $this;
475 475
     }
@@ -479,7 +479,7 @@  discard block
 block discarded – undo
479 479
      *
480 480
      * @return string
481 481
      */
482
-    public function toSql (): string {
482
+    public function toSql(): string {
483 483
         $sql = "SELECT {$this->_columns} FROM {$this->_table}";
484 484
         $sql .= $this->_join;
485 485
         $sql .= $this->_where;
@@ -496,7 +496,7 @@  discard block
 block discarded – undo
496 496
      *
497 497
      * @return string
498 498
      */
499
-    public function toSubquery (): string {
499
+    public function toSubquery(): string {
500 500
         return "({$this->toSql()}) AS {$this->alias}";
501 501
     }
502 502
 
@@ -506,7 +506,7 @@  discard block
 block discarded – undo
506 506
      * @param Select $select
507 507
      * @return $this
508 508
      */
509
-    public function union (Select $select) {
509
+    public function union(Select $select) {
510 510
         $select = clone $select;
511 511
         $select->_order = '';
512 512
         $select->_limit = '';
@@ -520,7 +520,7 @@  discard block
 block discarded – undo
520 520
      * @param Select $select
521 521
      * @return $this
522 522
      */
523
-    public function unionAll (Select $select) {
523
+    public function unionAll(Select $select) {
524 524
         $select = clone $select;
525 525
         $select->_order = '';
526 526
         $select->_limit = '';
@@ -534,7 +534,7 @@  discard block
 block discarded – undo
534 534
      * @param string ...$conditions
535 535
      * @return $this
536 536
      */
537
-    public function where (string ...$conditions) {
537
+    public function where(string ...$conditions) {
538 538
         assert(count($conditions) > 0);
539 539
         $conditions = implode(' AND ', $conditions);
540 540
         if (!strlen($this->_where)) {
Please login to merge, or discard this patch.
Braces   +6 added lines, -12 removed lines patch added patch discarded remove patch
@@ -132,8 +132,7 @@  discard block
 block discarded – undo
132 132
         if ($table instanceof Select) {
133 133
             $this->_table = $table->toSubquery();
134 134
             $this->alias = "_anon{$autoAlias}_{$table->alias}";
135
-        }
136
-        else {
135
+        } else {
137 136
             if (is_string($table)) {
138 137
                 $table = $db[$table];
139 138
                 assert(isset($table));
@@ -265,8 +264,7 @@  discard block
 block discarded – undo
265 264
     public function group (string $column) {
266 265
         if (!strlen($this->_group)) {
267 266
             $this->_group = " GROUP BY {$column}";
268
-        }
269
-        else {
267
+        } else {
270 268
             $this->_group .= ", {$column}";
271 269
         }
272 270
         return $this;
@@ -283,8 +281,7 @@  discard block
 block discarded – undo
283 281
         $conditions = implode(' AND ', $conditions);
284 282
         if (!strlen($this->_having)) {
285 283
             $this->_having = " HAVING {$conditions}";
286
-        }
287
-        else {
284
+        } else {
288 285
             $this->_having .= " AND {$conditions}";
289 286
         }
290 287
         return $this;
@@ -376,8 +373,7 @@  discard block
 block discarded – undo
376 373
     public function limit (int $limit, int $offset = 0) {
377 374
         if ($limit == 0) {
378 375
             $this->_limit = '';
379
-        }
380
-        else {
376
+        } else {
381 377
             $this->_limit = " LIMIT {$limit}";
382 378
             if ($offset > 1) {
383 379
                 $this->_limit .= " OFFSET {$offset}";
@@ -452,8 +448,7 @@  discard block
 block discarded – undo
452 448
             $name = $match['name'] ?? null;
453 449
             if (is_int($alias)) {
454 450
                 $alias = $name;
455
-            }
456
-            elseif ($alias !== $name) {
451
+            } elseif ($alias !== $name) {
457 452
                 $expr .= " AS {$alias}";
458 453
             }
459 454
             if (isset($alias)) {
@@ -539,8 +534,7 @@  discard block
 block discarded – undo
539 534
         $conditions = implode(' AND ', $conditions);
540 535
         if (!strlen($this->_where)) {
541 536
             $this->_where = " WHERE {$conditions}";
542
-        }
543
-        else {
537
+        } else {
544 538
             $this->_where .= " AND {$conditions}";
545 539
         }
546 540
         return $this;
Please login to merge, or discard this patch.
src/DB/Junction.php 2 patches
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
      * @param string $interface
30 30
      * @return Junction
31 31
      */
32
-    public static function fromInterface (DB $db, string $interface) {
32
+    public static function fromInterface(DB $db, string $interface) {
33 33
         $ref = new ReflectionClass($interface);
34 34
         assert($ref->isInterface());
35 35
         $doc = $ref->getDocComment();
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
      * @param string $table
49 49
      * @param string[] $classes
50 50
      */
51
-    public function __construct (DB $db, string $table, array $classes) {
51
+    public function __construct(DB $db, string $table, array $classes) {
52 52
         parent::__construct($db, $table, array_keys($classes));
53 53
         $this->classes = $classes;
54 54
     }
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
      * @param array $match Keyed by junction column.
63 63
      * @return Select|EntityInterface[]
64 64
      */
65
-    public function find (string $key, array $match = []) {
65
+    public function find(string $key, array $match = []) {
66 66
         $record = $this->getRecord($key);
67 67
         $select = $record->loadAll();
68 68
         $select->join($this, $this[$key]->isEqual($record['id']));
@@ -76,14 +76,14 @@  discard block
 block discarded – undo
76 76
      * @param string $column
77 77
      * @return string
78 78
      */
79
-    final public function getClass (string $column): string {
79
+    final public function getClass(string $column): string {
80 80
         return $this->classes[$column];
81 81
     }
82 82
 
83 83
     /**
84 84
      * @return string[]
85 85
      */
86
-    final public function getClasses () {
86
+    final public function getClasses() {
87 87
         return $this->classes;
88 88
     }
89 89
 
@@ -91,14 +91,14 @@  discard block
 block discarded – undo
91 91
      * @param string $column
92 92
      * @return Record
93 93
      */
94
-    public function getRecord (string $column) {
94
+    public function getRecord(string $column) {
95 95
         return $this->db->getRecord($this->classes[$column]);
96 96
     }
97 97
 
98 98
     /**
99 99
      * @return Record[]
100 100
      */
101
-    public function getRecords () {
101
+    public function getRecords() {
102 102
         return array_map(fn($class) => $this->db->getRecord($class), $this->classes);
103 103
     }
104 104
 
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
      * @param int[] $ids Keyed by column.
109 109
      * @return int Rows affected.
110 110
      */
111
-    public function link (array $ids): int {
111
+    public function link(array $ids): int {
112 112
         $statement = $this->cache(__FUNCTION__, function() {
113 113
             $columns = implode(',', array_keys($this->columns));
114 114
             $slots = implode(',', $this->db->slots(array_keys($this->columns)));
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
      * @param array $ids Keyed by Column
132 132
      * @return int Rows affected
133 133
      */
134
-    public function unlink (array $ids): int {
134
+    public function unlink(array $ids): int {
135 135
         return $this->delete($ids);
136 136
     }
137 137
 }
138 138
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -114,8 +114,7 @@
 block discarded – undo
114 114
             $slots = implode(',', $this->db->slots(array_keys($this->columns)));
115 115
             if ($this->db->isSQLite()) {
116 116
                 $sql = "INSERT OR IGNORE INTO {$this} ({$columns}) VALUES ({$slots})";
117
-            }
118
-            else {
117
+            } else {
119 118
                 $sql = "INSERT IGNORE INTO {$this} ({$columns}) VALUES ({$slots})";
120 119
             }
121 120
             return $this->db->prepare($sql);
Please login to merge, or discard this patch.