@@ -12,7 +12,7 @@ |
||
12 | 12 | * |
13 | 13 | * @return static |
14 | 14 | */ |
15 | - public function not () { |
|
15 | + public function not() { |
|
16 | 16 | return static::factory($this->db, "NOT({$this})"); |
17 | 17 | } |
18 | 18 |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | * @param DB $db |
29 | 29 | * @param string $expression |
30 | 30 | */ |
31 | - public function __construct (DB $db, string $expression) { |
|
31 | + public function __construct(DB $db, string $expression) { |
|
32 | 32 | $this->db = $db; |
33 | 33 | $this->expression = $expression; |
34 | 34 | } |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | /** |
37 | 37 | * @return string |
38 | 38 | */ |
39 | - public function __toString () { |
|
39 | + public function __toString() { |
|
40 | 40 | return $this->expression; |
41 | 41 | } |
42 | 42 | } |
43 | 43 | \ No newline at end of file |
@@ -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]); |
@@ -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 | $statement = $this->cache(__FUNCTION__, function() { |
31 | 31 | return $this->select(['COUNT(*) > 0'])->where('entity = ? AND attribute = ?')->prepare(); |
32 | 32 | }); |
@@ -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 | $statement = $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)) |
@@ -157,8 +157,7 @@ |
||
157 | 157 | if ($this->isSQLite()) { |
158 | 158 | $info = $this->query("PRAGMA table_info({$this->quote($name)})")->fetchAll(); |
159 | 159 | $cols = array_column($info, 'name'); |
160 | - } |
|
161 | - else { |
|
160 | + } else { |
|
162 | 161 | $cols = $this->query( |
163 | 162 | "SELECT column_name FROM information_schema.tables WHERE table_name = {$this->quote($name)}" |
164 | 163 | )->fetchAll(self::FETCH_COLUMN); |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | * @param string $password |
63 | 63 | * @param array $options |
64 | 64 | */ |
65 | - public function __construct ($dsn, $username = null, $password = null, array $options = []) { |
|
65 | + public function __construct($dsn, $username = null, $password = null, array $options = []) { |
|
66 | 66 | $options += [ |
67 | 67 | self::ATTR_STATEMENT_CLASS => [Statement::class, [$this]] |
68 | 68 | ]; |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | |
77 | 77 | if ($this->isSQLite()) { |
78 | 78 | // polyfill sqlite functions |
79 | - $this->sqliteCreateFunctions([ // deterministic functions |
|
79 | + $this->sqliteCreateFunctions([// deterministic functions |
|
80 | 80 | // https://www.sqlite.org/lang_mathfunc.html |
81 | 81 | 'ACOS' => 'acos', |
82 | 82 | 'ASIN' => 'asin', |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | 'SIGN' => fn($x) => ($x > 0) - ($x < 0), |
103 | 103 | ]); |
104 | 104 | |
105 | - $this->sqliteCreateFunctions([ // non-deterministic |
|
105 | + $this->sqliteCreateFunctions([// non-deterministic |
|
106 | 106 | 'RAND' => fn() => mt_rand(0, 1), |
107 | 107 | ], false); |
108 | 108 | } |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | * |
114 | 114 | * @return string |
115 | 115 | */ |
116 | - final public function __toString () { |
|
116 | + final public function __toString() { |
|
117 | 117 | return $this->driver; |
118 | 118 | } |
119 | 119 | |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | * @param string $sql |
124 | 124 | * @return int |
125 | 125 | */ |
126 | - public function exec ($sql): int { |
|
126 | + public function exec($sql): int { |
|
127 | 127 | $this->logger->__invoke($sql); |
128 | 128 | return parent::exec($sql); |
129 | 129 | } |
@@ -139,14 +139,14 @@ discard block |
||
139 | 139 | * @param mixed ...$args |
140 | 140 | * @return mixed |
141 | 141 | */ |
142 | - public function factory (string $class, ...$args) { |
|
142 | + public function factory(string $class, ...$args) { |
|
143 | 143 | return new $class($this, ...$args); |
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
147 | 147 | * @return string |
148 | 148 | */ |
149 | - final public function getDriver (): string { |
|
149 | + final public function getDriver(): string { |
|
150 | 150 | return $this->driver; |
151 | 151 | } |
152 | 152 | |
@@ -156,14 +156,14 @@ discard block |
||
156 | 156 | * @param string $interface |
157 | 157 | * @return Junction |
158 | 158 | */ |
159 | - public function getJunction ($interface) { |
|
159 | + public function getJunction($interface) { |
|
160 | 160 | return $this->junctions[$interface] ??= Junction::fromInterface($this, $interface); |
161 | 161 | } |
162 | 162 | |
163 | 163 | /** |
164 | 164 | * @return Closure |
165 | 165 | */ |
166 | - public function getLogger () { |
|
166 | + public function getLogger() { |
|
167 | 167 | return $this->logger; |
168 | 168 | } |
169 | 169 | |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | * @param string|EntityInterface $class |
174 | 174 | * @return Record |
175 | 175 | */ |
176 | - public function getRecord ($class) { |
|
176 | + public function getRecord($class) { |
|
177 | 177 | if (is_object($class)) { |
178 | 178 | $class = get_class($class); |
179 | 179 | } |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | * @param string $name |
185 | 185 | * @return null|Table |
186 | 186 | */ |
187 | - public function getTable (string $name) { |
|
187 | + public function getTable(string $name) { |
|
188 | 188 | if (!isset($this->tables[$name])) { |
189 | 189 | if ($this->isSQLite()) { |
190 | 190 | $info = $this->query("PRAGMA table_info({$this->quote($name)})")->fetchAll(); |
@@ -206,21 +206,21 @@ discard block |
||
206 | 206 | /** |
207 | 207 | * @return bool |
208 | 208 | */ |
209 | - final public function isMySQL (): bool { |
|
209 | + final public function isMySQL(): bool { |
|
210 | 210 | return $this->driver === 'mysql'; |
211 | 211 | } |
212 | 212 | |
213 | 213 | /** |
214 | 214 | * @return bool |
215 | 215 | */ |
216 | - final public function isPostgreSQL (): bool { |
|
216 | + final public function isPostgreSQL(): bool { |
|
217 | 217 | return $this->driver === 'pgsql'; |
218 | 218 | } |
219 | 219 | |
220 | 220 | /** |
221 | 221 | * @return bool |
222 | 222 | */ |
223 | - final public function isSQLite (): bool { |
|
223 | + final public function isSQLite(): bool { |
|
224 | 224 | return $this->driver === 'sqlite'; |
225 | 225 | } |
226 | 226 | |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | * @param mixed $b |
242 | 242 | * @return Predicate |
243 | 243 | */ |
244 | - public function match ($a, $b) { |
|
244 | + public function match($a, $b) { |
|
245 | 245 | if ($b instanceof Closure) { |
246 | 246 | return $b->__invoke($a, $this); |
247 | 247 | } |
@@ -263,7 +263,7 @@ discard block |
||
263 | 263 | * @param string $table |
264 | 264 | * @return bool |
265 | 265 | */ |
266 | - final public function offsetExists ($table): bool { |
|
266 | + final public function offsetExists($table): bool { |
|
267 | 267 | return (bool)$this->getTable($table); |
268 | 268 | } |
269 | 269 | |
@@ -273,7 +273,7 @@ discard block |
||
273 | 273 | * @param string $table |
274 | 274 | * @return null|Table |
275 | 275 | */ |
276 | - final public function offsetGet ($table) { |
|
276 | + final public function offsetGet($table) { |
|
277 | 277 | return $this->getTable($table); |
278 | 278 | } |
279 | 279 | |
@@ -282,7 +282,7 @@ discard block |
||
282 | 282 | * @param $value |
283 | 283 | * @throws LogicException |
284 | 284 | */ |
285 | - final public function offsetSet ($offset, $value) { |
|
285 | + final public function offsetSet($offset, $value) { |
|
286 | 286 | throw new LogicException('Raw table access is immutable.'); |
287 | 287 | } |
288 | 288 | |
@@ -290,7 +290,7 @@ discard block |
||
290 | 290 | * @param $offset |
291 | 291 | * @throws LogicException |
292 | 292 | */ |
293 | - final public function offsetUnset ($offset) { |
|
293 | + final public function offsetUnset($offset) { |
|
294 | 294 | throw new LogicException('Raw table access is immutable.'); |
295 | 295 | } |
296 | 296 | |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | * |
300 | 300 | * @return Num |
301 | 301 | */ |
302 | - public function pi () { |
|
302 | + public function pi() { |
|
303 | 303 | return Num::factory($this, "PI()"); |
304 | 304 | } |
305 | 305 | |
@@ -310,7 +310,7 @@ discard block |
||
310 | 310 | * @param array $options |
311 | 311 | * @return Statement |
312 | 312 | */ |
313 | - public function prepare ($sql, $options = []) { |
|
313 | + public function prepare($sql, $options = []) { |
|
314 | 314 | $this->logger->__invoke($sql); |
315 | 315 | /** @var Statement $statement */ |
316 | 316 | $statement = parent::prepare($sql, $options); |
@@ -326,7 +326,7 @@ discard block |
||
326 | 326 | * @param array $ctorargs Optional. |
327 | 327 | * @return Statement |
328 | 328 | */ |
329 | - public function query ($sql, $mode = PDO::ATTR_DEFAULT_FETCH_MODE, $arg3 = null, array $ctorargs = []) { |
|
329 | + public function query($sql, $mode = PDO::ATTR_DEFAULT_FETCH_MODE, $arg3 = null, array $ctorargs = []) { |
|
330 | 330 | $this->logger->__invoke($sql); |
331 | 331 | /** @var Statement $statement */ |
332 | 332 | $statement = parent::query(...func_get_args()); |
@@ -344,7 +344,7 @@ discard block |
||
344 | 344 | * @param int $type Ignored. |
345 | 345 | * @return string|ExpressionInterface |
346 | 346 | */ |
347 | - public function quote ($value, $type = self::PARAM_STR) { |
|
347 | + public function quote($value, $type = self::PARAM_STR) { |
|
348 | 348 | if ($value instanceof ExpressionInterface) { |
349 | 349 | return $value; |
350 | 350 | } |
@@ -364,7 +364,7 @@ discard block |
||
364 | 364 | * @param array $values |
365 | 365 | * @return string[] |
366 | 366 | */ |
367 | - public function quoteArray (array $values) { |
|
367 | + public function quoteArray(array $values) { |
|
368 | 368 | return array_map([$this, 'quote'], $values); |
369 | 369 | } |
370 | 370 | |
@@ -374,7 +374,7 @@ discard block |
||
374 | 374 | * @param array $values |
375 | 375 | * @return string |
376 | 376 | */ |
377 | - public function quoteList (array $values): string { |
|
377 | + public function quoteList(array $values): string { |
|
378 | 378 | return implode(',', $this->quoteArray($values)); |
379 | 379 | } |
380 | 380 | |
@@ -383,7 +383,7 @@ discard block |
||
383 | 383 | * |
384 | 384 | * @return Num |
385 | 385 | */ |
386 | - public function rand () { |
|
386 | + public function rand() { |
|
387 | 387 | return Num::factory($this, "RAND()"); |
388 | 388 | } |
389 | 389 | |
@@ -393,7 +393,7 @@ discard block |
||
393 | 393 | * @param EntityInterface $entity |
394 | 394 | * @return int ID |
395 | 395 | */ |
396 | - public function save (EntityInterface $entity): int { |
|
396 | + public function save(EntityInterface $entity): int { |
|
397 | 397 | return $this->getRecord($entity)->save($entity); |
398 | 398 | } |
399 | 399 | |
@@ -402,7 +402,7 @@ discard block |
||
402 | 402 | * @param Junction $junction |
403 | 403 | * @return $this |
404 | 404 | */ |
405 | - public function setJunction (string $interface, Junction $junction) { |
|
405 | + public function setJunction(string $interface, Junction $junction) { |
|
406 | 406 | $this->junctions[$interface] = $junction; |
407 | 407 | return $this; |
408 | 408 | } |
@@ -411,7 +411,7 @@ discard block |
||
411 | 411 | * @param Closure $logger |
412 | 412 | * @return $this |
413 | 413 | */ |
414 | - public function setLogger (Closure $logger) { |
|
414 | + public function setLogger(Closure $logger) { |
|
415 | 415 | $this->logger = $logger; |
416 | 416 | return $this; |
417 | 417 | } |
@@ -421,7 +421,7 @@ discard block |
||
421 | 421 | * @param Record $record |
422 | 422 | * @return $this |
423 | 423 | */ |
424 | - public function setRecord (string $class, Record $record) { |
|
424 | + public function setRecord(string $class, Record $record) { |
|
425 | 425 | $this->records[$class] = $record; |
426 | 426 | return $this; |
427 | 427 | } |
@@ -430,7 +430,7 @@ discard block |
||
430 | 430 | * @param callable[] $callbacks Keyed by function name. |
431 | 431 | * @param bool $deterministic Whether the callbacks aren't random / are without side-effects. |
432 | 432 | */ |
433 | - public function sqliteCreateFunctions (array $callbacks, bool $deterministic = true): void { |
|
433 | + public function sqliteCreateFunctions(array $callbacks, bool $deterministic = true): void { |
|
434 | 434 | $deterministic = $deterministic ? self::SQLITE_DETERMINISTIC : 0; |
435 | 435 | foreach ($callbacks as $name => $callback) { |
436 | 436 | $argc = (new ReflectionFunction($callback))->getNumberOfRequiredParameters(); |
@@ -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 | if ($this->db->isSQLite()) { |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | * @param Closure $prepare `():Statement` |
86 | 86 | * @return Statement |
87 | 87 | */ |
88 | - protected function cache (string $key, Closure $prepare) { |
|
88 | + protected function cache(string $key, Closure $prepare) { |
|
89 | 89 | return $this->_cache[$key] ??= $prepare->__invoke(); |
90 | 90 | } |
91 | 91 | |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | * @param array $match `[a => b]` |
94 | 94 | * @return int |
95 | 95 | */ |
96 | - public function count (array $match = []) { |
|
96 | + public function count(array $match = []) { |
|
97 | 97 | $select = $this->select(['COUNT(*)']); |
98 | 98 | foreach ($match as $a => $b) { |
99 | 99 | $select->where($this->db->match($this[$a] ?? $a, $b)); |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | * @param array $match |
110 | 110 | * @return int Rows affected. |
111 | 111 | */ |
112 | - public function delete (array $match): int { |
|
112 | + public function delete(array $match): int { |
|
113 | 113 | foreach ($match as $a => $b) { |
114 | 114 | $match[$a] = $this->db->match($this[$a] ?? $a, $b); |
115 | 115 | } |
@@ -120,14 +120,14 @@ discard block |
||
120 | 120 | /** |
121 | 121 | * @return Column[] |
122 | 122 | */ |
123 | - final public function getColumns (): array { |
|
123 | + final public function getColumns(): array { |
|
124 | 124 | return $this->columns; |
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
128 | 128 | * @return string |
129 | 129 | */ |
130 | - final public function getName (): string { |
|
130 | + final public function getName(): string { |
|
131 | 131 | return $this->name; |
132 | 132 | } |
133 | 133 | |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | * @param array $values |
138 | 138 | * @return Statement |
139 | 139 | */ |
140 | - public function insert (array $values) { |
|
140 | + public function insert(array $values) { |
|
141 | 141 | $columns = implode(',', array_keys($values)); |
142 | 142 | $values = $this->db->quoteList($values); |
143 | 143 | return $this->db->query("INSERT INTO {$this} ($columns) VALUES ($values)"); |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | * @param int|string $column |
148 | 148 | * @return Column |
149 | 149 | */ |
150 | - public function offsetGet ($column) { |
|
150 | + public function offsetGet($column) { |
|
151 | 151 | if (is_int($column)) { |
152 | 152 | return current(array_slice($this->columns, $column, 1)) ?: null; |
153 | 153 | } |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | * @param string[] $columns Defaults to all columns. |
161 | 161 | * @return Select|array[] |
162 | 162 | */ |
163 | - public function select (array $columns = []) { |
|
163 | + public function select(array $columns = []) { |
|
164 | 164 | if (empty($columns)) { |
165 | 165 | $columns = $this->columns; |
166 | 166 | } |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | * @param string $name |
174 | 174 | * @return Table |
175 | 175 | */ |
176 | - public function setName (string $name) { |
|
176 | + public function setName(string $name) { |
|
177 | 177 | $clone = clone $this; |
178 | 178 | $clone->name = $name; |
179 | 179 | foreach ($this->columns as $name => $column) { |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | * @param array $match |
192 | 192 | * @return int Rows affected. |
193 | 193 | */ |
194 | - public function update (array $values, array $match): int { |
|
194 | + public function update(array $values, array $match): int { |
|
195 | 195 | foreach ($this->db->quoteArray($values) as $key => $value) { |
196 | 196 | $values[$key] = "{$key} = {$value}"; |
197 | 197 | } |
@@ -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 | } |
@@ -254,8 +253,7 @@ discard block |
||
254 | 253 | public function save (EntityInterface $entity): int { |
255 | 254 | if (!$entity->getId()) { |
256 | 255 | $this->saveInsert($entity); |
257 | - } |
|
258 | - else { |
|
256 | + } else { |
|
259 | 257 | $this->saveUpdate($entity); |
260 | 258 | } |
261 | 259 | $this->saveEav($entity); |
@@ -341,8 +339,7 @@ discard block |
||
341 | 339 | if (isset($this->properties[$name])) { |
342 | 340 | settype($value, $this->types[$name]); |
343 | 341 | $this->properties[$name]->setValue($entity, $value); |
344 | - } |
|
345 | - else { |
|
342 | + } else { |
|
346 | 343 | $entity->{$name} = $value; |
347 | 344 | } |
348 | 345 | } |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | * @param string|EntityInterface $class |
67 | 67 | * @return Record |
68 | 68 | */ |
69 | - public static function fromClass (DB $db, $class) { |
|
69 | + public static function fromClass(DB $db, $class) { |
|
70 | 70 | return (function() use ($db, $class) { |
71 | 71 | $rClass = new ReflectionClass($class); |
72 | 72 | $columns = []; |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | * @param string[] $columns Property names. |
96 | 96 | * @param EAV[] $eav Keyed by property name. |
97 | 97 | */ |
98 | - public function __construct (DB $db, EntityInterface $proto, string $table, array $columns, array $eav = []) { |
|
98 | + public function __construct(DB $db, EntityInterface $proto, string $table, array $columns, array $eav = []) { |
|
99 | 99 | parent::__construct($db, $table, $columns); |
100 | 100 | $this->proto = $proto; |
101 | 101 | (function() use ($proto, $columns, $eav) { |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | * @param array[] $eavMatch `[eav property => attribute => mixed]` |
133 | 133 | * @return Select|EntityInterface[] |
134 | 134 | */ |
135 | - public function find (array $match, array $eavMatch = []) { |
|
135 | + public function find(array $match, array $eavMatch = []) { |
|
136 | 136 | $select = $this->loadAll(); |
137 | 137 | foreach ($match as $a => $b) { |
138 | 138 | $select->where($this->db->match($this[$a] ?? $a, $b)); |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | * @param Statement $statement |
151 | 151 | * @return EntityInterface[] Keyed by ID |
152 | 152 | */ |
153 | - public function getAll (Statement $statement): array { |
|
153 | + public function getAll(Statement $statement): array { |
|
154 | 154 | return iterator_to_array($this->getEach($statement)); |
155 | 155 | } |
156 | 156 | |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | * @param Statement $statement |
162 | 162 | * @return Generator|EntityInterface[] Keyed by ID |
163 | 163 | */ |
164 | - public function getEach (Statement $statement) { |
|
164 | + public function getEach(Statement $statement) { |
|
165 | 165 | do { |
166 | 166 | $entities = []; |
167 | 167 | for ($i = 0; $i < 256 and false !== $row = $statement->fetch(); $i++) { |
@@ -178,14 +178,14 @@ discard block |
||
178 | 178 | * @param string $property |
179 | 179 | * @return EAV |
180 | 180 | */ |
181 | - final public function getEav (string $property) { |
|
181 | + final public function getEav(string $property) { |
|
182 | 182 | return $this->eav[$property]; |
183 | 183 | } |
184 | 184 | |
185 | 185 | /** |
186 | 186 | * @return EntityInterface |
187 | 187 | */ |
188 | - public function getProto () { |
|
188 | + public function getProto() { |
|
189 | 189 | return $this->proto; |
190 | 190 | } |
191 | 191 | |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | * @param EntityInterface $entity |
194 | 194 | * @return array |
195 | 195 | */ |
196 | - protected function getValues (EntityInterface $entity): array { |
|
196 | + protected function getValues(EntityInterface $entity): array { |
|
197 | 197 | $values = []; |
198 | 198 | foreach (array_keys($this->columns) as $name) { |
199 | 199 | $values[$name] = $this->properties[$name]->getValue($entity); |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | * @param int $id |
208 | 208 | * @return null|EntityInterface |
209 | 209 | */ |
210 | - public function load (int $id) { |
|
210 | + public function load(int $id) { |
|
211 | 211 | $statement = $this->cache(__FUNCTION__, function() { |
212 | 212 | return $this->select(array_keys($this->columns))->where('id = ?')->prepare(); |
213 | 213 | }); |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | * |
228 | 228 | * @return Select|EntityInterface[] |
229 | 229 | */ |
230 | - public function loadAll () { |
|
230 | + public function loadAll() { |
|
231 | 231 | return $this->select()->setFetcher(function(Statement $statement) { |
232 | 232 | yield from $this->getEach($statement); |
233 | 233 | }); |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | * |
239 | 239 | * @param EntityInterface[] $entities |
240 | 240 | */ |
241 | - protected function loadEav (array $entities): void { |
|
241 | + protected function loadEav(array $entities): void { |
|
242 | 242 | $ids = array_keys($entities); |
243 | 243 | foreach ($this->eav as $name => $eav) { |
244 | 244 | foreach ($eav->loadAll($ids) as $id => $values) { |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | * @param EntityInterface $entity |
254 | 254 | * @return int ID |
255 | 255 | */ |
256 | - public function save (EntityInterface $entity): int { |
|
256 | + public function save(EntityInterface $entity): int { |
|
257 | 257 | if (!$entity->getId()) { |
258 | 258 | $this->saveInsert($entity); |
259 | 259 | } |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | /** |
268 | 268 | * @param EntityInterface $entity |
269 | 269 | */ |
270 | - protected function saveEav (EntityInterface $entity): void { |
|
270 | + protected function saveEav(EntityInterface $entity): void { |
|
271 | 271 | $id = $entity->getId(); |
272 | 272 | foreach ($this->eav as $name => $eav) { |
273 | 273 | // may be null to skip |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | * |
284 | 284 | * @param EntityInterface $entity |
285 | 285 | */ |
286 | - protected function saveInsert (EntityInterface $entity): void { |
|
286 | + protected function saveInsert(EntityInterface $entity): void { |
|
287 | 287 | $statement = $this->cache(__FUNCTION__, function() { |
288 | 288 | $slots = SQL::slots(array_keys($this->columns)); |
289 | 289 | unset($slots['id']); |
@@ -302,7 +302,7 @@ discard block |
||
302 | 302 | * |
303 | 303 | * @param EntityInterface $entity |
304 | 304 | */ |
305 | - protected function saveUpdate (EntityInterface $entity): void { |
|
305 | + protected function saveUpdate(EntityInterface $entity): void { |
|
306 | 306 | $statement = $this->cache(__FUNCTION__, function() { |
307 | 307 | $slots = SQL::slotsEqual(array_keys($this->columns)); |
308 | 308 | unset($slots['id']); |
@@ -317,7 +317,7 @@ discard block |
||
317 | 317 | * @param EntityInterface $proto |
318 | 318 | * @return $this |
319 | 319 | */ |
320 | - public function setProto (EntityInterface $proto) { |
|
320 | + public function setProto(EntityInterface $proto) { |
|
321 | 321 | $this->proto = $proto; |
322 | 322 | return $this; |
323 | 323 | } |
@@ -326,7 +326,7 @@ discard block |
||
326 | 326 | * @param EntityInterface $entity |
327 | 327 | * @param array $values |
328 | 328 | */ |
329 | - protected function setValues (EntityInterface $entity, array $values): void { |
|
329 | + protected function setValues(EntityInterface $entity, array $values): void { |
|
330 | 330 | foreach ($values as $name => $value) { |
331 | 331 | if (isset($this->properties[$name])) { |
332 | 332 | settype($value, $this->types[$name]); |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | * @param string $name |
44 | 44 | * @param string $qualifier |
45 | 45 | */ |
46 | - public function __construct (DB $db, string $name, string $qualifier = '') { |
|
46 | + public function __construct(DB $db, string $name, string $qualifier = '') { |
|
47 | 47 | $this->db = $db; |
48 | 48 | $this->name = $name; |
49 | 49 | $this->qualifier = $qualifier; |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | * |
55 | 55 | * @return string |
56 | 56 | */ |
57 | - public function __toString () { |
|
57 | + public function __toString() { |
|
58 | 58 | if (strlen($this->qualifier)) { |
59 | 59 | return "{$this->qualifier}.{$this->name}"; |
60 | 60 | } |
@@ -64,14 +64,14 @@ discard block |
||
64 | 64 | /** |
65 | 65 | * @return string |
66 | 66 | */ |
67 | - final public function getName (): string { |
|
67 | + final public function getName(): string { |
|
68 | 68 | return $this->name; |
69 | 69 | } |
70 | 70 | |
71 | 71 | /** |
72 | 72 | * @return string |
73 | 73 | */ |
74 | - final public function getQualifier (): string { |
|
74 | + final public function getQualifier(): string { |
|
75 | 75 | return $this->qualifier; |
76 | 76 | } |
77 | 77 | |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | * |
81 | 81 | * @return Select|scalar[] |
82 | 82 | */ |
83 | - public function select () { |
|
83 | + public function select() { |
|
84 | 84 | return Select::factory($this->db, $this->qualifier, [$this->name]) |
85 | 85 | ->setFetcher(function(Statement $statement) { |
86 | 86 | while (false !== $value = $statement->fetchColumn()) { |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | * @param string $name |
94 | 94 | * @return $this |
95 | 95 | */ |
96 | - public function setName (string $name) { |
|
96 | + public function setName(string $name) { |
|
97 | 97 | $clone = clone $this; |
98 | 98 | $clone->name = $name; |
99 | 99 | return $clone; |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | * @param string $qualifier |
104 | 104 | * @return $this |
105 | 105 | */ |
106 | - public function setQualifier (string $qualifier) { |
|
106 | + public function setQualifier(string $qualifier) { |
|
107 | 107 | $clone = clone $this; |
108 | 108 | $clone->qualifier = $qualifier; |
109 | 109 | return $clone; |
@@ -14,7 +14,7 @@ |
||
14 | 14 | /** |
15 | 15 | * @return string |
16 | 16 | */ |
17 | - abstract public function __toString (); |
|
17 | + abstract public function __toString(); |
|
18 | 18 | |
19 | 19 | /** |
20 | 20 | * @var DB |