Passed
Push — master ( 6df7c9...74bc2a )
by y
02:15
created
src/DB/SQL/Predicate.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
      * @param string[] $conditions
18 18
      * @return Predicate
19 19
      */
20
-    public static function all (array $conditions) {
20
+    public static function all(array $conditions) {
21 21
         if (count($conditions) === 1) {
22 22
             return new static(reset($conditions));
23 23
         }
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
      * @param string[] $conditions
31 31
      * @return Predicate
32 32
      */
33
-    public static function any (array $conditions) {
33
+    public static function any(array $conditions) {
34 34
         if (count($conditions) === 1) {
35 35
             return new static(reset($conditions));
36 36
         }
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
      *
43 43
      * @return Predicate
44 44
      */
45
-    public function invert () {
45
+    public function invert() {
46 46
         return new static("NOT({$this})");
47 47
     }
48 48
 }
49 49
\ No newline at end of file
Please login to merge, or discard this patch.
src/DB/Select.php 1 patch
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
      * @param string|Select $table
113 113
      * @param string[] $columns
114 114
      */
115
-    public function __construct (DB $db, $table, array $columns) {
115
+    public function __construct(DB $db, $table, array $columns) {
116 116
         parent::__construct($db);
117 117
         if ($table instanceof Select) {
118 118
             $this->table = $table->toSubquery();
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
      * @param array $args
133 133
      * @return Statement
134 134
      */
135
-    public function __invoke (array $args = []) {
135
+    public function __invoke(array $args = []) {
136 136
         return $this->execute($args);
137 137
     }
138 138
 
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
      *
142 142
      * @return string
143 143
      */
144
-    final public function __toString () {
144
+    final public function __toString() {
145 145
         return $this->alias;
146 146
     }
147 147
 
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
      * @param array $args Execution arguments.
152 152
      * @return int
153 153
      */
154
-    public function count (array $args = []): int {
154
+    public function count(array $args = []): int {
155 155
         $clone = clone $this;
156 156
         $clone->_columns = 'COUNT(*)';
157 157
         $clone->_order = '';
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
      * @param array $args
165 165
      * @return Statement
166 166
      */
167
-    public function execute (array $args = []) {
167
+    public function execute(array $args = []) {
168 168
         if (empty($args)) {
169 169
             return $this->db->query($this->toSql());
170 170
         }
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
      * @param array $args Execution arguments.
180 180
      * @return array
181 181
      */
182
-    public function getAll (array $args = []): array {
182
+    public function getAll(array $args = []): array {
183 183
         return iterator_to_array($this->fetcher->__invoke($this->execute($args)));
184 184
     }
185 185
 
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
      * @param array $args Execution arguments.
193 193
      * @return Generator
194 194
      */
195
-    public function getEach (array $args = []) {
195
+    public function getEach(array $args = []) {
196 196
         yield from $this->fetcher->__invoke($this->execute($args));
197 197
     }
198 198
 
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
      * @param array $args
205 205
      * @return mixed
206 206
      */
207
-    public function getFirst (array $args = []) {
207
+    public function getFirst(array $args = []) {
208 208
         return $this->getEach($args)->current();
209 209
     }
210 210
 
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
      *
216 216
      * @return Generator
217 217
      */
218
-    public function getIterator () {
218
+    public function getIterator() {
219 219
         yield from $this->getEach();
220 220
     }
221 221
 
@@ -225,7 +225,7 @@  discard block
 block discarded – undo
225 225
      * @param string $column
226 226
      * @return $this
227 227
      */
228
-    public function group (string $column) {
228
+    public function group(string $column) {
229 229
         if (!strlen($this->_group)) {
230 230
             $this->_group = " GROUP BY {$column}";
231 231
         }
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
      * @param string $condition
242 242
      * @return $this
243 243
      */
244
-    public function having (string $condition) {
244
+    public function having(string $condition) {
245 245
         if (!strlen($this->_having)) {
246 246
             $this->_having = " HAVING {$condition}";
247 247
         }
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
      * @param bool $all
259 259
      * @return $this
260 260
      */
261
-    public function intersect (Select $select, $all = false) {
261
+    public function intersect(Select $select, $all = false) {
262 262
         $select = clone $select;
263 263
         $select->_order = '';
264 264
         $select->_limit = '';
@@ -276,7 +276,7 @@  discard block
 block discarded – undo
276 276
      *
277 277
      * @return Predicate
278 278
      */
279
-    public function isEmpty () {
279
+    public function isEmpty() {
280 280
         return new Predicate("NOT EXISTS ({$this->toSql()})");
281 281
     }
282 282
 
@@ -285,7 +285,7 @@  discard block
 block discarded – undo
285 285
      *
286 286
      * @return Predicate
287 287
      */
288
-    public function isNotEmpty () {
288
+    public function isNotEmpty() {
289 289
         return new Predicate("EXISTS ({$this->toSql()})");
290 290
     }
291 291
 
@@ -297,7 +297,7 @@  discard block
 block discarded – undo
297 297
      * @param string $type
298 298
      * @return $this
299 299
      */
300
-    public function join ($table, string $condition, string $type = 'INNER') {
300
+    public function join($table, string $condition, string $type = 'INNER') {
301 301
         if ($table instanceof Select) {
302 302
             $table = $table->toSubquery();
303 303
         }
@@ -312,7 +312,7 @@  discard block
 block discarded – undo
312 312
      * @param int $offset
313 313
      * @return $this
314 314
      */
315
-    public function limit (int $limit, int $offset = 0) {
315
+    public function limit(int $limit, int $offset = 0) {
316 316
         if ($limit == 0) {
317 317
             $this->_limit = '';
318 318
         }
@@ -331,7 +331,7 @@  discard block
 block discarded – undo
331 331
      * @param mixed $offset Ordinal or reference name.
332 332
      * @return bool
333 333
      */
334
-    public function offsetExists ($offset): bool {
334
+    public function offsetExists($offset): bool {
335 335
         return isset($this->refs[$offset]);
336 336
     }
337 337
 
@@ -341,7 +341,7 @@  discard block
 block discarded – undo
341 341
      * @param mixed $offset Ordinal or reference name.
342 342
      * @return Column
343 343
      */
344
-    public function offsetGet ($offset) {
344
+    public function offsetGet($offset) {
345 345
         return $this->refs[$offset];
346 346
     }
347 347
 
@@ -351,7 +351,7 @@  discard block
 block discarded – undo
351 351
      * @param string $order
352 352
      * @return $this
353 353
      */
354
-    public function order (string $order) {
354
+    public function order(string $order) {
355 355
         if (strlen($order)) {
356 356
             $order = " ORDER BY {$order}";
357 357
         }
@@ -362,7 +362,7 @@  discard block
 block discarded – undo
362 362
     /**
363 363
      * @return Statement
364 364
      */
365
-    public function prepare () {
365
+    public function prepare() {
366 366
         return $this->db->prepare($this->toSql());
367 367
     }
368 368
 
@@ -370,7 +370,7 @@  discard block
 block discarded – undo
370 370
      * @param string $alias
371 371
      * @return $this
372 372
      */
373
-    public function setAlias (string $alias) {
373
+    public function setAlias(string $alias) {
374 374
         $this->alias = $alias;
375 375
         foreach ($this->refs as $k => $column) {
376 376
             $this->refs[$k] = $column->setQualifier($alias);
@@ -384,7 +384,7 @@  discard block
 block discarded – undo
384 384
      * @param string[] $columns
385 385
      * @return $this
386 386
      */
387
-    public function setColumns (array $columns) {
387
+    public function setColumns(array $columns) {
388 388
         $this->refs = [];
389 389
         $_columns = [];
390 390
         $i = 0;
@@ -413,7 +413,7 @@  discard block
 block discarded – undo
413 413
      * @param Closure $fetcher
414 414
      * @return $this
415 415
      */
416
-    public function setFetcher (Closure $fetcher) {
416
+    public function setFetcher(Closure $fetcher) {
417 417
         $this->fetcher = $fetcher;
418 418
         return $this;
419 419
     }
@@ -423,7 +423,7 @@  discard block
 block discarded – undo
423 423
      *
424 424
      * @return string
425 425
      */
426
-    public function toSql (): string {
426
+    public function toSql(): string {
427 427
         $sql = "SELECT {$this->_columns} FROM {$this->table}";
428 428
         $sql .= $this->_join;
429 429
         $sql .= $this->_where;
@@ -440,7 +440,7 @@  discard block
 block discarded – undo
440 440
      *
441 441
      * @return string
442 442
      */
443
-    public function toSubquery (): string {
443
+    public function toSubquery(): string {
444 444
         return "({$this->toSql()}) AS {$this->alias}";
445 445
     }
446 446
 
@@ -451,7 +451,7 @@  discard block
 block discarded – undo
451 451
      * @param bool $all
452 452
      * @return $this
453 453
      */
454
-    public function union (Select $select, $all = false) {
454
+    public function union(Select $select, $all = false) {
455 455
         $select = clone $select;
456 456
         $select->_order = '';
457 457
         $select->_limit = '';
@@ -470,7 +470,7 @@  discard block
 block discarded – undo
470 470
      * @param string $condition
471 471
      * @return $this
472 472
      */
473
-    public function where (string $condition) {
473
+    public function where(string $condition) {
474 474
         if (!strlen($this->_where)) {
475 475
             $this->_where = " WHERE {$condition}";
476 476
         }
Please login to merge, or discard this patch.
src/DB/AttributesTrait.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
     /**
31 31
      * @return array
32 32
      */
33
-    public function getAttributes (): array {
33
+    public function getAttributes(): array {
34 34
         return $this->attributes ?: [];
35 35
     }
36 36
 
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
      * @param mixed $attr
39 39
      * @return bool
40 40
      */
41
-    public function offsetExists ($attr): bool {
41
+    public function offsetExists($attr): bool {
42 42
         return $this->attributes and array_key_exists($attr, $this->attributes);
43 43
     }
44 44
 
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
      * @param mixed $attr
47 47
      * @return null|mixed
48 48
      */
49
-    public function offsetGet ($attr) {
49
+    public function offsetGet($attr) {
50 50
         return $this->attributes[$attr] ?? null;
51 51
     }
52 52
 
@@ -54,14 +54,14 @@  discard block
 block discarded – undo
54 54
      * @param mixed $attr
55 55
      * @param mixed $value
56 56
      */
57
-    public function offsetSet ($attr, $value): void {
57
+    public function offsetSet($attr, $value): void {
58 58
         $this->attributes[$attr] = $value;
59 59
     }
60 60
 
61 61
     /**
62 62
      * @param mixed $attr
63 63
      */
64
-    public function offsetUnset ($attr): void {
64
+    public function offsetUnset($attr): void {
65 65
         unset($this->attributes[$attr]);
66 66
     }
67 67
 
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
      * @param array $attributes
70 70
      * @return $this
71 71
      */
72
-    public function setAttributes (array $attributes) {
72
+    public function setAttributes(array $attributes) {
73 73
         $this->attributes = $attributes;
74 74
         return $this;
75 75
     }
Please login to merge, or discard this patch.
src/DB/Junction.php 1 patch
Spacing   +5 added lines, -5 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
         try {
34 34
             $ref = new ReflectionClass($interface);
35 35
         }
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
      * @param string $table
53 53
      * @param string[] $classes
54 54
      */
55
-    public function __construct (DB $db, string $table, array $classes) {
55
+    public function __construct(DB $db, string $table, array $classes) {
56 56
         parent::__construct($db, $table, array_keys($classes));
57 57
         $this->classes = $classes;
58 58
     }
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
      * @param array $match Keyed by junction column.
67 67
      * @return Select
68 68
      */
69
-    public function getCollection (string $key, array $match = []) {
69
+    public function getCollection(string $key, array $match = []) {
70 70
         $record = $this->db->getRecord($this->classes[$key]);
71 71
         $select = $record->select();
72 72
         $select->join($this, $this[$key]->isEqual($record['id']));
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
      * @param int[] $ids Keyed by column.
83 83
      * @return int Rows affected.
84 84
      */
85
-    public function link (array $ids): int {
85
+    public function link(array $ids): int {
86 86
         $link = $this->cache(__FUNCTION__, function() {
87 87
             $columns = implode(',', array_keys($this->columns));
88 88
             $slots = implode(',', SQL::slots(array_keys($this->columns)));
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
      * @param array $ids Keyed by Column
107 107
      * @return int Rows affected
108 108
      */
109
-    public function unlink (array $ids): int {
109
+    public function unlink(array $ids): int {
110 110
         return $this->delete($ids);
111 111
     }
112 112
 }
113 113
\ No newline at end of file
Please login to merge, or discard this patch.
src/DB.php 1 patch
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
      * @param string $password
53 53
      * @param array $options
54 54
      */
55
-    public function __construct ($dsn, $username = null, $password = null, $options = null) {
55
+    public function __construct($dsn, $username = null, $password = null, $options = null) {
56 56
         parent::__construct($dsn, $username, $password, $options);
57 57
         $this->driver = $this->getAttribute(self::ATTR_DRIVER_NAME);
58 58
         $this->setAttribute(self::ATTR_DEFAULT_FETCH_MODE, self::FETCH_ASSOC);
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
      *
75 75
      * @return string
76 76
      */
77
-    final public function __toString () {
77
+    final public function __toString() {
78 78
         return $this->driver;
79 79
     }
80 80
 
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
      * @param string $sql
85 85
      * @return int
86 86
      */
87
-    public function exec ($sql): int {
87
+    public function exec($sql): int {
88 88
         $this->logger->__invoke($sql);
89 89
         return parent::exec($sql);
90 90
     }
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
     /**
93 93
      * @return string
94 94
      */
95
-    final public function getDriver (): string {
95
+    final public function getDriver(): string {
96 96
         return $this->driver;
97 97
     }
98 98
 
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
      * @param string $interface
103 103
      * @return Junction
104 104
      */
105
-    public function getJunction ($interface) {
105
+    public function getJunction($interface) {
106 106
         if (!isset($this->junctions[$interface])) {
107 107
             $this->junctions[$interface] = Junction::fromInterface($this, $interface);
108 108
         }
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
     /**
113 113
      * @return Closure
114 114
      */
115
-    public function getLogger () {
115
+    public function getLogger() {
116 116
         return $this->logger;
117 117
     }
118 118
 
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
      * @param string|EntityInterface $class
123 123
      * @return Record
124 124
      */
125
-    public function getRecord ($class) {
125
+    public function getRecord($class) {
126 126
         if (is_object($class)) {
127 127
             $class = get_class($class);
128 128
         }
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
      * @param mixed $b
150 150
      * @return Predicate
151 151
      */
152
-    public function match ($a, $b) {
152
+    public function match($a, $b) {
153 153
         if ($b instanceof Closure) {
154 154
             return $b->__invoke($a, $this);
155 155
         }
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
      * @param string $class Class or interface name.
170 170
      * @return bool
171 171
      */
172
-    public function offsetExists ($class): bool {
172
+    public function offsetExists($class): bool {
173 173
         return (bool)$this->offsetGet($class);
174 174
     }
175 175
 
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
      * @param string $class Class or interface name.
178 178
      * @return null|Record|Junction
179 179
      */
180
-    public function offsetGet ($class) {
180
+    public function offsetGet($class) {
181 181
         if (class_exists($class)) {
182 182
             return $this->getRecord($class);
183 183
         }
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
      * @param string $class Class or interface name.
192 192
      * @param Record|Junction $access
193 193
      */
194
-    public function offsetSet ($class, $access) {
194
+    public function offsetSet($class, $access) {
195 195
         if ($access instanceof Record) {
196 196
             $this->setRecord($class, $access);
197 197
         }
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
     /**
204 204
      * @param string $class Class or interface name.
205 205
      */
206
-    public function offsetUnset ($class) {
206
+    public function offsetUnset($class) {
207 207
         unset($this->records[$class]);
208 208
         unset($this->junctions[$class]);
209 209
     }
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
      * @param array $options
216 216
      * @return Statement
217 217
      */
218
-    public function prepare ($sql, $options = []) {
218
+    public function prepare($sql, $options = []) {
219 219
         $this->logger->__invoke($sql);
220 220
         /** @var Statement $statement */
221 221
         $statement = parent::prepare($sql, $options);
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
      * @param array $ctorargs Optional.
232 232
      * @return Statement
233 233
      */
234
-    public function query ($sql, $mode = PDO::ATTR_DEFAULT_FETCH_MODE, $arg3 = null, array $ctorargs = []) {
234
+    public function query($sql, $mode = PDO::ATTR_DEFAULT_FETCH_MODE, $arg3 = null, array $ctorargs = []) {
235 235
         $this->logger->__invoke($sql);
236 236
         /** @var Statement $statement */
237 237
         $statement = parent::query(...func_get_args());
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
      * @param int $type Ignored.
250 250
      * @return string|ExpressionInterface
251 251
      */
252
-    public function quote ($value, $type = self::PARAM_STR) {
252
+    public function quote($value, $type = self::PARAM_STR) {
253 253
         if ($value instanceof ExpressionInterface) {
254 254
             return $value;
255 255
         }
@@ -269,7 +269,7 @@  discard block
 block discarded – undo
269 269
      * @param array $values
270 270
      * @return string[]
271 271
      */
272
-    public function quoteArray (array $values) {
272
+    public function quoteArray(array $values) {
273 273
         return array_map([$this, 'quote'], $values);
274 274
     }
275 275
 
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
      * @param array $values
280 280
      * @return string
281 281
      */
282
-    public function quoteList (array $values): string {
282
+    public function quoteList(array $values): string {
283 283
         return implode(',', $this->quoteArray($values));
284 284
     }
285 285
 
@@ -289,7 +289,7 @@  discard block
 block discarded – undo
289 289
      * @param EntityInterface $entity
290 290
      * @return int ID
291 291
      */
292
-    public function save (EntityInterface $entity): int {
292
+    public function save(EntityInterface $entity): int {
293 293
         return $this->getRecord($entity)->save($entity);
294 294
     }
295 295
 
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
      * @param Junction $junction
299 299
      * @return $this
300 300
      */
301
-    public function setJunction (string $interface, Junction $junction) {
301
+    public function setJunction(string $interface, Junction $junction) {
302 302
         $this->junctions[$interface] = $junction;
303 303
         return $this;
304 304
     }
@@ -307,7 +307,7 @@  discard block
 block discarded – undo
307 307
      * @param Closure $logger
308 308
      * @return $this
309 309
      */
310
-    public function setLogger (Closure $logger) {
310
+    public function setLogger(Closure $logger) {
311 311
         $this->logger = $logger;
312 312
         return $this;
313 313
     }
@@ -317,7 +317,7 @@  discard block
 block discarded – undo
317 317
      * @param Record $record
318 318
      * @return $this
319 319
      */
320
-    public function setRecord (string $class, Record $record) {
320
+    public function setRecord(string $class, Record $record) {
321 321
         $this->records[$class] = $record;
322 322
         return $this;
323 323
     }
Please login to merge, or discard this patch.