@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | * @param string $passwd |
54 | 54 | * @param array $options |
55 | 55 | */ |
56 | - public function __construct ($dsn, $username = null, $passwd = null, $options = null) { |
|
56 | + public function __construct($dsn, $username = null, $passwd = null, $options = null) { |
|
57 | 57 | parent::__construct($dsn, $username, $passwd, $options); |
58 | 58 | $this->driver = $this->getAttribute(self::ATTR_DRIVER_NAME); |
59 | 59 | $this->setAttribute(self::ATTR_DEFAULT_FETCH_MODE, self::FETCH_ASSOC); |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | * @param string $sql |
75 | 75 | * @return int |
76 | 76 | */ |
77 | - public function exec ($sql): int { |
|
77 | + public function exec($sql): int { |
|
78 | 78 | $this->logger->__invoke($sql); |
79 | 79 | return parent::exec($sql); |
80 | 80 | } |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | /** |
83 | 83 | * @return string |
84 | 84 | */ |
85 | - final public function getDriver (): string { |
|
85 | + final public function getDriver(): string { |
|
86 | 86 | return $this->driver; |
87 | 87 | } |
88 | 88 | |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | * @param string $interface |
93 | 93 | * @return Junction |
94 | 94 | */ |
95 | - public function getJunction ($interface): Junction { |
|
95 | + public function getJunction($interface): Junction { |
|
96 | 96 | if (!isset($this->junctions[$interface])) { |
97 | 97 | $this->junctions[$interface] = Junction::fromInterface($this, $interface); |
98 | 98 | } |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | /** |
103 | 103 | * @return Closure |
104 | 104 | */ |
105 | - public function getLogger (): Closure { |
|
105 | + public function getLogger(): Closure { |
|
106 | 106 | return $this->logger; |
107 | 107 | } |
108 | 108 | |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | * @param string|EntityInterface $class |
113 | 113 | * @return Record |
114 | 114 | */ |
115 | - public function getRecord ($class): Record { |
|
115 | + public function getRecord($class): Record { |
|
116 | 116 | $name = $class; |
117 | 117 | if (is_object($name)) { |
118 | 118 | $name = get_class($name); |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | * @param mixed $b |
138 | 138 | * @return string |
139 | 139 | */ |
140 | - public function match ($a, $b) { |
|
140 | + public function match($a, $b) { |
|
141 | 141 | if ($b instanceof Closure) { |
142 | 142 | if (!$a instanceof Column) { |
143 | 143 | $a = new Column($this, $a); |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | * @param array $match |
164 | 164 | * @return string[] |
165 | 165 | */ |
166 | - public function matchArray (array $match) { |
|
166 | + public function matchArray(array $match) { |
|
167 | 167 | return array_map([$this, 'match'], array_keys($match), $match); |
168 | 168 | } |
169 | 169 | |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | * @param string $access Class or interface name. |
172 | 172 | * @return bool |
173 | 173 | */ |
174 | - public function offsetExists ($access): bool { |
|
174 | + public function offsetExists($access): bool { |
|
175 | 175 | return (bool)$this->offsetGet($access); |
176 | 176 | } |
177 | 177 | |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | * @param string $access Class or interface name. |
180 | 180 | * @return null|Record|Junction |
181 | 181 | */ |
182 | - public function offsetGet ($access) { |
|
182 | + public function offsetGet($access) { |
|
183 | 183 | if (class_exists($access)) { |
184 | 184 | return $this->getRecord($access); |
185 | 185 | } |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | * @param void $value |
197 | 197 | * @throws Exception |
198 | 198 | */ |
199 | - final public function offsetSet ($access, $value): void { |
|
199 | + final public function offsetSet($access, $value): void { |
|
200 | 200 | throw new Exception('The schema is immutable.'); |
201 | 201 | } |
202 | 202 | |
@@ -206,7 +206,7 @@ discard block |
||
206 | 206 | * @param void $access |
207 | 207 | * @throws Exception |
208 | 208 | */ |
209 | - final public function offsetUnset ($access): void { |
|
209 | + final public function offsetUnset($access): void { |
|
210 | 210 | $this->offsetSet($access, null); |
211 | 211 | } |
212 | 212 | |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | * @param array $options |
218 | 218 | * @return Statement |
219 | 219 | */ |
220 | - public function prepare ($sql, $options = []): Statement { |
|
220 | + public function prepare($sql, $options = []): Statement { |
|
221 | 221 | $this->logger->__invoke($sql); |
222 | 222 | /** @var Statement $statement */ |
223 | 223 | $statement = parent::prepare($sql, $options); |
@@ -233,7 +233,7 @@ discard block |
||
233 | 233 | * @param array $ctorargs |
234 | 234 | * @return Statement |
235 | 235 | */ |
236 | - public function query ($sql, $mode = PDO::ATTR_DEFAULT_FETCH_MODE, $arg3 = null, array $ctorargs = []): Statement { |
|
236 | + public function query($sql, $mode = PDO::ATTR_DEFAULT_FETCH_MODE, $arg3 = null, array $ctorargs = []): Statement { |
|
237 | 237 | $this->logger->__invoke($sql); |
238 | 238 | /** @var Statement $statement */ |
239 | 239 | $statement = parent::query(...func_get_args()); |
@@ -252,7 +252,7 @@ discard block |
||
252 | 252 | * @param int $type Ignored. |
253 | 253 | * @return string |
254 | 254 | */ |
255 | - public function quote ($value, $type = null) { |
|
255 | + public function quote($value, $type = null) { |
|
256 | 256 | if ($value instanceof ExpressionInterface) { |
257 | 257 | return $value; |
258 | 258 | } |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | * @param array $values |
273 | 273 | * @return array |
274 | 274 | */ |
275 | - public function quoteArray (array $values): array { |
|
275 | + public function quoteArray(array $values): array { |
|
276 | 276 | return array_map([$this, 'quote'], $values); |
277 | 277 | } |
278 | 278 | |
@@ -282,7 +282,7 @@ discard block |
||
282 | 282 | * @param mixed $value |
283 | 283 | * @return array|string |
284 | 284 | */ |
285 | - public function quoteMixed ($value) { |
|
285 | + public function quoteMixed($value) { |
|
286 | 286 | if (is_array($value)) { |
287 | 287 | return $this->quoteArray($value); |
288 | 288 | } |
@@ -295,7 +295,7 @@ discard block |
||
295 | 295 | * @param EntityInterface $entity |
296 | 296 | * @return int ID |
297 | 297 | */ |
298 | - public function save (EntityInterface $entity): int { |
|
298 | + public function save(EntityInterface $entity): int { |
|
299 | 299 | return $this->getRecord($entity)->save($entity); |
300 | 300 | } |
301 | 301 | |
@@ -303,7 +303,7 @@ discard block |
||
303 | 303 | * @param Closure $logger |
304 | 304 | * @return $this |
305 | 305 | */ |
306 | - public function setLogger (Closure $logger) { |
|
306 | + public function setLogger(Closure $logger) { |
|
307 | 307 | $this->logger = $logger; |
308 | 308 | return $this; |
309 | 309 | } |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | * @param string|Select $table |
74 | 74 | * @param string[] $columns |
75 | 75 | */ |
76 | - public function __construct (DB $db, $table, array $columns) { |
|
76 | + public function __construct(DB $db, $table, array $columns) { |
|
77 | 77 | parent::__construct($db); |
78 | 78 | if ($table instanceof Select) { |
79 | 79 | $table = $table->toSubquery(); |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | /** |
98 | 98 | * Gives the clone a new alias. |
99 | 99 | */ |
100 | - public function __clone () { |
|
100 | + public function __clone() { |
|
101 | 101 | $this->alias = uniqid('_') . "__{$this->table}"; |
102 | 102 | } |
103 | 103 | |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | * @param array $args |
106 | 106 | * @return Statement |
107 | 107 | */ |
108 | - public function __invoke (array $args = []): Statement { |
|
108 | + public function __invoke(array $args = []): Statement { |
|
109 | 109 | return $this->execute($args); |
110 | 110 | } |
111 | 111 | |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | * |
115 | 115 | * @return string |
116 | 116 | */ |
117 | - final public function __toString () { |
|
117 | + final public function __toString() { |
|
118 | 118 | return $this->alias; |
119 | 119 | } |
120 | 120 | |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | * @param array $args Execution arguments. |
125 | 125 | * @return int |
126 | 126 | */ |
127 | - public function count (array $args = []): int { |
|
127 | + public function count(array $args = []): int { |
|
128 | 128 | $clone = clone $this; |
129 | 129 | $clone->_columns = 'COUNT(*)'; |
130 | 130 | return (int)$clone->execute($args)->fetchColumn(); |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | * @param array $args |
137 | 137 | * @return Statement |
138 | 138 | */ |
139 | - public function execute (array $args = []): Statement { |
|
139 | + public function execute(array $args = []): Statement { |
|
140 | 140 | if (!empty($args)) { |
141 | 141 | return $this->prepare()->__invoke($args); |
142 | 142 | } |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | * @param array $args Execution arguments. |
152 | 152 | * @return array |
153 | 153 | */ |
154 | - public function fetchAll (array $args = []): array { |
|
154 | + public function fetchAll(array $args = []): array { |
|
155 | 155 | return iterator_to_array($this->fetcher->__invoke($this->execute($args))); |
156 | 156 | } |
157 | 157 | |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | * @param array $args Execution arguments. |
165 | 165 | * @return Generator |
166 | 166 | */ |
167 | - public function fetchEach (array $args = []) { |
|
167 | + public function fetchEach(array $args = []) { |
|
168 | 168 | yield from $this->fetcher->__invoke($this->execute($args)); |
169 | 169 | } |
170 | 170 | |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | * |
176 | 176 | * @return Generator |
177 | 177 | */ |
178 | - public function getIterator () { |
|
178 | + public function getIterator() { |
|
179 | 179 | yield from $this->fetchEach(); |
180 | 180 | } |
181 | 181 | |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | * @param string $column |
186 | 186 | * @return $this |
187 | 187 | */ |
188 | - public function group (string $column) { |
|
188 | + public function group(string $column) { |
|
189 | 189 | if (!strlen($this->_group)) { |
190 | 190 | $this->_group = " GROUP BY {$column}"; |
191 | 191 | } |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | * @param string $condition |
202 | 202 | * @return $this |
203 | 203 | */ |
204 | - public function having (string $condition) { |
|
204 | + public function having(string $condition) { |
|
205 | 205 | if (!strlen($this->_having)) { |
206 | 206 | $this->_having = " HAVING {$condition}"; |
207 | 207 | } |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | * @param string $type |
220 | 220 | * @return $this |
221 | 221 | */ |
222 | - public function join ($table, string $condition, string $type = 'INNER') { |
|
222 | + public function join($table, string $condition, string $type = 'INNER') { |
|
223 | 223 | if ($table instanceof Select) { |
224 | 224 | $table = $table->toSubquery(); |
225 | 225 | } |
@@ -234,7 +234,7 @@ discard block |
||
234 | 234 | * @param int $offset |
235 | 235 | * @return $this |
236 | 236 | */ |
237 | - public function limit (int $limit, int $offset = 0) { |
|
237 | + public function limit(int $limit, int $offset = 0) { |
|
238 | 238 | if ($limit == 0) { |
239 | 239 | $this->_limit = ''; |
240 | 240 | } |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | * @param string $name Name or alias if used. |
254 | 254 | * @return bool |
255 | 255 | */ |
256 | - public function offsetExists ($name): bool { |
|
256 | + public function offsetExists($name): bool { |
|
257 | 257 | return true; |
258 | 258 | } |
259 | 259 | |
@@ -263,7 +263,7 @@ discard block |
||
263 | 263 | * @param string $name Name, or alias if used. |
264 | 264 | * @return Column |
265 | 265 | */ |
266 | - public function offsetGet ($name): Column { |
|
266 | + public function offsetGet($name): Column { |
|
267 | 267 | return new Column($this->db, $name, $this->alias); |
268 | 268 | } |
269 | 269 | |
@@ -273,7 +273,7 @@ discard block |
||
273 | 273 | * @param string $order |
274 | 274 | * @return $this |
275 | 275 | */ |
276 | - public function order (string $order) { |
|
276 | + public function order(string $order) { |
|
277 | 277 | if (strlen($order)) { |
278 | 278 | $order = " ORDER BY {$order}"; |
279 | 279 | } |
@@ -284,7 +284,7 @@ discard block |
||
284 | 284 | /** |
285 | 285 | * @return Statement |
286 | 286 | */ |
287 | - public function prepare (): Statement { |
|
287 | + public function prepare(): Statement { |
|
288 | 288 | return $this->db->prepare($this->toSql()); |
289 | 289 | } |
290 | 290 | |
@@ -292,7 +292,7 @@ discard block |
||
292 | 292 | * @param Closure $fetcher |
293 | 293 | * @return $this |
294 | 294 | */ |
295 | - public function setFetcher (Closure $fetcher) { |
|
295 | + public function setFetcher(Closure $fetcher) { |
|
296 | 296 | $this->fetcher = $fetcher; |
297 | 297 | return $this; |
298 | 298 | } |
@@ -300,7 +300,7 @@ discard block |
||
300 | 300 | /** |
301 | 301 | * @return string |
302 | 302 | */ |
303 | - public function toSql (): string { |
|
303 | + public function toSql(): string { |
|
304 | 304 | $sql = "SELECT {$this->_columns} FROM {$this->table}"; |
305 | 305 | $sql .= $this->_join; |
306 | 306 | $sql .= $this->_where; |
@@ -316,7 +316,7 @@ discard block |
||
316 | 316 | * |
317 | 317 | * @return string |
318 | 318 | */ |
319 | - public function toSubquery (): string { |
|
319 | + public function toSubquery(): string { |
|
320 | 320 | return "({$this->toSql()}) AS {$this->alias}"; |
321 | 321 | } |
322 | 322 | |
@@ -326,7 +326,7 @@ discard block |
||
326 | 326 | * @param string $condition |
327 | 327 | * @return $this |
328 | 328 | */ |
329 | - public function where (string $condition) { |
|
329 | + public function where(string $condition) { |
|
330 | 330 | if (!strlen($this->_where)) { |
331 | 331 | $this->_where = " WHERE {$condition}"; |
332 | 332 | } |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | * @param Record $record The entity's storage access. |
20 | 20 | * @param $name |
21 | 21 | */ |
22 | - public function __construct (Record $record, $name) { |
|
22 | + public function __construct(Record $record, $name) { |
|
23 | 23 | $this->record = $record; |
24 | 24 | parent::__construct($record->db, $name, ['entity', 'attribute', 'value']); |
25 | 25 | } |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | * @param int $id |
31 | 31 | * @return int |
32 | 32 | */ |
33 | - public function count (int $id): int { |
|
33 | + public function count(int $id): int { |
|
34 | 34 | $count = $this->cache(__FUNCTION__, function() { |
35 | 35 | return $this->select(['COUNT(*)'])->where('entity=?')->prepare(); |
36 | 36 | }); |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | * @param string $attribute |
45 | 45 | * @return bool |
46 | 46 | */ |
47 | - public function exists (int $id, string $attribute): bool { |
|
47 | + public function exists(int $id, string $attribute): bool { |
|
48 | 48 | $exists = $this->cache(__FUNCTION__, function() { |
49 | 49 | $select = $this->select(['COUNT(*) > 0']); |
50 | 50 | $select->where('entity = ? AND attribute = ?'); |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | * @param array $match `[attribute => value]`. If empty, selects all IDs for entities having at least one attribute. |
63 | 63 | * @return Select |
64 | 64 | */ |
65 | - public function find (array $match): Select { |
|
65 | + public function find(array $match): Select { |
|
66 | 66 | $select = $this->select([$this['entity']]); |
67 | 67 | $prior = $this; |
68 | 68 | foreach ($match as $attribute => $value) { |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | * @param int $id |
85 | 85 | * @return array `[attribute => value]` |
86 | 86 | */ |
87 | - public function load (int $id): array { |
|
87 | + public function load(int $id): array { |
|
88 | 88 | $load = $this->cache(__FUNCTION__, function() { |
89 | 89 | $select = $this->select(['attribute', 'value']); |
90 | 90 | $select->where('entity = ?'); |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | * @param int[] $ids |
101 | 101 | * @return array[] `[id => attribute => value] |
102 | 102 | */ |
103 | - public function loadAll (array $ids): array { |
|
103 | + public function loadAll(array $ids): array { |
|
104 | 104 | if (empty($ids)) { |
105 | 105 | return []; |
106 | 106 | } |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | * @param array $values `[attribute => value]` |
126 | 126 | * @return $this |
127 | 127 | */ |
128 | - public function save (int $id, array $values) { |
|
128 | + public function save(int $id, array $values) { |
|
129 | 129 | $this->delete([ |
130 | 130 | $this['entity']->isEqual($id), |
131 | 131 | $this['attribute']->isNotEqual(array_keys($values)) |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | * @param string $interface |
29 | 29 | * @return Junction |
30 | 30 | */ |
31 | - public static function fromInterface (DB $db, string $interface) { |
|
31 | + public static function fromInterface(DB $db, string $interface) { |
|
32 | 32 | try { |
33 | 33 | $ref = new ReflectionClass($interface); |
34 | 34 | } |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | * @param string $table |
52 | 52 | * @param string[] $keys Columns, keyed by class. |
53 | 53 | */ |
54 | - public function __construct (DB $db, string $table, array $keys) { |
|
54 | + public function __construct(DB $db, string $table, array $keys) { |
|
55 | 55 | parent::__construct($db, $table, $keys); |
56 | 56 | $this->keys = $keys; |
57 | 57 | } |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | * @param EntityInterface $entity |
63 | 63 | * @return int |
64 | 64 | */ |
65 | - public function count (EntityInterface $entity): int { |
|
65 | + public function count(EntityInterface $entity): int { |
|
66 | 66 | $key = $this->getKey($entity); |
67 | 67 | $count = $this->cache("count.{$key}", function() use ($key) { |
68 | 68 | return $this->select(['COUNT(*)'])->where("{$key} = ?")->prepare(); |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | * @param string $class |
80 | 80 | * @return Select |
81 | 81 | */ |
82 | - public function getCollection (EntityInterface $owner, string $class): Select { |
|
82 | + public function getCollection(EntityInterface $owner, string $class): Select { |
|
83 | 83 | $record = $this->db->getRecord($class); |
84 | 84 | $select = $record->select(); |
85 | 85 | $select->join($this, $this[$class]->isEqual($record['id'])); |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | * @param EntityInterface|string $class |
94 | 94 | * @return string |
95 | 95 | */ |
96 | - public function getKey ($class): string { |
|
96 | + public function getKey($class): string { |
|
97 | 97 | if (is_object($class)) { |
98 | 98 | $class = get_class($class); |
99 | 99 | } |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | * @param EntityInterface[] $entities |
112 | 112 | * @return int Rows affected. |
113 | 113 | */ |
114 | - public function link (array $entities): int { |
|
114 | + public function link(array $entities): int { |
|
115 | 115 | $link = $this->cache(__FUNCTION__, function() { |
116 | 116 | $slots = implode(',', SQL::slots($this->keys)); |
117 | 117 | $columns = implode(',', $this->keys); |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | * @param string $name |
134 | 134 | * @return bool |
135 | 135 | */ |
136 | - public function offsetExists ($name): bool { |
|
136 | + public function offsetExists($name): bool { |
|
137 | 137 | return isset($this->columns[$name]) or isset($this->keys[$name]); |
138 | 138 | } |
139 | 139 | |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | * @param string $name |
144 | 144 | * @return Column |
145 | 145 | */ |
146 | - public function offsetGet ($name): Column { |
|
146 | + public function offsetGet($name): Column { |
|
147 | 147 | return $this->columns[$name] ?? $this->columns[$this->keys[$name]]; |
148 | 148 | } |
149 | 149 | |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | * @param EntityInterface[] $entities |
157 | 157 | * @return int Rows affected. |
158 | 158 | */ |
159 | - public function unlink (array $entities): int { |
|
159 | + public function unlink(array $entities): int { |
|
160 | 160 | $unlink = $this->cache(__FUNCTION__, function() { |
161 | 161 | $slots = Predicate::all(SQL::slotsEqual($this->keys)); |
162 | 162 | return $this->db->prepare("DELETE FROM {$this} WHERE {$slots}"); |
@@ -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(); |
@@ -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 string[] $eav Table names, 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 { |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | * @param Statement $statement |
126 | 126 | * @return EntityInterface[] Enumerated |
127 | 127 | */ |
128 | - public function fetchAll (Statement $statement): array { |
|
128 | + public function fetchAll(Statement $statement): array { |
|
129 | 129 | return iterator_to_array($this->fetchEach($statement)); |
130 | 130 | } |
131 | 131 | |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | * @param Statement $statement |
137 | 137 | * @return Generator |
138 | 138 | */ |
139 | - public function fetchEach (Statement $statement) { |
|
139 | + public function fetchEach(Statement $statement) { |
|
140 | 140 | do { |
141 | 141 | $entities = []; |
142 | 142 | for ($i = 0; $i < 256 and false !== $row = $statement->fetch(); $i++) { |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | * @param array[] $eavMatch Additional `[eav property => attribute => mixed]` |
160 | 160 | * @return Select |
161 | 161 | */ |
162 | - public function find (array $match, array $eavMatch = []): Select { |
|
162 | + public function find(array $match, array $eavMatch = []): Select { |
|
163 | 163 | $select = $this->select(); |
164 | 164 | foreach ($match as $column => $value) { |
165 | 165 | $select->where($this->db->match($column, $value)); |
@@ -175,14 +175,14 @@ discard block |
||
175 | 175 | * @param string $property |
176 | 176 | * @return EAV |
177 | 177 | */ |
178 | - final public function getEav (string $property): EAV { |
|
178 | + final public function getEav(string $property): EAV { |
|
179 | 179 | return $this->eav[$property]; |
180 | 180 | } |
181 | 181 | |
182 | 182 | /** |
183 | 183 | * @return EntityInterface |
184 | 184 | */ |
185 | - public function getProto (): EntityInterface { |
|
185 | + public function getProto(): EntityInterface { |
|
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): ?EntityInterface { |
|
207 | + public function load(int $id): ?EntityInterface { |
|
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 = []): Select { |
|
304 | + public function select(array $columns = []): Select { |
|
305 | 305 | return parent::select($columns)->setFetcher(function(Statement $statement) { |
306 | 306 | yield from $this->fetchEach($statement); |
307 | 307 | }); |
@@ -311,7 +311,7 @@ discard block |
||
311 | 311 | * @param EntityInterface $proto |
312 | 312 | * @return $this |
313 | 313 | */ |
314 | - public function setProto (EntityInterface $proto) { |
|
314 | + public function setProto(EntityInterface $proto) { |
|
315 | 315 | $this->proto = $proto; |
316 | 316 | return $this; |
317 | 317 | } |
@@ -320,7 +320,7 @@ discard block |
||
320 | 320 | * @param EntityInterface $entity |
321 | 321 | * @param array $values |
322 | 322 | */ |
323 | - protected function setValues (EntityInterface $entity, array $values): void { |
|
323 | + protected function setValues(EntityInterface $entity, array $values): void { |
|
324 | 324 | foreach ($values as $name => $value) { |
325 | 325 | settype($value, $this->types[$name]); |
326 | 326 | $this->properties[$name]->setValue($entity, $value); |
@@ -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, $match)) { |
|
75 | + } elseif (preg_match('/@eav\s+(?<table>\S+)/', $doc, $match)) { |
|
78 | 76 | $eav[$name] = $match['table']; |
79 | 77 | } |
80 | 78 | } |
@@ -113,8 +111,7 @@ discard block |
||
113 | 111 | $this->properties[$name] = $rProp; |
114 | 112 | $this->eav[$name] = new EAV($this, $table); |
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); |