Passed
Push — master ( b7a806...8658ef )
by y
01:51
created
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/Record.php 2 patches
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.
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
      * @param string|EntityInterface $class
77 77
      * @return Record
78 78
      */
79
-    public static function fromClass (DB $db, $class) {
79
+    public static function fromClass(DB $db, $class) {
80 80
         $rClass = new ReflectionClass($class);
81 81
         assert($rClass->isInstantiable());
82 82
         $columns = [];
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
      * @param string[] $columns Property names.
105 105
      * @param EAV[] $eav Keyed by property name.
106 106
      */
107
-    public function __construct (DB $db, EntityInterface $proto, string $table, array $columns, array $eav = []) {
107
+    public function __construct(DB $db, EntityInterface $proto, string $table, array $columns, array $eav = []) {
108 108
         parent::__construct($db, $table, $columns);
109 109
         $this->proto = $proto;
110 110
         $rClass = new ReflectionClass($proto);
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
      * @param array[] $eavMatch `[eav property => attribute => mixed]`
158 158
      * @return Select|EntityInterface[]
159 159
      */
160
-    public function find (array $match, array $eavMatch = []) {
160
+    public function find(array $match, array $eavMatch = []) {
161 161
         $select = $this->loadAll();
162 162
         foreach ($match as $a => $b) {
163 163
             $select->where($this->db->match($this[$a] ?? $a, $b));
@@ -175,14 +175,14 @@  discard block
 block discarded – undo
175 175
      * @param Statement $statement
176 176
      * @return EntityInterface[] Keyed by ID
177 177
      */
178
-    public function getAll (Statement $statement): array {
178
+    public function getAll(Statement $statement): array {
179 179
         return iterator_to_array($this->getEach($statement));
180 180
     }
181 181
 
182 182
     /**
183 183
      * @return string
184 184
      */
185
-    final public function getClass (): string {
185
+    final public function getClass(): string {
186 186
         return get_class($this->proto);
187 187
     }
188 188
 
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
      * @param Statement $statement
194 194
      * @return Generator|EntityInterface[] Keyed by ID
195 195
      */
196
-    public function getEach (Statement $statement) {
196
+    public function getEach(Statement $statement) {
197 197
         do {
198 198
             $entities = [];
199 199
             for ($i = 0; $i < 256 and false !== $row = $statement->fetch(); $i++) {
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
     /**
210 210
      * @return EAV[]
211 211
      */
212
-    public function getEav () {
212
+    public function getEav() {
213 213
         return $this->eav;
214 214
     }
215 215
 
@@ -218,14 +218,14 @@  discard block
 block discarded – undo
218 218
      *
219 219
      * @return string[]
220 220
      */
221
-    final public function getProperties (): array {
221
+    final public function getProperties(): array {
222 222
         return array_keys($this->properties);
223 223
     }
224 224
 
225 225
     /**
226 226
      * @return EntityInterface
227 227
      */
228
-    public function getProto () {
228
+    public function getProto() {
229 229
         return $this->proto;
230 230
     }
231 231
 
@@ -236,7 +236,7 @@  discard block
 block discarded – undo
236 236
      *
237 237
      * @return string[]
238 238
      */
239
-    final public function getTypes (): array {
239
+    final public function getTypes(): array {
240 240
         return $this->types;
241 241
     }
242 242
 
@@ -244,7 +244,7 @@  discard block
 block discarded – undo
244 244
      * @param EntityInterface $entity
245 245
      * @return array
246 246
      */
247
-    protected function getValues (EntityInterface $entity): array {
247
+    protected function getValues(EntityInterface $entity): array {
248 248
         $values = [];
249 249
         foreach (array_keys($this->columns) as $name) {
250 250
             $values[$name] = $this->properties[$name]->getValue($entity);
@@ -256,7 +256,7 @@  discard block
 block discarded – undo
256 256
      * @param string $property
257 257
      * @return bool
258 258
      */
259
-    final public function isNullable (string $property): bool {
259
+    final public function isNullable(string $property): bool {
260 260
         return $this->nullable[$property];
261 261
     }
262 262
 
@@ -266,7 +266,7 @@  discard block
 block discarded – undo
266 266
      * @param int $id
267 267
      * @return null|EntityInterface
268 268
      */
269
-    public function load (int $id) {
269
+    public function load(int $id) {
270 270
         $statement = $this->cache(__FUNCTION__, function() {
271 271
             return $this->select()->where('id = ?')->prepare();
272 272
         });
@@ -286,7 +286,7 @@  discard block
 block discarded – undo
286 286
      *
287 287
      * @return Select|EntityInterface[]
288 288
      */
289
-    public function loadAll () {
289
+    public function loadAll() {
290 290
         return $this->select()->setFetcher(function(Statement $statement) {
291 291
             yield from $this->getEach($statement);
292 292
         });
@@ -297,7 +297,7 @@  discard block
 block discarded – undo
297 297
      *
298 298
      * @param EntityInterface[] $entities
299 299
      */
300
-    protected function loadEav (array $entities): void {
300
+    protected function loadEav(array $entities): void {
301 301
         $ids = array_keys($entities);
302 302
         foreach ($this->eav as $name => $eav) {
303 303
             foreach ($eav->loadAll($ids) as $id => $values) {
@@ -312,7 +312,7 @@  discard block
 block discarded – undo
312 312
      * @param EntityInterface $entity
313 313
      * @return int ID
314 314
      */
315
-    public function save (EntityInterface $entity): int {
315
+    public function save(EntityInterface $entity): int {
316 316
         if (!$entity->getId()) {
317 317
             $this->saveInsert($entity);
318 318
         }
@@ -326,7 +326,7 @@  discard block
 block discarded – undo
326 326
     /**
327 327
      * @param EntityInterface $entity
328 328
      */
329
-    protected function saveEav (EntityInterface $entity): void {
329
+    protected function saveEav(EntityInterface $entity): void {
330 330
         $id = $entity->getId();
331 331
         foreach ($this->eav as $name => $eav) {
332 332
             // may be null to skip
@@ -342,7 +342,7 @@  discard block
 block discarded – undo
342 342
      *
343 343
      * @param EntityInterface $entity
344 344
      */
345
-    protected function saveInsert (EntityInterface $entity): void {
345
+    protected function saveInsert(EntityInterface $entity): void {
346 346
         $statement = $this->cache(__FUNCTION__, function() {
347 347
             $slots = $this->db->slots(array_keys($this->columns));
348 348
             unset($slots['id']);
@@ -361,7 +361,7 @@  discard block
 block discarded – undo
361 361
      *
362 362
      * @param EntityInterface $entity
363 363
      */
364
-    protected function saveUpdate (EntityInterface $entity): void {
364
+    protected function saveUpdate(EntityInterface $entity): void {
365 365
         $statement = $this->cache(__FUNCTION__, function() {
366 366
             $slots = $this->db->slotsEqual(array_keys($this->columns));
367 367
             unset($slots['id']);
@@ -376,7 +376,7 @@  discard block
 block discarded – undo
376 376
      * @param EntityInterface $proto
377 377
      * @return $this
378 378
      */
379
-    public function setProto (EntityInterface $proto) {
379
+    public function setProto(EntityInterface $proto) {
380 380
         $this->proto = $proto;
381 381
         return $this;
382 382
     }
@@ -385,7 +385,7 @@  discard block
 block discarded – undo
385 385
      * @param EntityInterface $entity
386 386
      * @param array $values
387 387
      */
388
-    protected function setValues (EntityInterface $entity, array $values): void {
388
+    protected function setValues(EntityInterface $entity, array $values): void {
389 389
         foreach ($values as $name => $value) {
390 390
             if (isset($this->properties[$name])) {
391 391
                 settype($value, $this->types[$name]); // doesn't care about letter case
Please login to merge, or discard this patch.
src/DB/Schema.php 2 patches
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.
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
     /**
197 197
      * @param DB $db
198 198
      */
199
-    public function __construct (DB $db) {
199
+    public function __construct(DB $db) {
200 200
         $this->db = $db;
201 201
         $this->colDefs ??= self::COLUMN_DEFINITIONS[$db->getDriver()];
202 202
     }
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
      * @param int $type
210 210
      * @return $this
211 211
      */
212
-    public function addColumn (string $table, string $column, int $type = self::T_STRING) {
212
+    public function addColumn(string $table, string $column, int $type = self::T_STRING) {
213 213
         $type = $this->colDefs[$type & self::T_MASK];
214 214
         $this->db->exec("ALTER TABLE {$table} ADD COLUMN {$column} {$type}");
215 215
         unset($this->tables[$table]);
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
      * @param array[] $constraints `[ <TABLE_CONST> => spec ]`
236 236
      * @return $this
237 237
      */
238
-    public function createTable (string $table, array $columns, array $constraints = []) {
238
+    public function createTable(string $table, array $columns, array $constraints = []) {
239 239
         $defs = $this->toColumnDefinitions($columns);
240 240
 
241 241
         /** @var string[] $pk */
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
      * @param string $column
272 272
      * @return $this
273 273
      */
274
-    public function dropColumn (string $table, string $column) {
274
+    public function dropColumn(string $table, string $column) {
275 275
         $this->db->exec("ALTER TABLE {$table} DROP COLUMN {$column}");
276 276
         unset($this->tables[$table]);
277 277
         return $this;
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
      *
283 283
      * @param string $table
284 284
      */
285
-    public function dropTable (string $table): void {
285
+    public function dropTable(string $table): void {
286 286
         $this->db->exec("DROP TABLE IF EXISTS {$table}");
287 287
         unset($this->tables[$table]);
288 288
     }
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
     /**
291 291
      * @return DB
292 292
      */
293
-    public function getDb () {
293
+    public function getDb() {
294 294
         return $this->db;
295 295
     }
296 296
 
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
      * @param string $name
299 299
      * @return null|Table
300 300
      */
301
-    public function getTable (string $name) {
301
+    public function getTable(string $name) {
302 302
         if (!isset($this->tables[$name])) {
303 303
             if ($this->db->isSQLite()) {
304 304
                 $info = $this->db->query("PRAGMA table_info({$name})")->fetchAll();
@@ -323,7 +323,7 @@  discard block
 block discarded – undo
323 323
      * @param string $table
324 324
      * @return bool
325 325
      */
326
-    final public function offsetExists ($table): bool {
326
+    final public function offsetExists($table): bool {
327 327
         return (bool)$this->offsetGet($table);
328 328
     }
329 329
 
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
      * @param string $table
334 334
      * @return null|Table
335 335
      */
336
-    public function offsetGet ($table) {
336
+    public function offsetGet($table) {
337 337
         return $this->getTable($table);
338 338
     }
339 339
 
@@ -342,7 +342,7 @@  discard block
 block discarded – undo
342 342
      * @param $value
343 343
      * @throws LogicException
344 344
      */
345
-    final public function offsetSet ($offset, $value) {
345
+    final public function offsetSet($offset, $value) {
346 346
         throw new LogicException('The schema cannot be altered this way.');
347 347
     }
348 348
 
@@ -350,7 +350,7 @@  discard block
 block discarded – undo
350 350
      * @param $offset
351 351
      * @throws LogicException
352 352
      */
353
-    final public function offsetUnset ($offset) {
353
+    final public function offsetUnset($offset) {
354 354
         throw new LogicException('The schema cannot be altered this way.');
355 355
     }
356 356
 
@@ -362,7 +362,7 @@  discard block
 block discarded – undo
362 362
      * @param string $newName
363 363
      * @return $this
364 364
      */
365
-    public function renameColumn (string $table, string $oldName, string $newName) {
365
+    public function renameColumn(string $table, string $oldName, string $newName) {
366 366
         $this->db->exec("ALTER TABLE {$table} RENAME COLUMN {$oldName} TO {$newName}");
367 367
         unset($this->tables[$table]);
368 368
         return $this;
@@ -375,7 +375,7 @@  discard block
 block discarded – undo
375 375
      * @param string $newName
376 376
      * @return $this
377 377
      */
378
-    public function renameTable (string $oldName, string $newName) {
378
+    public function renameTable(string $oldName, string $newName) {
379 379
         $this->db->exec("ALTER TABLE {$oldName} RENAME TO {$newName}");
380 380
         unset($this->tables[$oldName]);
381 381
         return $this;
@@ -387,7 +387,7 @@  discard block
 block discarded – undo
387 387
      * @param int[] $types
388 388
      * @return int[]
389 389
      */
390
-    protected function sortColumns (array $types): array {
390
+    protected function sortColumns(array $types): array {
391 391
         uksort($types, function(string $a, string $b) use ($types) {
392 392
             // descending index priority, increasing size, name
393 393
             return $types[$b] <=> $types[$a] ?: $a <=> $b;
@@ -399,7 +399,7 @@  discard block
 block discarded – undo
399 399
      * @param int[] $columns `[ name => <I_CONST> | <T_CONST> ]`
400 400
      * @return string[]
401 401
      */
402
-    protected function toColumnDefinitions (array $columns): array {
402
+    protected function toColumnDefinitions(array $columns): array {
403 403
         assert(count($columns) > 0);
404 404
         $columns = $this->sortColumns($columns);
405 405
         $defs = [];
@@ -424,7 +424,7 @@  discard block
 block discarded – undo
424 424
      * @param Column $foreign
425 425
      * @return string
426 426
      */
427
-    protected function toForeignKeyConstraint (string $table, string $local, Column $foreign): string {
427
+    protected function toForeignKeyConstraint(string $table, string $local, Column $foreign): string {
428 428
         return sprintf(
429 429
             'CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s(%s) ON DELETE CASCADE',
430 430
             $this->toForeignKeyConstraint_name($table, $local),
@@ -441,7 +441,7 @@  discard block
 block discarded – undo
441 441
      * @param string $column
442 442
      * @return string
443 443
      */
444
-    protected function toForeignKeyConstraint_name (string $table, string $column): string {
444
+    protected function toForeignKeyConstraint_name(string $table, string $column): string {
445 445
         return 'FK_' . $table . '__' . $column;
446 446
     }
447 447
 
@@ -450,7 +450,7 @@  discard block
 block discarded – undo
450 450
      * @param string[] $columns
451 451
      * @return string
452 452
      */
453
-    protected function toPrimaryKeyConstraint (string $table, array $columns): string {
453
+    protected function toPrimaryKeyConstraint(string $table, array $columns): string {
454 454
         return sprintf(
455 455
             'CONSTRAINT %s PRIMARY KEY (%s)',
456 456
             $this->toPrimaryKeyConstraint_name($table, $columns),
@@ -465,7 +465,7 @@  discard block
 block discarded – undo
465 465
      * @param string[] $columns
466 466
      * @return string
467 467
      */
468
-    protected function toPrimaryKeyConstraint_name (string $table, array $columns): string {
468
+    protected function toPrimaryKeyConstraint_name(string $table, array $columns): string {
469 469
         sort($columns, SORT_STRING);
470 470
         return 'PK_' . $table . '__' . implode('__', $columns);
471 471
     }
@@ -475,7 +475,7 @@  discard block
 block discarded – undo
475 475
      * @param string[] $columns
476 476
      * @return string
477 477
      */
478
-    protected function toUniqueKeyConstraint (string $table, array $columns): string {
478
+    protected function toUniqueKeyConstraint(string $table, array $columns): string {
479 479
         return sprintf(
480 480
             'CONSTRAINT %s UNIQUE (%s)',
481 481
             $this->toUniqueKeyConstraint_name($table, $columns),
@@ -490,7 +490,7 @@  discard block
 block discarded – undo
490 490
      * @param string[] $columns
491 491
      * @return string
492 492
      */
493
-    protected function toUniqueKeyConstraint_name (string $table, array $columns): string {
493
+    protected function toUniqueKeyConstraint_name(string $table, array $columns): string {
494 494
         sort($columns, SORT_STRING);
495 495
         return 'UQ_' . $table . '__' . implode('__', $columns);
496 496
     }
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.
src/DB/Migrator.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
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
         $this->table ??= $db['__migrations__'] ?? $db->getSchema()->createTable('__migrations__', [
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
      * @param string $to Migration sequence identifier, or `null` to step down once.
49 49
      * @return null|string The resulting current sequence identifier.
50 50
      */
51
-    public function down (string $to = null): ?string {
51
+    public function down(string $to = null): ?string {
52 52
         return $this->db->transact(function() use ($to) {
53 53
             $current = $this->getCurrent();
54 54
             // walk newest to oldest
@@ -75,14 +75,14 @@  discard block
 block discarded – undo
75 75
      *
76 76
      * @return null|string
77 77
      */
78
-    public function getCurrent (): ?string {
78
+    public function getCurrent(): ?string {
79 79
         return $this->table->select([$this->table['sequence']->max()])->getResult();
80 80
     }
81 81
 
82 82
     /**
83 83
      * @return string
84 84
      */
85
-    final public function getDir (): string {
85
+    final public function getDir(): string {
86 86
         return $this->dir;
87 87
     }
88 88
 
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
      * @param array $spec
91 91
      * @return MigrationInterface
92 92
      */
93
-    protected function getMigration (string $file) {
93
+    protected function getMigration(string $file) {
94 94
         $migration = include "{$file}";
95 95
         assert($migration instanceof MigrationInterface);
96 96
         return $migration;
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
      *
102 102
      * @return string[] [ sequence => file ]
103 103
      */
104
-    protected function glob () {
104
+    protected function glob() {
105 105
         $files = [];
106 106
         foreach (glob("{$this->dir}/*.php") as $file) {
107 107
             $files[basename($file, '.php')] = $file;
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
      * @param null|string $to Migration sequence identifier, or `null` for all upgrades.
116 116
      * @return null|string The resulting current sequence identifier.
117 117
      */
118
-    public function up (string $to = null): ?string {
118
+    public function up(string $to = null): ?string {
119 119
         return $this->db->transact(function() use ($to) {
120 120
             $current = $this->getCurrent();
121 121
             // walk oldest to newest
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
@@ -31,11 +31,11 @@
 block discarded – undo
31 31
      * @param Schema $schema
32 32
      * @return void
33 33
      */
34
-    public function down ($schema);
34
+    public function down($schema);
35 35
 
36 36
     /**
37 37
      * @param Schema $schema
38 38
      * @return void
39 39
      */
40
-    public function up ($schema);
40
+    public function up($schema);
41 41
 }
42 42
\ No newline at end of file
Please login to merge, or discard this patch.
bin/helix.db.migrate.php 5 patches
Indentation   +1 added lines, -3 removed lines patch added patch discarded remove patch
@@ -271,6 +271,4 @@
 block discarded – undo
271 271
         return;
272 272
 
273 273
     default:
274
-        $usage();
275
-        exit(1);
276
-}
277 274
\ No newline at end of file
275
+        $usage
278 276
\ No newline at end of file
Please login to merge, or discard this patch.
Switch Indentation   +1 added lines, -3 removed lines patch added patch discarded remove patch
@@ -271,6 +271,4 @@
 block discarded – undo
271 271
         return;
272 272
 
273 273
     default:
274
-        $usage();
275
-        exit(1);
276
-}
277 274
\ No newline at end of file
275
+        $usage
278 276
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +4 added lines, -6 removed lines patch added patch discarded remove patch
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
         };
146 146
         if ($access instanceof Record) {
147 147
             // create table
148
-            if (!$db[$access->getName()]) {
148
+            if (!$db[$access - >getName()]) {
149 149
                 $columns = [];
150 150
                 foreach ($access->getTypes() as $property => $type) {
151 151
                     $T_CONST = Schema::PHP_TYPE_NAMES[$type];
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
             // check each eav
164 164
             foreach ($access->getEav() as $eav) {
165 165
                 // create table
166
-                if (!$db[$eav->getName()]) {
166
+                if (!$db[$eav - >getName()]) {
167 167
                     $T_CONST = Schema::PHP_TYPE_NAMES[$eav->getValueType()];
168 168
                     $columns = [
169 169
                         "'entity' => Schema::T_INT_STRICT",
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
         }
184 184
         elseif ($access instanceof Junction) {
185 185
             // create table
186
-            if (!$db[$access->getName()]) {
186
+            if (!$db[$access - >getName()]) {
187 187
                 $records = $access->getRecords();
188 188
                 $columns = array_map(
189 189
                     fn(string $column) => "'{$column}' => Schema::T_INT_STRICT",
@@ -271,6 +271,4 @@  discard block
 block discarded – undo
271 271
         return;
272 272
 
273 273
     default:
274
-        $usage();
275
-        exit(1);
276
-}
277 274
\ No newline at end of file
275
+        $usage
278 276
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +1 added lines, -3 removed lines patch added patch discarded remove patch
@@ -271,6 +271,4 @@
 block discarded – undo
271 271
         return;
272 272
 
273 273
     default:
274
-        $usage();
275
-        exit(1);
276
-}
277 274
\ No newline at end of file
275
+        $usage
278 276
\ No newline at end of file
Please login to merge, or discard this patch.
Upper-Lower-Casing   +1 added lines, -3 removed lines patch added patch discarded remove patch
@@ -271,6 +271,4 @@
 block discarded – undo
271 271
         return;
272 272
 
273 273
     default:
274
-        $usage();
275
-        exit(1);
276
-}
277 274
\ No newline at end of file
275
+        $usage
278 276
\ No newline at end of file
Please login to merge, or discard this patch.