@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | */ |
16 | 16 | trait ComparisonTrait { |
17 | 17 | |
18 | - abstract public function __toString (); |
|
18 | + abstract public function __toString(); |
|
19 | 19 | |
20 | 20 | /** |
21 | 21 | * @var DB |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | * @param array $values |
29 | 29 | * @return Value |
30 | 30 | */ |
31 | - public function coalesce (array $values) { |
|
31 | + public function coalesce(array $values) { |
|
32 | 32 | array_unshift($values, $this); |
33 | 33 | $values = $this->db->quoteList($values); |
34 | 34 | return Value::factory($this->db, "COALESCE({$values})"); |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | * @param null|bool|number|string|Select $arg |
44 | 44 | * @return Predicate |
45 | 45 | */ |
46 | - public function is ($arg): Predicate { |
|
46 | + public function is($arg): Predicate { |
|
47 | 47 | if ($arg instanceof Select) { |
48 | 48 | if ($this->db->isSQLite()) { |
49 | 49 | return Select::factory($this->db, $arg, [$arg[0]]) |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | * @param number $max |
72 | 72 | * @return Predicate |
73 | 73 | */ |
74 | - public function isBetween ($min, $max) { |
|
74 | + public function isBetween($min, $max) { |
|
75 | 75 | $min = $this->db->quote($min); |
76 | 76 | $max = $this->db->quote($max); |
77 | 77 | return Predicate::factory($this->db, "{$this} BETWEEN {$min} AND {$max}"); |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | * @param bool|number|string|array|Select $arg |
84 | 84 | * @return Predicate |
85 | 85 | */ |
86 | - public function isEqual ($arg) { |
|
86 | + public function isEqual($arg) { |
|
87 | 87 | return $this->db->match($this, $arg); |
88 | 88 | } |
89 | 89 | |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | * |
93 | 93 | * @return Predicate |
94 | 94 | */ |
95 | - public function isFalse () { |
|
95 | + public function isFalse() { |
|
96 | 96 | return Predicate::factory($this->db, "{$this} IS FALSE"); |
97 | 97 | } |
98 | 98 | |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | * @param string $multi `ALL|ANY` |
109 | 109 | * @return Predicate |
110 | 110 | */ |
111 | - public function isGreater ($arg, string $multi = 'ALL') { |
|
111 | + public function isGreater($arg, string $multi = 'ALL') { |
|
112 | 112 | if ($arg instanceof Select) { |
113 | 113 | if ($this->db->isSQLite()) { |
114 | 114 | $sub = Select::factory($this->db, $arg, [$arg[0]]); |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | * @param string $multi `ALL|ANY` |
135 | 135 | * @return Predicate |
136 | 136 | */ |
137 | - public function isGreaterOrEqual ($arg, string $multi = 'ALL') { |
|
137 | + public function isGreaterOrEqual($arg, string $multi = 'ALL') { |
|
138 | 138 | if ($arg instanceof Select) { |
139 | 139 | if ($this->db->isSQLite()) { |
140 | 140 | $sub = Select::factory($this->db, $arg, [$arg[0]]); |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | * @param string $multi `ALL|ANY` |
161 | 161 | * @return Predicate |
162 | 162 | */ |
163 | - public function isLess ($arg, string $multi = 'ALL') { |
|
163 | + public function isLess($arg, string $multi = 'ALL') { |
|
164 | 164 | if ($arg instanceof Select) { |
165 | 165 | if ($this->db->isSQLite()) { |
166 | 166 | $sub = Select::factory($this->db, $arg, [$arg[0]]); |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | * @param string $multi `ALL|ANY` |
187 | 187 | * @return Predicate |
188 | 188 | */ |
189 | - public function isLessOrEqual ($arg, string $multi = 'ALL') { |
|
189 | + public function isLessOrEqual($arg, string $multi = 'ALL') { |
|
190 | 190 | if ($arg instanceof Select) { |
191 | 191 | if ($this->db->isSQLite()) { |
192 | 192 | $sub = Select::factory($this->db, $arg, [$arg[0]]); |
@@ -206,7 +206,7 @@ discard block |
||
206 | 206 | * @param string $pattern |
207 | 207 | * @return Predicate |
208 | 208 | */ |
209 | - public function isLike (string $pattern) { |
|
209 | + public function isLike(string $pattern) { |
|
210 | 210 | $pattern = $this->db->quote($pattern); |
211 | 211 | return Predicate::factory($this->db, "{$this} LIKE {$pattern}"); |
212 | 212 | } |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | * @param null|bool|number|string|Select $arg |
218 | 218 | * @return Predicate |
219 | 219 | */ |
220 | - public function isNot ($arg) { |
|
220 | + public function isNot($arg) { |
|
221 | 221 | return $this->is($arg)->not(); |
222 | 222 | } |
223 | 223 | |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | * @param number $max |
229 | 229 | * @return Predicate |
230 | 230 | */ |
231 | - public function isNotBetween ($min, $max) { |
|
231 | + public function isNotBetween($min, $max) { |
|
232 | 232 | $min = $this->db->quote($min); |
233 | 233 | $max = $this->db->quote($max); |
234 | 234 | return Predicate::factory($this->db, "{$this} NOT BETWEEN {$min} AND {$max}"); |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | * @param bool|number|string|array|Select $arg |
241 | 241 | * @return Predicate |
242 | 242 | */ |
243 | - public function isNotEqual ($arg) { |
|
243 | + public function isNotEqual($arg) { |
|
244 | 244 | if ($arg instanceof Select) { |
245 | 245 | return Predicate::factory($this->db, "{$this} NOT IN ({$arg->toSql()})"); |
246 | 246 | } |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | * @param string $pattern |
257 | 257 | * @return Predicate |
258 | 258 | */ |
259 | - public function isNotLike (string $pattern) { |
|
259 | + public function isNotLike(string $pattern) { |
|
260 | 260 | $pattern = $this->db->quote($pattern); |
261 | 261 | return Predicate::factory($this->db, "{$this} NOT LIKE {$pattern}"); |
262 | 262 | } |
@@ -266,7 +266,7 @@ discard block |
||
266 | 266 | * |
267 | 267 | * @return Predicate |
268 | 268 | */ |
269 | - public function isNotNull () { |
|
269 | + public function isNotNull() { |
|
270 | 270 | return Predicate::factory($this->db, "{$this} IS NOT NULL"); |
271 | 271 | } |
272 | 272 | |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | * @param string $pattern |
277 | 277 | * @return Predicate |
278 | 278 | */ |
279 | - public function isNotRegExp (string $pattern) { |
|
279 | + public function isNotRegExp(string $pattern) { |
|
280 | 280 | $pattern = $this->db->quote($pattern); |
281 | 281 | return Predicate::factory($this->db, "{$this} NOT REGEXP {$pattern}"); |
282 | 282 | } |
@@ -286,7 +286,7 @@ discard block |
||
286 | 286 | * |
287 | 287 | * @return Predicate |
288 | 288 | */ |
289 | - public function isNull () { |
|
289 | + public function isNull() { |
|
290 | 290 | return Predicate::factory($this->db, "{$this} IS NULL"); |
291 | 291 | } |
292 | 292 | |
@@ -296,7 +296,7 @@ discard block |
||
296 | 296 | * @param string $pattern |
297 | 297 | * @return Predicate |
298 | 298 | */ |
299 | - public function isRegExp (string $pattern) { |
|
299 | + public function isRegExp(string $pattern) { |
|
300 | 300 | $pattern = $this->db->quote($pattern); |
301 | 301 | return Predicate::factory($this->db, "{$this} REGEXP {$pattern}"); |
302 | 302 | } |
@@ -17,7 +17,7 @@ |
||
17 | 17 | * @param array $args The first argument must be a {@link DB} instance. |
18 | 18 | * @return static |
19 | 19 | */ |
20 | - public static function __callStatic (string $ignored, array $args) { |
|
20 | + public static function __callStatic(string $ignored, array $args) { |
|
21 | 21 | /** @var DB $db */ |
22 | 22 | $db = $args[0]; |
23 | 23 | unset($args[0]); |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | * @param string|Select $table |
117 | 117 | * @param string[] $columns |
118 | 118 | */ |
119 | - public function __construct (DB $db, $table, array $columns) { |
|
119 | + public function __construct(DB $db, $table, array $columns) { |
|
120 | 120 | parent::__construct($db); |
121 | 121 | if ($table instanceof Select) { |
122 | 122 | $this->table = $table->toSubquery(); |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | * @param array $args |
137 | 137 | * @return Statement |
138 | 138 | */ |
139 | - public function __invoke (array $args = []) { |
|
139 | + public function __invoke(array $args = []) { |
|
140 | 140 | return $this->execute($args); |
141 | 141 | } |
142 | 142 | |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | * |
146 | 146 | * @return string |
147 | 147 | */ |
148 | - final public function __toString () { |
|
148 | + final public function __toString() { |
|
149 | 149 | return $this->alias; |
150 | 150 | } |
151 | 151 | |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | * @param array $args Execution arguments. |
156 | 156 | * @return int |
157 | 157 | */ |
158 | - public function count (array $args = []): int { |
|
158 | + public function count(array $args = []): int { |
|
159 | 159 | $clone = clone $this; |
160 | 160 | $clone->_columns = 'COUNT(*)'; |
161 | 161 | $clone->_order = ''; |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | * @param array $args |
169 | 169 | * @return Statement |
170 | 170 | */ |
171 | - public function execute (array $args = []) { |
|
171 | + public function execute(array $args = []) { |
|
172 | 172 | if (empty($args)) { |
173 | 173 | return $this->db->query($this->toSql()); |
174 | 174 | } |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | * @param array $args Execution arguments. |
184 | 184 | * @return array |
185 | 185 | */ |
186 | - public function getAll (array $args = []): array { |
|
186 | + public function getAll(array $args = []): array { |
|
187 | 187 | return iterator_to_array($this->fetcher->__invoke($this->execute($args))); |
188 | 188 | } |
189 | 189 | |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | * @param array $args Execution arguments. |
197 | 197 | * @return Generator |
198 | 198 | */ |
199 | - public function getEach (array $args = []) { |
|
199 | + public function getEach(array $args = []) { |
|
200 | 200 | yield from $this->fetcher->__invoke($this->execute($args)); |
201 | 201 | } |
202 | 202 | |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | * @param array $args |
209 | 209 | * @return mixed |
210 | 210 | */ |
211 | - public function getFirst (array $args = []) { |
|
211 | + public function getFirst(array $args = []) { |
|
212 | 212 | return $this->getEach($args)->current(); |
213 | 213 | } |
214 | 214 | |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | * |
220 | 220 | * @return Generator |
221 | 221 | */ |
222 | - public function getIterator () { |
|
222 | + public function getIterator() { |
|
223 | 223 | yield from $this->getEach(); |
224 | 224 | } |
225 | 225 | |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | * @param string $column |
230 | 230 | * @return $this |
231 | 231 | */ |
232 | - public function group (string $column) { |
|
232 | + public function group(string $column) { |
|
233 | 233 | if (!strlen($this->_group)) { |
234 | 234 | $this->_group = " GROUP BY {$column}"; |
235 | 235 | } |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | * @param string $condition |
246 | 246 | * @return $this |
247 | 247 | */ |
248 | - public function having (string $condition) { |
|
248 | + public function having(string $condition) { |
|
249 | 249 | if (!strlen($this->_having)) { |
250 | 250 | $this->_having = " HAVING {$condition}"; |
251 | 251 | } |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | * @param bool $all |
263 | 263 | * @return $this |
264 | 264 | */ |
265 | - public function intersect (Select $select, $all = false) { |
|
265 | + public function intersect(Select $select, $all = false) { |
|
266 | 266 | $select = clone $select; |
267 | 267 | $select->_order = ''; |
268 | 268 | $select->_limit = ''; |
@@ -280,7 +280,7 @@ discard block |
||
280 | 280 | * |
281 | 281 | * @return Predicate |
282 | 282 | */ |
283 | - public function isEmpty () { |
|
283 | + public function isEmpty() { |
|
284 | 284 | return Predicate::factory($this->db, "NOT EXISTS ({$this->toSql()})"); |
285 | 285 | } |
286 | 286 | |
@@ -289,7 +289,7 @@ discard block |
||
289 | 289 | * |
290 | 290 | * @return Predicate |
291 | 291 | */ |
292 | - public function isNotEmpty () { |
|
292 | + public function isNotEmpty() { |
|
293 | 293 | return Predicate::factory($this->db, "EXISTS ({$this->toSql()})"); |
294 | 294 | } |
295 | 295 | |
@@ -301,7 +301,7 @@ discard block |
||
301 | 301 | * @param string $type |
302 | 302 | * @return $this |
303 | 303 | */ |
304 | - public function join ($table, string $condition, string $type = 'INNER') { |
|
304 | + public function join($table, string $condition, string $type = 'INNER') { |
|
305 | 305 | if ($table instanceof Select) { |
306 | 306 | $table = $table->toSubquery(); |
307 | 307 | } |
@@ -316,7 +316,7 @@ discard block |
||
316 | 316 | * @param int $offset |
317 | 317 | * @return $this |
318 | 318 | */ |
319 | - public function limit (int $limit, int $offset = 0) { |
|
319 | + public function limit(int $limit, int $offset = 0) { |
|
320 | 320 | if ($limit == 0) { |
321 | 321 | $this->_limit = ''; |
322 | 322 | } |
@@ -335,7 +335,7 @@ discard block |
||
335 | 335 | * @param int|string $ref Ordinal or reference name. |
336 | 336 | * @return null|Column |
337 | 337 | */ |
338 | - public function offsetGet ($ref) { |
|
338 | + public function offsetGet($ref) { |
|
339 | 339 | if (is_int($ref)) { |
340 | 340 | return current(array_slice($this->refs, $ref, 1)) ?: null; |
341 | 341 | } |
@@ -348,7 +348,7 @@ discard block |
||
348 | 348 | * @param string $order |
349 | 349 | * @return $this |
350 | 350 | */ |
351 | - public function order (string $order) { |
|
351 | + public function order(string $order) { |
|
352 | 352 | if (strlen($order)) { |
353 | 353 | $order = " ORDER BY {$order}"; |
354 | 354 | } |
@@ -359,7 +359,7 @@ discard block |
||
359 | 359 | /** |
360 | 360 | * @return Statement |
361 | 361 | */ |
362 | - public function prepare () { |
|
362 | + public function prepare() { |
|
363 | 363 | return $this->db->prepare($this->toSql()); |
364 | 364 | } |
365 | 365 | |
@@ -367,7 +367,7 @@ discard block |
||
367 | 367 | * @param string $alias |
368 | 368 | * @return $this |
369 | 369 | */ |
370 | - public function setAlias (string $alias) { |
|
370 | + public function setAlias(string $alias) { |
|
371 | 371 | $this->alias = $alias; |
372 | 372 | foreach ($this->refs as $k => $column) { |
373 | 373 | $this->refs[$k] = $column->setQualifier($alias); |
@@ -385,7 +385,7 @@ discard block |
||
385 | 385 | * @param string[] $expressions Keyed by alias if applicable. |
386 | 386 | * @return $this |
387 | 387 | */ |
388 | - public function setColumns (array $expressions) { |
|
388 | + public function setColumns(array $expressions) { |
|
389 | 389 | $this->refs = []; |
390 | 390 | $_columns = []; |
391 | 391 | foreach ($expressions as $alias => $expr) { |
@@ -410,7 +410,7 @@ discard block |
||
410 | 410 | * @param Closure $fetcher |
411 | 411 | * @return $this |
412 | 412 | */ |
413 | - public function setFetcher (Closure $fetcher) { |
|
413 | + public function setFetcher(Closure $fetcher) { |
|
414 | 414 | $this->fetcher = $fetcher; |
415 | 415 | return $this; |
416 | 416 | } |
@@ -420,7 +420,7 @@ discard block |
||
420 | 420 | * |
421 | 421 | * @return string |
422 | 422 | */ |
423 | - public function toSql (): string { |
|
423 | + public function toSql(): string { |
|
424 | 424 | $sql = "SELECT {$this->_columns} FROM {$this->table}"; |
425 | 425 | $sql .= $this->_join; |
426 | 426 | $sql .= $this->_where; |
@@ -437,7 +437,7 @@ discard block |
||
437 | 437 | * |
438 | 438 | * @return string |
439 | 439 | */ |
440 | - public function toSubquery (): string { |
|
440 | + public function toSubquery(): string { |
|
441 | 441 | return "({$this->toSql()}) AS {$this->alias}"; |
442 | 442 | } |
443 | 443 | |
@@ -448,7 +448,7 @@ discard block |
||
448 | 448 | * @param bool $all |
449 | 449 | * @return $this |
450 | 450 | */ |
451 | - public function union (Select $select, $all = false) { |
|
451 | + public function union(Select $select, $all = false) { |
|
452 | 452 | $select = clone $select; |
453 | 453 | $select->_order = ''; |
454 | 454 | $select->_limit = ''; |
@@ -467,7 +467,7 @@ discard block |
||
467 | 467 | * @param string $condition |
468 | 468 | * @return $this |
469 | 469 | */ |
470 | - public function where (string $condition) { |
|
470 | + public function where(string $condition) { |
|
471 | 471 | if (!strlen($this->_where)) { |
472 | 472 | $this->_where = " WHERE {$condition}"; |
473 | 473 | } |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | * @param DB $db |
16 | 16 | * @param string $name |
17 | 17 | */ |
18 | - public function __construct (DB $db, string $name) { |
|
18 | + public function __construct(DB $db, string $name) { |
|
19 | 19 | parent::__construct($db, $name, ['entity', 'attribute', 'value']); |
20 | 20 | } |
21 | 21 | |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | * @param string $attribute |
27 | 27 | * @return bool |
28 | 28 | */ |
29 | - public function exists (int $id, string $attribute): bool { |
|
29 | + public function exists(int $id, string $attribute): bool { |
|
30 | 30 | $exists = $this->cache(__FUNCTION__, function() { |
31 | 31 | $select = $this->select(['COUNT(*) > 0']); |
32 | 32 | $select->where('entity = ? AND attribute = ?'); |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | * @param array $match `[attribute => value]`. If empty, selects all IDs for entities having at least one attribute. |
45 | 45 | * @return Select |
46 | 46 | */ |
47 | - public function find (array $match) { |
|
47 | + public function find(array $match) { |
|
48 | 48 | $select = $this->select([$this['entity']]); |
49 | 49 | $prior = $this; |
50 | 50 | foreach ($match as $attribute => $value) { |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | * @param int $id |
67 | 67 | * @return array `[attribute => value]` |
68 | 68 | */ |
69 | - public function load (int $id): array { |
|
69 | + public function load(int $id): array { |
|
70 | 70 | $load = $this->cache(__FUNCTION__, function() { |
71 | 71 | $select = $this->select(['attribute', 'value']); |
72 | 72 | $select->where('entity = ?'); |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | * @param int[] $ids |
83 | 83 | * @return array[] `[id => attribute => value] |
84 | 84 | */ |
85 | - public function loadAll (array $ids): array { |
|
85 | + public function loadAll(array $ids): array { |
|
86 | 86 | if (empty($ids)) { |
87 | 87 | return []; |
88 | 88 | } |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | * @param array $values `[attribute => value]` |
108 | 108 | * @return $this |
109 | 109 | */ |
110 | - public function save (int $id, array $values) { |
|
110 | + public function save(int $id, array $values) { |
|
111 | 111 | $this->delete([ |
112 | 112 | $this['entity']->isEqual($id), |
113 | 113 | $this['attribute']->isNotEqual(array_keys($values)) |
@@ -75,8 +75,7 @@ discard block |
||
75 | 75 | foreach ($rClass->getProperties() as $rProp) { |
76 | 76 | if (preg_match('/@col(umn)?[\s$]/', $rProp->getDocComment())) { |
77 | 77 | $columns[] = $rProp->getName(); |
78 | - } |
|
79 | - elseif (preg_match('/@eav\s+(?<table>\S+)/', $rProp->getDocComment(), $attr)) { |
|
78 | + } elseif (preg_match('/@eav\s+(?<table>\S+)/', $rProp->getDocComment(), $attr)) { |
|
80 | 79 | $eav[$rProp->getName()] = EAV::factory($db, $attr['table']); |
81 | 80 | } |
82 | 81 | } |
@@ -243,8 +242,7 @@ discard block |
||
243 | 242 | public function save (EntityInterface $entity): int { |
244 | 243 | if (!$entity->getId()) { |
245 | 244 | $this->saveInsert($entity); |
246 | - } |
|
247 | - else { |
|
245 | + } else { |
|
248 | 246 | $this->saveUpdate($entity); |
249 | 247 | } |
250 | 248 | $this->saveEav($entity); |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | * @param string $name |
43 | 43 | * @param string[] $columns |
44 | 44 | */ |
45 | - public function __construct (DB $db, string $name, array $columns) { |
|
45 | + public function __construct(DB $db, string $name, array $columns) { |
|
46 | 46 | parent::__construct($db); |
47 | 47 | $this->name = $name; |
48 | 48 | foreach ($columns as $column) { |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | * |
56 | 56 | * @return string |
57 | 57 | */ |
58 | - final public function __toString () { |
|
58 | + final public function __toString() { |
|
59 | 59 | return $this->name; |
60 | 60 | } |
61 | 61 | |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | * @param array $values |
66 | 66 | * @return int Rows affected. |
67 | 67 | */ |
68 | - public function apply (array $values): int { |
|
68 | + public function apply(array $values): int { |
|
69 | 69 | $columns = implode(',', array_keys($values)); |
70 | 70 | $values = $this->db->quoteList($values); |
71 | 71 | switch ($this->db) { |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | * @param Closure $prepare `():Statement` |
88 | 88 | * @return Statement |
89 | 89 | */ |
90 | - protected function cache (string $key, Closure $prepare) { |
|
90 | + protected function cache(string $key, Closure $prepare) { |
|
91 | 91 | return $this->_cache[$key] ?? $this->_cache[$key] = $prepare->__invoke(); |
92 | 92 | } |
93 | 93 | |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | * @param array $match `[a => b]` |
96 | 96 | * @return int |
97 | 97 | */ |
98 | - public function count (array $match = []) { |
|
98 | + public function count(array $match = []) { |
|
99 | 99 | $select = $this->select(['COUNT(*)']); |
100 | 100 | foreach ($match as $a => $b) { |
101 | 101 | $select->where($this->db->match($this[$a] ?? $a, $b)); |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | * @param array $match |
112 | 112 | * @return int Rows affected. |
113 | 113 | */ |
114 | - public function delete (array $match): int { |
|
114 | + public function delete(array $match): int { |
|
115 | 115 | foreach ($match as $a => $b) { |
116 | 116 | $match[$a] = $this->db->match($this[$a] ?? $a, $b); |
117 | 117 | } |
@@ -122,14 +122,14 @@ discard block |
||
122 | 122 | /** |
123 | 123 | * @return Column[] |
124 | 124 | */ |
125 | - final public function getColumns (): array { |
|
125 | + final public function getColumns(): array { |
|
126 | 126 | return $this->columns; |
127 | 127 | } |
128 | 128 | |
129 | 129 | /** |
130 | 130 | * @return string |
131 | 131 | */ |
132 | - final public function getName (): string { |
|
132 | + final public function getName(): string { |
|
133 | 133 | return $this->name; |
134 | 134 | } |
135 | 135 | |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | * @param array $values |
140 | 140 | * @return Statement |
141 | 141 | */ |
142 | - public function insert (array $values) { |
|
142 | + public function insert(array $values) { |
|
143 | 143 | $columns = implode(',', array_keys($values)); |
144 | 144 | $values = $this->db->quoteList($values); |
145 | 145 | return $this->db->query("INSERT INTO {$this} ($columns) VALUES ($values)"); |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | * @param int|string $column |
150 | 150 | * @return Column |
151 | 151 | */ |
152 | - public function offsetGet ($column) { |
|
152 | + public function offsetGet($column) { |
|
153 | 153 | if (is_int($column)) { |
154 | 154 | return current(array_slice($this->columns, $column, 1)) ?: null; |
155 | 155 | } |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | * @param string[] $columns Defaults to all columns. |
163 | 163 | * @return Select |
164 | 164 | */ |
165 | - public function select (array $columns = []) { |
|
165 | + public function select(array $columns = []) { |
|
166 | 166 | if (empty($columns)) { |
167 | 167 | $columns = $this->columns; |
168 | 168 | } |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | * @param string $name |
176 | 176 | * @return Table |
177 | 177 | */ |
178 | - public function setName (string $name) { |
|
178 | + public function setName(string $name) { |
|
179 | 179 | $clone = clone $this; |
180 | 180 | $clone->name = $name; |
181 | 181 | foreach ($this->columns as $name => $column) { |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | * @param array $match |
194 | 194 | * @return int Rows affected. |
195 | 195 | */ |
196 | - public function update (array $values, array $match): int { |
|
196 | + public function update(array $values, array $match): int { |
|
197 | 197 | foreach ($this->db->quoteArray($values) as $key => $value) { |
198 | 198 | $values[$key] = "{$key} = {$value}"; |
199 | 199 | } |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | * @param string $password |
60 | 60 | * @param array $options |
61 | 61 | */ |
62 | - public function __construct ($dsn, $username = null, $password = null, $options = null) { |
|
62 | + public function __construct($dsn, $username = null, $password = null, $options = null) { |
|
63 | 63 | parent::__construct($dsn, $username, $password, $options); |
64 | 64 | $this->driver = $this->getAttribute(self::ATTR_DRIVER_NAME); |
65 | 65 | $this->setAttribute(self::ATTR_DEFAULT_FETCH_MODE, self::FETCH_ASSOC); |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | * |
82 | 82 | * @return string |
83 | 83 | */ |
84 | - final public function __toString () { |
|
84 | + final public function __toString() { |
|
85 | 85 | return $this->driver; |
86 | 86 | } |
87 | 87 | |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | * @param string $sql |
92 | 92 | * @return int |
93 | 93 | */ |
94 | - public function exec ($sql): int { |
|
94 | + public function exec($sql): int { |
|
95 | 95 | $this->logger->__invoke($sql); |
96 | 96 | return parent::exec($sql); |
97 | 97 | } |
@@ -107,14 +107,14 @@ discard block |
||
107 | 107 | * @param mixed ...$args |
108 | 108 | * @return mixed |
109 | 109 | */ |
110 | - public function factory (string $class, ...$args) { |
|
110 | + public function factory(string $class, ...$args) { |
|
111 | 111 | return new $class($this, ...$args); |
112 | 112 | } |
113 | 113 | |
114 | 114 | /** |
115 | 115 | * @return string |
116 | 116 | */ |
117 | - final public function getDriver (): string { |
|
117 | + final public function getDriver(): string { |
|
118 | 118 | return $this->driver; |
119 | 119 | } |
120 | 120 | |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | * @param string $interface |
125 | 125 | * @return Junction |
126 | 126 | */ |
127 | - public function getJunction ($interface) { |
|
127 | + public function getJunction($interface) { |
|
128 | 128 | return $this->junctions[$interface] |
129 | 129 | ?? $this->junctions[$interface] = Junction::fromInterface($this, $interface); |
130 | 130 | } |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | /** |
133 | 133 | * @return Closure |
134 | 134 | */ |
135 | - public function getLogger () { |
|
135 | + public function getLogger() { |
|
136 | 136 | return $this->logger; |
137 | 137 | } |
138 | 138 | |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | * @param string|EntityInterface $class |
143 | 143 | * @return Record |
144 | 144 | */ |
145 | - public function getRecord ($class) { |
|
145 | + public function getRecord($class) { |
|
146 | 146 | if (is_object($class)) { |
147 | 147 | $class = get_class($class); |
148 | 148 | } |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | * @param string $name |
155 | 155 | * @return null|Table |
156 | 156 | */ |
157 | - public function getTable (string $name) { |
|
157 | + public function getTable(string $name) { |
|
158 | 158 | if (!isset($this->tables[$name])) { |
159 | 159 | if ($this->isSQLite()) { |
160 | 160 | $info = $this->query("PRAGMA table_info({$this->quote($name)})")->fetchAll(); |
@@ -176,21 +176,21 @@ discard block |
||
176 | 176 | /** |
177 | 177 | * @return bool |
178 | 178 | */ |
179 | - final public function isMySQL (): bool { |
|
179 | + final public function isMySQL(): bool { |
|
180 | 180 | return $this->driver === 'mysql'; |
181 | 181 | } |
182 | 182 | |
183 | 183 | /** |
184 | 184 | * @return bool |
185 | 185 | */ |
186 | - final public function isPostgreSQL (): bool { |
|
186 | + final public function isPostgreSQL(): bool { |
|
187 | 187 | return $this->driver === 'pgsql'; |
188 | 188 | } |
189 | 189 | |
190 | 190 | /** |
191 | 191 | * @return bool |
192 | 192 | */ |
193 | - final public function isSQLite (): bool { |
|
193 | + final public function isSQLite(): bool { |
|
194 | 194 | return $this->driver === 'sqlite'; |
195 | 195 | } |
196 | 196 | |
@@ -211,7 +211,7 @@ discard block |
||
211 | 211 | * @param mixed $b |
212 | 212 | * @return Predicate |
213 | 213 | */ |
214 | - public function match ($a, $b) { |
|
214 | + public function match($a, $b) { |
|
215 | 215 | if ($b instanceof Closure) { |
216 | 216 | return $b->__invoke($a, $this); |
217 | 217 | } |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | * @param string $class Class or interface name. |
232 | 232 | * @return bool |
233 | 233 | */ |
234 | - public function offsetExists ($class): bool { |
|
234 | + public function offsetExists($class): bool { |
|
235 | 235 | return (bool)$this->offsetGet($class); |
236 | 236 | } |
237 | 237 | |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | * @param string $class Class or interface name. |
240 | 240 | * @return null|Table|Record|Junction |
241 | 241 | */ |
242 | - public function offsetGet ($class) { |
|
242 | + public function offsetGet($class) { |
|
243 | 243 | if (is_a($class, EntityInterface::class, true)) { |
244 | 244 | return $this->getRecord($class); |
245 | 245 | } |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | * @param mixed $class Class or interface name. |
256 | 256 | * @param Table|Record|Junction $access |
257 | 257 | */ |
258 | - public function offsetSet ($class, $access) { |
|
258 | + public function offsetSet($class, $access) { |
|
259 | 259 | if ($access instanceof Record) { |
260 | 260 | $this->setRecord($class, $access); |
261 | 261 | } |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | /** |
271 | 271 | * @param string $class Class or interface name. |
272 | 272 | */ |
273 | - public function offsetUnset ($class) { |
|
273 | + public function offsetUnset($class) { |
|
274 | 274 | unset($this->records[$class]); |
275 | 275 | unset($this->junctions[$class]); |
276 | 276 | } |
@@ -282,7 +282,7 @@ discard block |
||
282 | 282 | * @param array $options |
283 | 283 | * @return Statement |
284 | 284 | */ |
285 | - public function prepare ($sql, $options = []) { |
|
285 | + public function prepare($sql, $options = []) { |
|
286 | 286 | $this->logger->__invoke($sql); |
287 | 287 | /** @var Statement $statement */ |
288 | 288 | $statement = parent::prepare($sql, $options); |
@@ -298,7 +298,7 @@ discard block |
||
298 | 298 | * @param array $ctorargs Optional. |
299 | 299 | * @return Statement |
300 | 300 | */ |
301 | - public function query ($sql, $mode = PDO::ATTR_DEFAULT_FETCH_MODE, $arg3 = null, array $ctorargs = []) { |
|
301 | + public function query($sql, $mode = PDO::ATTR_DEFAULT_FETCH_MODE, $arg3 = null, array $ctorargs = []) { |
|
302 | 302 | $this->logger->__invoke($sql); |
303 | 303 | /** @var Statement $statement */ |
304 | 304 | $statement = parent::query(...func_get_args()); |
@@ -316,7 +316,7 @@ discard block |
||
316 | 316 | * @param int $type Ignored. |
317 | 317 | * @return string|ExpressionInterface |
318 | 318 | */ |
319 | - public function quote ($value, $type = self::PARAM_STR) { |
|
319 | + public function quote($value, $type = self::PARAM_STR) { |
|
320 | 320 | if ($value instanceof ExpressionInterface) { |
321 | 321 | return $value; |
322 | 322 | } |
@@ -336,7 +336,7 @@ discard block |
||
336 | 336 | * @param array $values |
337 | 337 | * @return string[] |
338 | 338 | */ |
339 | - public function quoteArray (array $values) { |
|
339 | + public function quoteArray(array $values) { |
|
340 | 340 | return array_map([$this, 'quote'], $values); |
341 | 341 | } |
342 | 342 | |
@@ -346,7 +346,7 @@ discard block |
||
346 | 346 | * @param array $values |
347 | 347 | * @return string |
348 | 348 | */ |
349 | - public function quoteList (array $values): string { |
|
349 | + public function quoteList(array $values): string { |
|
350 | 350 | return implode(',', $this->quoteArray($values)); |
351 | 351 | } |
352 | 352 | |
@@ -356,7 +356,7 @@ discard block |
||
356 | 356 | * @param EntityInterface $entity |
357 | 357 | * @return int ID |
358 | 358 | */ |
359 | - public function save (EntityInterface $entity): int { |
|
359 | + public function save(EntityInterface $entity): int { |
|
360 | 360 | return $this->getRecord($entity)->save($entity); |
361 | 361 | } |
362 | 362 | |
@@ -365,7 +365,7 @@ discard block |
||
365 | 365 | * @param Junction $junction |
366 | 366 | * @return $this |
367 | 367 | */ |
368 | - public function setJunction (string $interface, Junction $junction) { |
|
368 | + public function setJunction(string $interface, Junction $junction) { |
|
369 | 369 | $this->junctions[$interface] = $junction; |
370 | 370 | return $this; |
371 | 371 | } |
@@ -374,7 +374,7 @@ discard block |
||
374 | 374 | * @param Closure $logger |
375 | 375 | * @return $this |
376 | 376 | */ |
377 | - public function setLogger (Closure $logger) { |
|
377 | + public function setLogger(Closure $logger) { |
|
378 | 378 | $this->logger = $logger; |
379 | 379 | return $this; |
380 | 380 | } |
@@ -384,7 +384,7 @@ discard block |
||
384 | 384 | * @param Record $record |
385 | 385 | * @return $this |
386 | 386 | */ |
387 | - public function setRecord (string $class, Record $record) { |
|
387 | + public function setRecord(string $class, Record $record) { |
|
388 | 388 | $this->records[$class] = $record; |
389 | 389 | return $this; |
390 | 390 | } |