@@ -10,5 +10,5 @@ |
||
10 | 10 | /** |
11 | 11 | * @return int |
12 | 12 | */ |
13 | - public function getId (); |
|
13 | + public function getId(); |
|
14 | 14 | } |
15 | 15 | \ No newline at end of file |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | * |
22 | 22 | * @param DB $db |
23 | 23 | */ |
24 | - protected function __construct (DB $db) { |
|
24 | + protected function __construct(DB $db) { |
|
25 | 25 | $this->db = $db; |
26 | 26 | } |
27 | 27 | |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | * @param array $args |
32 | 32 | * @return $this |
33 | 33 | */ |
34 | - public function __invoke (array $args = null) { |
|
34 | + public function __invoke(array $args = null) { |
|
35 | 35 | $this->execute($args); |
36 | 36 | return $this; |
37 | 37 | } |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | * |
42 | 42 | * @return string |
43 | 43 | */ |
44 | - public function __toString () { |
|
44 | + public function __toString() { |
|
45 | 45 | return $this->queryString; |
46 | 46 | } |
47 | 47 | |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | * @return bool |
55 | 55 | * @throws ArgumentCountError |
56 | 56 | */ |
57 | - public function execute ($args = null) { |
|
57 | + public function execute($args = null) { |
|
58 | 58 | $this->db->getLogger()->__invoke($this->queryString); |
59 | 59 | if ($result = !parent::execute($args)) { |
60 | 60 | $info = $this->errorInfo(); |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | * |
72 | 72 | * @return int |
73 | 73 | */ |
74 | - public function getId (): int { |
|
74 | + public function getId(): int { |
|
75 | 75 | return (int)$this->db->lastInsertId(); |
76 | 76 | } |
77 | 77 | } |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | * @param int|array|Countable $count |
20 | 20 | * @return ExpressionInterface[] |
21 | 21 | */ |
22 | - public static function marks ($count): array { |
|
22 | + public static function marks($count): array { |
|
23 | 23 | if (is_array($count) or $count instanceof Countable) { |
24 | 24 | $count = count($count); |
25 | 25 | } |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | * @param string[] $columns |
35 | 35 | * @return string[] `["column" => ":column"]` |
36 | 36 | */ |
37 | - public static function slots (array $columns): array { |
|
37 | + public static function slots(array $columns): array { |
|
38 | 38 | $slots = []; |
39 | 39 | foreach ($columns as $column) { |
40 | 40 | $slots[(string)$column] = ':' . str_replace('.', '__', $column); |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | * @param string[] $columns |
47 | 47 | * @return string[] `["column" => "column=:column"]` |
48 | 48 | */ |
49 | - public static function slotsEqual (array $columns): array { |
|
49 | + public static function slotsEqual(array $columns): array { |
|
50 | 50 | $slots = static::slots($columns); |
51 | 51 | foreach ($slots as $column => $slot) { |
52 | 52 | $slots[$column] = "{$column} = {$slot}"; |
@@ -54,5 +54,5 @@ discard block |
||
54 | 54 | return $slots; |
55 | 55 | } |
56 | 56 | |
57 | - final private function __construct () { } |
|
57 | + final private function __construct() { } |
|
58 | 58 | } |
59 | 59 | \ No newline at end of file |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | * @param string $name |
39 | 39 | * @param string $qualifier |
40 | 40 | */ |
41 | - public function __construct (DB $db, string $name, string $qualifier = '') { |
|
41 | + public function __construct(DB $db, string $name, string $qualifier = '') { |
|
42 | 42 | $this->db = $db; |
43 | 43 | $this->name = $name; |
44 | 44 | $this->qualifier = $qualifier; |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | * |
50 | 50 | * @return string |
51 | 51 | */ |
52 | - public function __toString (): string { |
|
52 | + public function __toString(): string { |
|
53 | 53 | if (strlen($this->qualifier)) { |
54 | 54 | return "{$this->qualifier}.{$this->name}"; |
55 | 55 | } |
@@ -59,14 +59,14 @@ discard block |
||
59 | 59 | /** |
60 | 60 | * @return string |
61 | 61 | */ |
62 | - final public function getName (): string { |
|
62 | + final public function getName(): string { |
|
63 | 63 | return $this->name; |
64 | 64 | } |
65 | 65 | |
66 | 66 | /** |
67 | 67 | * @return string |
68 | 68 | */ |
69 | - final public function getQualifier (): string { |
|
69 | + final public function getQualifier(): string { |
|
70 | 70 | return $this->qualifier; |
71 | 71 | } |
72 | 72 | |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | * @param string $name |
75 | 75 | * @return $this |
76 | 76 | */ |
77 | - public function setName (string $name) { |
|
77 | + public function setName(string $name) { |
|
78 | 78 | $clone = clone $this; |
79 | 79 | $clone->name = $name; |
80 | 80 | return $clone; |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | * @param string $qualifier |
85 | 85 | * @return $this |
86 | 86 | */ |
87 | - public function setQualifier (string $qualifier) { |
|
87 | + public function setQualifier(string $qualifier) { |
|
88 | 88 | $clone = clone $this; |
89 | 89 | $clone->qualifier = $qualifier; |
90 | 90 | return $clone; |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | * |
13 | 13 | * @return Predicate |
14 | 14 | */ |
15 | - public function isFalse () { |
|
15 | + public function isFalse() { |
|
16 | 16 | return new Predicate("{$this} IS FALSE"); |
17 | 17 | } |
18 | 18 | |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | * |
22 | 22 | * @return Predicate |
23 | 23 | */ |
24 | - public function isNotNull () { |
|
24 | + public function isNotNull() { |
|
25 | 25 | return new Predicate("{$this} IS NOT NULL"); |
26 | 26 | } |
27 | 27 | |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | * |
31 | 31 | * @return Predicate |
32 | 32 | */ |
33 | - public function isNull () { |
|
33 | + public function isNull() { |
|
34 | 34 | return new Predicate("{$this} IS NULL"); |
35 | 35 | } |
36 | 36 | } |
37 | 37 | \ No newline at end of file |
@@ -15,14 +15,14 @@ |
||
15 | 15 | /** |
16 | 16 | * @param string $expression |
17 | 17 | */ |
18 | - public function __construct (string $expression) { |
|
18 | + public function __construct(string $expression) { |
|
19 | 19 | $this->expression = $expression; |
20 | 20 | } |
21 | 21 | |
22 | 22 | /** |
23 | 23 | * @return string |
24 | 24 | */ |
25 | - public function __toString () { |
|
25 | + public function __toString() { |
|
26 | 26 | return $this->expression; |
27 | 27 | } |
28 | 28 | } |
29 | 29 | \ No newline at end of file |
@@ -31,8 +31,7 @@ |
||
31 | 31 | public static function fromInterface (DB $db, string $interface) { |
32 | 32 | try { |
33 | 33 | $ref = new ReflectionClass($interface); |
34 | - } |
|
35 | - catch (ReflectionException $exception) { |
|
34 | + } catch (ReflectionException $exception) { |
|
36 | 35 | throw new LogicException('Unexpected ReflectionException', 0, $exception); |
37 | 36 | } |
38 | 37 | $doc = $ref->getDocComment(); |
@@ -29,7 +29,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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))); |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | * @param DB $db |
15 | 15 | * @param $name |
16 | 16 | */ |
17 | - public function __construct (DB $db, $name) { |
|
17 | + public function __construct(DB $db, $name) { |
|
18 | 18 | parent::__construct($db, $name, ['entity', 'attribute', 'value']); |
19 | 19 | } |
20 | 20 | |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | * @param string $attribute |
26 | 26 | * @return bool |
27 | 27 | */ |
28 | - public function exists (int $id, string $attribute): bool { |
|
28 | + public function exists(int $id, string $attribute): bool { |
|
29 | 29 | $exists = $this->cache(__FUNCTION__, function() { |
30 | 30 | $select = $this->select(['COUNT(*) > 0']); |
31 | 31 | $select->where('entity = ? AND attribute = ?'); |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | * @param array $match `[attribute => value]`. If empty, selects all IDs for entities having at least one attribute. |
44 | 44 | * @return Select |
45 | 45 | */ |
46 | - public function find (array $match) { |
|
46 | + public function find(array $match) { |
|
47 | 47 | $select = $this->select([$this['entity']]); |
48 | 48 | $prior = $this; |
49 | 49 | foreach ($match as $attribute => $value) { |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | * @param int $id |
66 | 66 | * @return array `[attribute => value]` |
67 | 67 | */ |
68 | - public function load (int $id): array { |
|
68 | + public function load(int $id): array { |
|
69 | 69 | $load = $this->cache(__FUNCTION__, function() { |
70 | 70 | $select = $this->select(['attribute', 'value']); |
71 | 71 | $select->where('entity = ?'); |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | * @param int[] $ids |
82 | 82 | * @return array[] `[id => attribute => value] |
83 | 83 | */ |
84 | - public function loadAll (array $ids): array { |
|
84 | + public function loadAll(array $ids): array { |
|
85 | 85 | if (empty($ids)) { |
86 | 86 | return []; |
87 | 87 | } |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | * @param array $values `[attribute => value]` |
107 | 107 | * @return $this |
108 | 108 | */ |
109 | - public function save (int $id, array $values) { |
|
109 | + public function save(int $id, array $values) { |
|
110 | 110 | $this->delete([ |
111 | 111 | $this['entity']->isEqual($id), |
112 | 112 | $this['attribute']->isNotEqual(array_keys($values)) |
@@ -62,8 +62,7 @@ discard block |
||
62 | 62 | public static function fromClass (DB $db, $class) { |
63 | 63 | try { |
64 | 64 | $rClass = new ReflectionClass($class); |
65 | - } |
|
66 | - catch (ReflectionException $exception) { |
|
65 | + } catch (ReflectionException $exception) { |
|
67 | 66 | throw new LogicException('Unexpected ReflectionException', 0, $exception); |
68 | 67 | } |
69 | 68 | $columns = []; |
@@ -73,8 +72,7 @@ discard block |
||
73 | 72 | $name = $rProp->getName(); |
74 | 73 | if (preg_match('/@col(umn)?[\s$]/', $doc)) { |
75 | 74 | $columns[] = $name; |
76 | - } |
|
77 | - elseif (preg_match('/@eav\s+(?<table>\S+)/', $doc, $attr)) { |
|
75 | + } elseif (preg_match('/@eav\s+(?<table>\S+)/', $doc, $attr)) { |
|
78 | 76 | $eav[$name] = new EAV($db, $attr['table']); |
79 | 77 | } |
80 | 78 | } |
@@ -113,8 +111,7 @@ discard block |
||
113 | 111 | $rProp->setAccessible(true); |
114 | 112 | $this->properties[$name] = $rProp; |
115 | 113 | } |
116 | - } |
|
117 | - catch (ReflectionException $exception) { |
|
114 | + } catch (ReflectionException $exception) { |
|
118 | 115 | throw new LogicException('Unexpected ReflectionException', 0, $exception); |
119 | 116 | } |
120 | 117 | } |
@@ -242,8 +239,7 @@ discard block |
||
242 | 239 | public function save (EntityInterface $entity): int { |
243 | 240 | if (!$entity->getId()) { |
244 | 241 | $this->saveInsert($entity); |
245 | - } |
|
246 | - else { |
|
242 | + } else { |
|
247 | 243 | $this->saveUpdate($entity); |
248 | 244 | } |
249 | 245 | $this->saveEav($entity); |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | * @param string|EntityInterface $class |
60 | 60 | * @return Record |
61 | 61 | */ |
62 | - public static function fromClass (DB $db, $class) { |
|
62 | + public static function fromClass(DB $db, $class) { |
|
63 | 63 | try { |
64 | 64 | $rClass = new ReflectionClass($class); |
65 | 65 | } |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | * @param string[] $columns Property names. |
93 | 93 | * @param EAV[] $eav Keyed by property name. |
94 | 94 | */ |
95 | - public function __construct (DB $db, EntityInterface $proto, string $table, array $columns, array $eav = []) { |
|
95 | + public function __construct(DB $db, EntityInterface $proto, string $table, array $columns, array $eav = []) { |
|
96 | 96 | parent::__construct($db, $table, $columns); |
97 | 97 | $this->proto = $proto; |
98 | 98 | try { |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | * @param array[] $eavMatch `[eav property => attribute => mixed]` |
129 | 129 | * @return Select |
130 | 130 | */ |
131 | - public function find (array $match, array $eavMatch = []) { |
|
131 | + public function find(array $match, array $eavMatch = []) { |
|
132 | 132 | $select = $this->select(); |
133 | 133 | foreach ($match as $a => $b) { |
134 | 134 | $select->where($this->db->match($this[$a] ?? $a, $b)); |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | * @param Statement $statement |
147 | 147 | * @return EntityInterface[] Enumerated |
148 | 148 | */ |
149 | - public function getAll (Statement $statement): array { |
|
149 | + public function getAll(Statement $statement): array { |
|
150 | 150 | return iterator_to_array($this->getEach($statement)); |
151 | 151 | } |
152 | 152 | |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | * @param Statement $statement |
158 | 158 | * @return Generator |
159 | 159 | */ |
160 | - public function getEach (Statement $statement) { |
|
160 | + public function getEach(Statement $statement) { |
|
161 | 161 | do { |
162 | 162 | $entities = []; |
163 | 163 | for ($i = 0; $i < 256 and false !== $row = $statement->fetch(); $i++) { |
@@ -175,14 +175,14 @@ discard block |
||
175 | 175 | * @param string $property |
176 | 176 | * @return EAV |
177 | 177 | */ |
178 | - final public function getEav (string $property) { |
|
178 | + final public function getEav(string $property) { |
|
179 | 179 | return $this->eav[$property]; |
180 | 180 | } |
181 | 181 | |
182 | 182 | /** |
183 | 183 | * @return EntityInterface |
184 | 184 | */ |
185 | - public function getProto () { |
|
185 | + public function getProto() { |
|
186 | 186 | return $this->proto; |
187 | 187 | } |
188 | 188 | |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | * @param EntityInterface $entity |
191 | 191 | * @return array |
192 | 192 | */ |
193 | - protected function getValues (EntityInterface $entity): array { |
|
193 | + protected function getValues(EntityInterface $entity): array { |
|
194 | 194 | $values = []; |
195 | 195 | foreach (array_keys($this->columns) as $name) { |
196 | 196 | $values[$name] = $this->properties[$name]->getValue($entity); |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | * @param int $id |
205 | 205 | * @return null|EntityInterface |
206 | 206 | */ |
207 | - public function load (int $id) { |
|
207 | + public function load(int $id) { |
|
208 | 208 | $load = $this->cache(__FUNCTION__, function() { |
209 | 209 | return $this->select(array_keys($this->columns))->where('id = ?')->prepare(); |
210 | 210 | }); |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | * |
223 | 223 | * @param EntityInterface[] $entities |
224 | 224 | */ |
225 | - protected function loadEav (array $entities): void { |
|
225 | + protected function loadEav(array $entities): void { |
|
226 | 226 | $ids = array_keys($entities); |
227 | 227 | foreach ($this->eav as $name => $eav) { |
228 | 228 | foreach ($eav->loadAll($ids) as $id => $values) { |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | * @param EntityInterface $entity |
240 | 240 | * @return int ID |
241 | 241 | */ |
242 | - public function save (EntityInterface $entity): int { |
|
242 | + public function save(EntityInterface $entity): int { |
|
243 | 243 | if (!$entity->getId()) { |
244 | 244 | $this->saveInsert($entity); |
245 | 245 | } |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | /** |
254 | 254 | * @param EntityInterface $entity |
255 | 255 | */ |
256 | - protected function saveEav (EntityInterface $entity): void { |
|
256 | + protected function saveEav(EntityInterface $entity): void { |
|
257 | 257 | $id = $entity->getId(); |
258 | 258 | foreach ($this->eav as $name => $eav) { |
259 | 259 | $values = $this->properties[$name]->getValue($entity); |
@@ -268,7 +268,7 @@ discard block |
||
268 | 268 | * |
269 | 269 | * @param EntityInterface $entity |
270 | 270 | */ |
271 | - protected function saveInsert (EntityInterface $entity): void { |
|
271 | + protected function saveInsert(EntityInterface $entity): void { |
|
272 | 272 | $insert = $this->cache(__FUNCTION__, function() { |
273 | 273 | $slots = SQL::slots(array_keys($this->columns)); |
274 | 274 | unset($slots['id']); |
@@ -286,7 +286,7 @@ discard block |
||
286 | 286 | * |
287 | 287 | * @param EntityInterface $entity |
288 | 288 | */ |
289 | - protected function saveUpdate (EntityInterface $entity): void { |
|
289 | + protected function saveUpdate(EntityInterface $entity): void { |
|
290 | 290 | $this->cache(__FUNCTION__, function() { |
291 | 291 | $slots = SQL::slotsEqual(array_keys($this->columns)); |
292 | 292 | unset($slots['id']); |
@@ -301,7 +301,7 @@ discard block |
||
301 | 301 | * @param array $columns Defaults to all columns. |
302 | 302 | * @return Select |
303 | 303 | */ |
304 | - public function select (array $columns = []) { |
|
304 | + public function select(array $columns = []) { |
|
305 | 305 | $select = parent::select($columns); |
306 | 306 | if (empty($columns)) { |
307 | 307 | $select->setFetcher(function(Statement $statement) { |
@@ -315,7 +315,7 @@ discard block |
||
315 | 315 | * @param EntityInterface $proto |
316 | 316 | * @return $this |
317 | 317 | */ |
318 | - public function setProto (EntityInterface $proto) { |
|
318 | + public function setProto(EntityInterface $proto) { |
|
319 | 319 | $this->proto = $proto; |
320 | 320 | return $this; |
321 | 321 | } |
@@ -324,7 +324,7 @@ discard block |
||
324 | 324 | * @param EntityInterface $entity |
325 | 325 | * @param array $values |
326 | 326 | */ |
327 | - protected function setValues (EntityInterface $entity, array $values): void { |
|
327 | + protected function setValues(EntityInterface $entity, array $values): void { |
|
328 | 328 | foreach ($values as $name => $value) { |
329 | 329 | settype($value, $this->types[$name]); |
330 | 330 | $this->properties[$name]->setValue($entity, $value); |