Passed
Push — master ( 3084e3...f39217 )
by y
01:35
created
src/DB.php 1 patch
Spacing   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
      * @param string $file
70 70
      * @return static
71 71
      */
72
-    public static function fromConfig (string $connection = 'default', string $file = 'db.config.php') {
72
+    public static function fromConfig(string $connection = 'default', string $file = 'db.config.php') {
73 73
         $config = (include "{$file}")[$connection];
74 74
         return new static($config['dsn'], $config['username'] ?? null, $config['password'] ?? null, $config['options'] ?? []);
75 75
     }
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
      * @param string $password
85 85
      * @param array $options
86 86
      */
87
-    public function __construct ($dsn, $username = null, $password = null, array $options = []) {
87
+    public function __construct($dsn, $username = null, $password = null, array $options = []) {
88 88
         $options[self::ATTR_STATEMENT_CLASS] ??= [Statement::class, [$this]];
89 89
         parent::__construct($dsn, $username, $password, $options);
90 90
         $this->setAttribute(self::ATTR_DEFAULT_FETCH_MODE, self::FETCH_ASSOC);
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
 
97 97
         if ($this->isSQLite()) {
98 98
             // polyfill sqlite functions
99
-            $this->sqliteCreateFunctions([ // deterministic functions
99
+            $this->sqliteCreateFunctions([// deterministic functions
100 100
                 // https://www.sqlite.org/lang_mathfunc.html
101 101
                 'ACOS' => 'acos',
102 102
                 'ASIN' => 'asin',
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
                 'SIGN' => fn($x) => ($x > 0) - ($x < 0),
123 123
             ]);
124 124
 
125
-            $this->sqliteCreateFunctions([ // non-deterministic
125
+            $this->sqliteCreateFunctions([// non-deterministic
126 126
                 'RAND' => fn() => mt_rand() / mt_getrandmax(),
127 127
             ], false);
128 128
         }
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
      *
134 134
      * @return string
135 135
      */
136
-    final public function __toString () {
136
+    final public function __toString() {
137 137
         return $this->driver;
138 138
     }
139 139
 
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
      *
145 145
      * @return true
146 146
      */
147
-    public function beginTransaction () {
147
+    public function beginTransaction() {
148 148
         assert($this->transactions >= 0);
149 149
         if ($this->transactions === 0) {
150 150
             $this->logger->__invoke("BEGIN TRANSACTION");
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
      *
165 165
      * @return true
166 166
      */
167
-    public function commit () {
167
+    public function commit() {
168 168
         assert($this->transactions > 0);
169 169
         if ($this->transactions === 1) {
170 170
             $this->logger->__invoke("COMMIT TRANSACTION");
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
      * @param string $sql
185 185
      * @return int
186 186
      */
187
-    public function exec ($sql): int {
187
+    public function exec($sql): int {
188 188
         $this->logger->__invoke($sql);
189 189
         return parent::exec($sql);
190 190
     }
@@ -200,14 +200,14 @@  discard block
 block discarded – undo
200 200
      * @param mixed ...$args
201 201
      * @return mixed
202 202
      */
203
-    public function factory (string $class, ...$args) {
203
+    public function factory(string $class, ...$args) {
204 204
         return new $class($this, ...$args);
205 205
     }
206 206
 
207 207
     /**
208 208
      * @return string
209 209
      */
210
-    final public function getDriver (): string {
210
+    final public function getDriver(): string {
211 211
         return $this->driver;
212 212
     }
213 213
 
@@ -217,14 +217,14 @@  discard block
 block discarded – undo
217 217
      * @param string $interface
218 218
      * @return Junction
219 219
      */
220
-    public function getJunction ($interface) {
220
+    public function getJunction($interface) {
221 221
         return $this->junctions[$interface] ??= Junction::fromInterface($this, $interface);
222 222
     }
223 223
 
224 224
     /**
225 225
      * @return Closure
226 226
      */
227
-    public function getLogger () {
227
+    public function getLogger() {
228 228
         return $this->logger;
229 229
     }
230 230
 
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
      * @param string|EntityInterface $class
235 235
      * @return Record
236 236
      */
237
-    public function getRecord ($class) {
237
+    public function getRecord($class) {
238 238
         if (is_object($class)) {
239 239
             $class = get_class($class);
240 240
         }
@@ -245,7 +245,7 @@  discard block
 block discarded – undo
245 245
      * @param string $name
246 246
      * @return null|Table
247 247
      */
248
-    public function getTable (string $name) {
248
+    public function getTable(string $name) {
249 249
         if (!isset($this->tables[$name])) {
250 250
             if ($this->isSQLite()) {
251 251
                 $info = $this->query("PRAGMA table_info({$this->quote($name)})")->fetchAll();
@@ -267,21 +267,21 @@  discard block
 block discarded – undo
267 267
     /**
268 268
      * @return bool
269 269
      */
270
-    final public function isMySQL (): bool {
270
+    final public function isMySQL(): bool {
271 271
         return $this->driver === 'mysql';
272 272
     }
273 273
 
274 274
     /**
275 275
      * @return bool
276 276
      */
277
-    final public function isPostgreSQL (): bool {
277
+    final public function isPostgreSQL(): bool {
278 278
         return $this->driver === 'pgsql';
279 279
     }
280 280
 
281 281
     /**
282 282
      * @return bool
283 283
      */
284
-    final public function isSQLite (): bool {
284
+    final public function isSQLite(): bool {
285 285
         return $this->driver === 'sqlite';
286 286
     }
287 287
 
@@ -302,7 +302,7 @@  discard block
 block discarded – undo
302 302
      * @param mixed $b
303 303
      * @return Predicate
304 304
      */
305
-    public function match ($a, $b) {
305
+    public function match($a, $b) {
306 306
         if ($b instanceof Closure) {
307 307
             return $b->__invoke($a, $this);
308 308
         }
@@ -323,7 +323,7 @@  discard block
 block discarded – undo
323 323
      *
324 324
      * @return Transaction
325 325
      */
326
-    public function newTransaction () {
326
+    public function newTransaction() {
327 327
         return Transaction::factory($this);
328 328
     }
329 329
 
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
      * @param string $table
334 334
      * @return bool
335 335
      */
336
-    final public function offsetExists ($table): bool {
336
+    final public function offsetExists($table): bool {
337 337
         return (bool)$this->getTable($table);
338 338
     }
339 339
 
@@ -343,7 +343,7 @@  discard block
 block discarded – undo
343 343
      * @param string $table
344 344
      * @return null|Table
345 345
      */
346
-    final public function offsetGet ($table) {
346
+    final public function offsetGet($table) {
347 347
         return $this->getTable($table);
348 348
     }
349 349
 
@@ -352,7 +352,7 @@  discard block
 block discarded – undo
352 352
      * @param $value
353 353
      * @throws LogicException
354 354
      */
355
-    final public function offsetSet ($offset, $value) {
355
+    final public function offsetSet($offset, $value) {
356 356
         throw new LogicException('Raw table access is immutable.');
357 357
     }
358 358
 
@@ -360,7 +360,7 @@  discard block
 block discarded – undo
360 360
      * @param $offset
361 361
      * @throws LogicException
362 362
      */
363
-    final public function offsetUnset ($offset) {
363
+    final public function offsetUnset($offset) {
364 364
         throw new LogicException('Raw table access is immutable.');
365 365
     }
366 366
 
@@ -369,7 +369,7 @@  discard block
 block discarded – undo
369 369
      *
370 370
      * @return Num
371 371
      */
372
-    public function pi () {
372
+    public function pi() {
373 373
         return Num::factory($this, "PI()");
374 374
     }
375 375
 
@@ -380,7 +380,7 @@  discard block
 block discarded – undo
380 380
      * @param array $options
381 381
      * @return Statement
382 382
      */
383
-    public function prepare ($sql, $options = []) {
383
+    public function prepare($sql, $options = []) {
384 384
         $this->logger->__invoke($sql);
385 385
         /** @var Statement $statement */
386 386
         $statement = parent::prepare($sql, $options);
@@ -396,7 +396,7 @@  discard block
 block discarded – undo
396 396
      * @param array $ctorargs Optional.
397 397
      * @return Statement
398 398
      */
399
-    public function query ($sql, $mode = PDO::ATTR_DEFAULT_FETCH_MODE, $arg3 = null, array $ctorargs = []) {
399
+    public function query($sql, $mode = PDO::ATTR_DEFAULT_FETCH_MODE, $arg3 = null, array $ctorargs = []) {
400 400
         $this->logger->__invoke($sql);
401 401
         /** @var Statement $statement */
402 402
         $statement = parent::query(...func_get_args());
@@ -414,7 +414,7 @@  discard block
 block discarded – undo
414 414
      * @param int $type Ignored.
415 415
      * @return string|ExpressionInterface
416 416
      */
417
-    public function quote ($value, $type = self::PARAM_STR) {
417
+    public function quote($value, $type = self::PARAM_STR) {
418 418
         if ($value instanceof ExpressionInterface) {
419 419
             return $value;
420 420
         }
@@ -434,7 +434,7 @@  discard block
 block discarded – undo
434 434
      * @param array $values
435 435
      * @return string[]
436 436
      */
437
-    public function quoteArray (array $values) {
437
+    public function quoteArray(array $values) {
438 438
         return array_map([$this, 'quote'], $values);
439 439
     }
440 440
 
@@ -444,7 +444,7 @@  discard block
 block discarded – undo
444 444
      * @param array $values
445 445
      * @return string
446 446
      */
447
-    public function quoteList (array $values): string {
447
+    public function quoteList(array $values): string {
448 448
         return implode(',', $this->quoteArray($values));
449 449
     }
450 450
 
@@ -453,7 +453,7 @@  discard block
 block discarded – undo
453 453
      *
454 454
      * @return Num
455 455
      */
456
-    public function rand () {
456
+    public function rand() {
457 457
         return Num::factory($this, "RAND()");
458 458
     }
459 459
 
@@ -464,7 +464,7 @@  discard block
 block discarded – undo
464 464
      *
465 465
      * @return true
466 466
      */
467
-    public function rollBack () {
467
+    public function rollBack() {
468 468
         assert($this->transactions > 0);
469 469
         if ($this->transactions === 1) {
470 470
             $this->logger->__invoke("ROLLBACK TRANSACTION");
@@ -484,7 +484,7 @@  discard block
 block discarded – undo
484 484
      * @param EntityInterface $entity
485 485
      * @return int ID
486 486
      */
487
-    public function save (EntityInterface $entity): int {
487
+    public function save(EntityInterface $entity): int {
488 488
         return $this->getRecord($entity)->save($entity);
489 489
     }
490 490
 
@@ -493,7 +493,7 @@  discard block
 block discarded – undo
493 493
      * @param Junction $junction
494 494
      * @return $this
495 495
      */
496
-    public function setJunction (string $interface, Junction $junction) {
496
+    public function setJunction(string $interface, Junction $junction) {
497 497
         $this->junctions[$interface] = $junction;
498 498
         return $this;
499 499
     }
@@ -502,7 +502,7 @@  discard block
 block discarded – undo
502 502
      * @param Closure $logger
503 503
      * @return $this
504 504
      */
505
-    public function setLogger (Closure $logger) {
505
+    public function setLogger(Closure $logger) {
506 506
         $this->logger = $logger;
507 507
         return $this;
508 508
     }
@@ -512,7 +512,7 @@  discard block
 block discarded – undo
512 512
      * @param Record $record
513 513
      * @return $this
514 514
      */
515
-    public function setRecord (string $class, Record $record) {
515
+    public function setRecord(string $class, Record $record) {
516 516
         $this->records[$class] = $record;
517 517
         return $this;
518 518
     }
@@ -521,7 +521,7 @@  discard block
 block discarded – undo
521 521
      * @param callable[] $callbacks Keyed by function name.
522 522
      * @param bool $deterministic Whether the callbacks aren't random / are without side-effects.
523 523
      */
524
-    public function sqliteCreateFunctions (array $callbacks, bool $deterministic = true): void {
524
+    public function sqliteCreateFunctions(array $callbacks, bool $deterministic = true): void {
525 525
         $deterministic = $deterministic ? self::SQLITE_DETERMINISTIC : 0;
526 526
         foreach ($callbacks as $name => $callback) {
527 527
             $argc = (new ReflectionFunction($callback))->getNumberOfRequiredParameters();
@@ -537,7 +537,7 @@  discard block
 block discarded – undo
537 537
      * @param callable $work
538 538
      * @return mixed The return value of `$work`
539 539
      */
540
-    public function transact (callable $work) {
540
+    public function transact(callable $work) {
541 541
         $transaction = $this->newTransaction();
542 542
         $return = call_user_func($work);
543 543
         $transaction->commit();
Please login to merge, or discard this patch.