@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | * @param string $passwd |
47 | 47 | * @param array $options |
48 | 48 | */ |
49 | - public function __construct ($dsn, $username = null, $passwd = null, $options = null) { |
|
49 | + public function __construct($dsn, $username = null, $passwd = null, $options = null) { |
|
50 | 50 | parent::__construct(...func_get_args()); |
51 | 51 | $this->setAttribute(self::ATTR_DEFAULT_FETCH_MODE, self::FETCH_ASSOC); |
52 | 52 | $this->setAttribute(self::ATTR_EMULATE_PREPARES, false); |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | * @param string $sql |
63 | 63 | * @return int |
64 | 64 | */ |
65 | - public function exec ($sql): int { |
|
65 | + public function exec($sql): int { |
|
66 | 66 | $this->logger->__invoke($sql); |
67 | 67 | return parent::exec($sql); |
68 | 68 | } |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | * |
73 | 73 | * @return string |
74 | 74 | */ |
75 | - final public function getDriver (): string { |
|
75 | + final public function getDriver(): string { |
|
76 | 76 | return $this->getAttribute(self::ATTR_DRIVER_NAME); |
77 | 77 | } |
78 | 78 | |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | * @param string $interface |
83 | 83 | * @return Junction |
84 | 84 | */ |
85 | - public function getJunction ($interface): Junction { |
|
85 | + public function getJunction($interface): Junction { |
|
86 | 86 | if (!isset($this->junctions[$interface])) { |
87 | 87 | $this->junctions[$interface] = new Junction($this, $interface); |
88 | 88 | } |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | /** |
93 | 93 | * @return Closure |
94 | 94 | */ |
95 | - public function getLogger (): Closure { |
|
95 | + public function getLogger(): Closure { |
|
96 | 96 | return $this->logger; |
97 | 97 | } |
98 | 98 | |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | * @param string|EntityInterface $class |
103 | 103 | * @return Record |
104 | 104 | */ |
105 | - public function getRecord ($class): Record { |
|
105 | + public function getRecord($class): Record { |
|
106 | 106 | if (is_object($class)) { |
107 | 107 | $class = get_class($class); |
108 | 108 | } |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | * @param string|array|Select|Closure $b |
135 | 135 | * @return string|string[] Same type as `$a`, keys are not preserved. |
136 | 136 | */ |
137 | - public function match ($a, $b = null) { |
|
137 | + public function match($a, $b = null) { |
|
138 | 138 | if (is_array($a)) { |
139 | 139 | return array_map([$this, __FUNCTION__], array_keys($a), $a); |
140 | 140 | } |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | * @param string $access Class or interface name. |
152 | 152 | * @return bool |
153 | 153 | */ |
154 | - public function offsetExists ($access): bool { |
|
154 | + public function offsetExists($access): bool { |
|
155 | 155 | return (bool)$this->offsetGet($access); |
156 | 156 | } |
157 | 157 | |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | * @param string $access Class or interface name. |
160 | 160 | * @return Record|Junction|null |
161 | 161 | */ |
162 | - public function offsetGet ($access) { |
|
162 | + public function offsetGet($access) { |
|
163 | 163 | if (class_exists($access)) { |
164 | 164 | return $this->getRecord($access); |
165 | 165 | } |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | * @param void $value |
177 | 177 | * @throws Exception |
178 | 178 | */ |
179 | - final public function offsetSet ($access, $value): void { |
|
179 | + final public function offsetSet($access, $value): void { |
|
180 | 180 | throw new Exception('The schema is immutable.'); |
181 | 181 | } |
182 | 182 | |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | * @param void $access |
187 | 187 | * @throws Exception |
188 | 188 | */ |
189 | - final public function offsetUnset ($access): void { |
|
189 | + final public function offsetUnset($access): void { |
|
190 | 190 | $this->offsetSet($access, null); |
191 | 191 | } |
192 | 192 | |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | * @param array $options |
198 | 198 | * @return Statement |
199 | 199 | */ |
200 | - public function prepare ($sql, $options = null): Statement { |
|
200 | + public function prepare($sql, $options = null): Statement { |
|
201 | 201 | $this->logger->__invoke($sql); |
202 | 202 | /** @var Statement $statement */ |
203 | 203 | $statement = parent::prepare(...func_get_args()); |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | * @param array $ctorargs |
214 | 214 | * @return Statement |
215 | 215 | */ |
216 | - public function query ($sql, $mode = PDO::ATTR_DEFAULT_FETCH_MODE, $arg3 = null, array $ctorargs = []): Statement { |
|
216 | + public function query($sql, $mode = PDO::ATTR_DEFAULT_FETCH_MODE, $arg3 = null, array $ctorargs = []): Statement { |
|
217 | 217 | $this->logger->__invoke($sql); |
218 | 218 | /** @var Statement $statement */ |
219 | 219 | $statement = parent::query(...func_get_args()); |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | * @param int $type Ignored. |
239 | 239 | * @return mixed |
240 | 240 | */ |
241 | - public function quote ($value, $type = null) { |
|
241 | + public function quote($value, $type = null) { |
|
242 | 242 | if ($value instanceof Column) { |
243 | 243 | return (string)$value; |
244 | 244 | } |
@@ -263,7 +263,7 @@ discard block |
||
263 | 263 | * @param EntityInterface $entity |
264 | 264 | * @return int ID |
265 | 265 | */ |
266 | - public function save (EntityInterface $entity): int { |
|
266 | + public function save(EntityInterface $entity): int { |
|
267 | 267 | return $this->getRecord($entity)->save($entity); |
268 | 268 | } |
269 | 269 | |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | * @param Closure $logger |
272 | 272 | * @return $this |
273 | 273 | */ |
274 | - public function setLogger (Closure $logger) { |
|
274 | + public function setLogger(Closure $logger) { |
|
275 | 275 | $this->logger = $logger; |
276 | 276 | return $this; |
277 | 277 | } |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | * @param string|Select $table |
75 | 75 | * @param array $columns Strings or {@link Column}. Keys are used for aliasing. |
76 | 76 | */ |
77 | - public function __construct (DB $db, $table, array $columns) { |
|
77 | + public function __construct(DB $db, $table, array $columns) { |
|
78 | 78 | parent::__construct($db); |
79 | 79 | if ($table instanceof Select) { |
80 | 80 | $table = $table->toSubquery(); |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | /** |
91 | 91 | * Gives the clone a new alias. |
92 | 92 | */ |
93 | - public function __clone () { |
|
93 | + public function __clone() { |
|
94 | 94 | $this->alias = uniqid('_') . "__{$this->table}"; |
95 | 95 | } |
96 | 96 | |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | * @param array $args |
99 | 99 | * @return Statement |
100 | 100 | */ |
101 | - public function __invoke (array $args = []): Statement { |
|
101 | + public function __invoke(array $args = []): Statement { |
|
102 | 102 | return $this->execute($args); |
103 | 103 | } |
104 | 104 | |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | * |
108 | 108 | * @return string |
109 | 109 | */ |
110 | - public function __toString (): string { |
|
110 | + public function __toString(): string { |
|
111 | 111 | return $this->alias; |
112 | 112 | } |
113 | 113 | |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | * @param array $args Execution arguments. |
118 | 118 | * @return int |
119 | 119 | */ |
120 | - public function count (array $args = []): int { |
|
120 | + public function count(array $args = []): int { |
|
121 | 121 | $clone = clone $this; |
122 | 122 | $clone->setColumns(['COUNT(*)']); |
123 | 123 | return (int)$clone->execute($args)->fetchColumn(); |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | * @param array $args |
130 | 130 | * @return Statement |
131 | 131 | */ |
132 | - public function execute (array $args = []): Statement { |
|
132 | + public function execute(array $args = []): Statement { |
|
133 | 133 | return $this->prepare()->execute($args); |
134 | 134 | } |
135 | 135 | |
@@ -141,21 +141,21 @@ discard block |
||
141 | 141 | * @param array $args Execution arguments. |
142 | 142 | * @return array |
143 | 143 | */ |
144 | - public function fetchAll (array $args = []): array { |
|
144 | + public function fetchAll(array $args = []): array { |
|
145 | 145 | return $this->fetcher->__invoke($this->execute($args)); |
146 | 146 | } |
147 | 147 | |
148 | 148 | /** |
149 | 149 | * @return string |
150 | 150 | */ |
151 | - final public function getAlias (): string { |
|
151 | + final public function getAlias(): string { |
|
152 | 152 | return $this->alias; |
153 | 153 | } |
154 | 154 | |
155 | 155 | /** |
156 | 156 | * @return Closure |
157 | 157 | */ |
158 | - public function getFetcher (): Closure { |
|
158 | + public function getFetcher(): Closure { |
|
159 | 159 | return $this->fetcher; |
160 | 160 | } |
161 | 161 | |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | * |
167 | 167 | * @return ArrayIterator |
168 | 168 | */ |
169 | - public function getIterator () { |
|
169 | + public function getIterator() { |
|
170 | 170 | return new ArrayIterator($this->fetchAll()); |
171 | 171 | } |
172 | 172 | |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | * @param string $column |
177 | 177 | * @return $this |
178 | 178 | */ |
179 | - public function group ($column) { |
|
179 | + public function group($column) { |
|
180 | 180 | $this->_group[] = $column; |
181 | 181 | return $this; |
182 | 182 | } |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | * @param string $condition |
188 | 188 | * @return $this |
189 | 189 | */ |
190 | - public function having ($condition) { |
|
190 | + public function having($condition) { |
|
191 | 191 | $this->_having[] = $condition; |
192 | 192 | return $this; |
193 | 193 | } |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | * @param string $type |
201 | 201 | * @return $this |
202 | 202 | */ |
203 | - public function join ($table, $condition, $type = 'INNER') { |
|
203 | + public function join($table, $condition, $type = 'INNER') { |
|
204 | 204 | if ($table instanceof Select) { |
205 | 205 | $table = $table->toSubquery(); |
206 | 206 | } |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | * @param int $offset |
216 | 216 | * @return $this |
217 | 217 | */ |
218 | - public function limit ($limit, $offset = 0) { |
|
218 | + public function limit($limit, $offset = 0) { |
|
219 | 219 | $this->_limit = " LIMIT {$limit}"; |
220 | 220 | if ($offset) { |
221 | 221 | $this->_limit .= " OFFSET {$offset}"; |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | * @param string $name Name or alias if used. |
230 | 230 | * @return bool |
231 | 231 | */ |
232 | - public function offsetExists ($name): bool { |
|
232 | + public function offsetExists($name): bool { |
|
233 | 233 | return isset($this->columns[$name]); |
234 | 234 | } |
235 | 235 | |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | * @param string $name Name or alias if used. |
240 | 240 | * @return Column |
241 | 241 | */ |
242 | - public function offsetGet ($name): Column { |
|
242 | + public function offsetGet($name): Column { |
|
243 | 243 | return new Column($this->db, $name, $this->alias); |
244 | 244 | } |
245 | 245 | |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | * @param string $order |
250 | 250 | * @return $this |
251 | 251 | */ |
252 | - public function order ($order) { |
|
252 | + public function order($order) { |
|
253 | 253 | $this->_order = " ORDER BY {$order}"; |
254 | 254 | return $this; |
255 | 255 | } |
@@ -257,7 +257,7 @@ discard block |
||
257 | 257 | /** |
258 | 258 | * @return Statement |
259 | 259 | */ |
260 | - public function prepare (): Statement { |
|
260 | + public function prepare(): Statement { |
|
261 | 261 | return $this->db->prepare($this->toSql()); |
262 | 262 | } |
263 | 263 | |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | * @param array $columns Strings or {@link Column}. Keys are used for aliasing. |
268 | 268 | * @return $this |
269 | 269 | */ |
270 | - public function setColumns (array $columns) { |
|
270 | + public function setColumns(array $columns) { |
|
271 | 271 | $this->columns = []; |
272 | 272 | foreach ($columns as $alias => $column) { |
273 | 273 | if ($column instanceof Column) { |
@@ -291,7 +291,7 @@ discard block |
||
291 | 291 | * @param Closure $fetcher |
292 | 292 | * @return $this |
293 | 293 | */ |
294 | - public function setFetcher (Closure $fetcher) { |
|
294 | + public function setFetcher(Closure $fetcher) { |
|
295 | 295 | $this->fetcher = $fetcher; |
296 | 296 | return $this; |
297 | 297 | } |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | /** |
300 | 300 | * @return string |
301 | 301 | */ |
302 | - public function toSql (): string { |
|
302 | + public function toSql(): string { |
|
303 | 303 | $columns = []; |
304 | 304 | foreach ($this->columns as $alias => $column) { |
305 | 305 | if ($alias !== $column) { |
@@ -335,7 +335,7 @@ discard block |
||
335 | 335 | * |
336 | 336 | * @return string |
337 | 337 | */ |
338 | - public function toSubquery (): string { |
|
338 | + public function toSubquery(): string { |
|
339 | 339 | return "({$this->toSql()}) AS {$this->getAlias()}"; |
340 | 340 | } |
341 | 341 | |
@@ -345,7 +345,7 @@ discard block |
||
345 | 345 | * @param string $condition |
346 | 346 | * @return $this |
347 | 347 | */ |
348 | - public function where ($condition) { |
|
348 | + public function where($condition) { |
|
349 | 349 | $this->_where[] = $condition; |
350 | 350 | return $this; |
351 | 351 | } |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | /** |
26 | 26 | * @param DB $db |
27 | 27 | */ |
28 | - public function __construct (DB $db) { |
|
28 | + public function __construct(DB $db) { |
|
29 | 29 | $this->db = $db; |
30 | 30 | } |
31 | 31 | |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | * @param Closure $prepare `():Statement` |
37 | 37 | * @return Statement |
38 | 38 | */ |
39 | - protected function cache (string $key, Closure $prepare): Statement { |
|
39 | + protected function cache(string $key, Closure $prepare): Statement { |
|
40 | 40 | return $this->_cache[$key] ?? $this->_cache[$key] = $prepare->__invoke(); |
41 | 41 | } |
42 | 42 |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | * @param DB $db |
63 | 63 | * @param string $class |
64 | 64 | */ |
65 | - public function __construct (DB $db, string $class) { |
|
65 | + public function __construct(DB $db, string $class) { |
|
66 | 66 | $this->db = $db; |
67 | 67 | $this->class = $class; |
68 | 68 | try { |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | * @param Statement $statement |
109 | 109 | * @return EntityInterface[] Enumerated |
110 | 110 | */ |
111 | - public function fetchAll (Statement $statement): array { |
|
111 | + public function fetchAll(Statement $statement): array { |
|
112 | 112 | $entities = []; |
113 | 113 | foreach ($statement->fetchAll() as $row) { |
114 | 114 | $clone = clone $this->proto; |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | * @param array[] $eavMatch Additional `[eav property => attribute => mixed]` |
129 | 129 | * @return Select |
130 | 130 | */ |
131 | - public function find (array $match, array $eavMatch = []): Select { |
|
131 | + public function find(array $match, array $eavMatch = []): Select { |
|
132 | 132 | $select = $this->select(); |
133 | 133 | foreach ($match as $column => $value) { |
134 | 134 | $select->where($this->db->match($column, $value)); |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | /** |
144 | 144 | * @return string |
145 | 145 | */ |
146 | - final public function getClass (): string { |
|
146 | + final public function getClass(): string { |
|
147 | 147 | return $this->class; |
148 | 148 | } |
149 | 149 | |
@@ -151,14 +151,14 @@ discard block |
||
151 | 151 | * @param string $property |
152 | 152 | * @return EAV |
153 | 153 | */ |
154 | - final public function getEav (string $property): EAV { |
|
154 | + final public function getEav(string $property): EAV { |
|
155 | 155 | return $this->eav[$property]; |
156 | 156 | } |
157 | 157 | |
158 | 158 | /** |
159 | 159 | * @return EntityInterface |
160 | 160 | */ |
161 | - public function getProto (): EntityInterface { |
|
161 | + public function getProto(): EntityInterface { |
|
162 | 162 | return $this->proto; |
163 | 163 | } |
164 | 164 | |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | * @param EntityInterface $entity |
167 | 167 | * @return array |
168 | 168 | */ |
169 | - protected function getValues (EntityInterface $entity): array { |
|
169 | + protected function getValues(EntityInterface $entity): array { |
|
170 | 170 | $values = []; |
171 | 171 | foreach (array_keys($this->columns) as $name) { |
172 | 172 | $values[$name] = $this->properties[$name]->getValue($entity); |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | * @param int $id |
181 | 181 | * @return null|EntityInterface |
182 | 182 | */ |
183 | - public function load (int $id): ?EntityInterface { |
|
183 | + public function load(int $id): ?EntityInterface { |
|
184 | 184 | $load = $this->cache(__FUNCTION__, function() { |
185 | 185 | return $this->select()->where('id = ?')->prepare(); |
186 | 186 | })->execute([$id]); |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | * |
199 | 199 | * @param EntityInterface[] $entities |
200 | 200 | */ |
201 | - protected function loadEav (array $entities): void { |
|
201 | + protected function loadEav(array $entities): void { |
|
202 | 202 | $ids = array_keys($entities); |
203 | 203 | foreach ($this->eav as $name => $eav) { |
204 | 204 | foreach ($eav->loadAll($ids) as $id => $values) { |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | * @param EntityInterface $entity |
214 | 214 | * @return int ID |
215 | 215 | */ |
216 | - public function save (EntityInterface $entity): int { |
|
216 | + public function save(EntityInterface $entity): int { |
|
217 | 217 | if (!$entity->getId()) { |
218 | 218 | $this->saveInsert($entity); |
219 | 219 | } |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | /** |
228 | 228 | * @param EntityInterface $entity |
229 | 229 | */ |
230 | - protected function saveEav (EntityInterface $entity): void { |
|
230 | + protected function saveEav(EntityInterface $entity): void { |
|
231 | 231 | $id = $entity->getId(); |
232 | 232 | foreach ($this->eav as $name => $eav) { |
233 | 233 | $values = $this->properties[$name]->getValue($entity); |
@@ -242,7 +242,7 @@ discard block |
||
242 | 242 | * |
243 | 243 | * @param EntityInterface $entity |
244 | 244 | */ |
245 | - protected function saveInsert (EntityInterface $entity): void { |
|
245 | + protected function saveInsert(EntityInterface $entity): void { |
|
246 | 246 | $values = $this->getValues($entity); |
247 | 247 | unset($values['id']); |
248 | 248 | $insert = $this->cache(__FUNCTION__, function() { |
@@ -260,7 +260,7 @@ discard block |
||
260 | 260 | * |
261 | 261 | * @param EntityInterface $entity |
262 | 262 | */ |
263 | - protected function saveUpdate (EntityInterface $entity): void { |
|
263 | + protected function saveUpdate(EntityInterface $entity): void { |
|
264 | 264 | $this->cache(__FUNCTION__, function() { |
265 | 265 | $slots = SQL::slots(array_keys($this->columns)); |
266 | 266 | unset($slots['id']); |
@@ -275,7 +275,7 @@ discard block |
||
275 | 275 | * @param array $columns Defaults to all columns. |
276 | 276 | * @return Select |
277 | 277 | */ |
278 | - public function select (array $columns = []): Select { |
|
278 | + public function select(array $columns = []): Select { |
|
279 | 279 | return parent::select($columns)->setFetcher(function(Statement $statement) { |
280 | 280 | return $this->fetchAll($statement); |
281 | 281 | }); |
@@ -285,7 +285,7 @@ discard block |
||
285 | 285 | * @param EntityInterface $proto |
286 | 286 | * @return $this |
287 | 287 | */ |
288 | - public function setProto (EntityInterface $proto) { |
|
288 | + public function setProto(EntityInterface $proto) { |
|
289 | 289 | $this->proto = $proto; |
290 | 290 | return $this; |
291 | 291 | } |
@@ -294,7 +294,7 @@ discard block |
||
294 | 294 | * @param EntityInterface $entity |
295 | 295 | * @param array $values |
296 | 296 | */ |
297 | - protected function setValues (EntityInterface $entity, array $values): void { |
|
297 | + protected function setValues(EntityInterface $entity, array $values): void { |
|
298 | 298 | foreach ($values as $name => $value) { |
299 | 299 | settype($value, $this->types[$name]); |
300 | 300 | $this->properties[$name]->setValue($entity, $value); |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | * @param string $name |
31 | 31 | * @param string[] $columns |
32 | 32 | */ |
33 | - public function __construct (DB $db, $name, array $columns) { |
|
33 | + public function __construct(DB $db, $name, array $columns) { |
|
34 | 34 | parent::__construct($db); |
35 | 35 | $this->name = $name; |
36 | 36 | foreach ($columns as $column) { |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | * |
44 | 44 | * @return string |
45 | 45 | */ |
46 | - final public function __toString (): string { |
|
46 | + final public function __toString(): string { |
|
47 | 47 | return $this->name; |
48 | 48 | } |
49 | 49 | |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | * @param array $match |
56 | 56 | * @return int Rows affected. |
57 | 57 | */ |
58 | - public function delete (array $match): int { |
|
58 | + public function delete(array $match): int { |
|
59 | 59 | $match = SQL::all($this->db->match($match)); |
60 | 60 | return $this->db->exec("DELETE FROM {$this} WHERE {$match}"); |
61 | 61 | } |
@@ -63,14 +63,14 @@ discard block |
||
63 | 63 | /** |
64 | 64 | * @return Column[] |
65 | 65 | */ |
66 | - final public function getColumns (): array { |
|
66 | + final public function getColumns(): array { |
|
67 | 67 | return $this->columns; |
68 | 68 | } |
69 | 69 | |
70 | 70 | /** |
71 | 71 | * @return string |
72 | 72 | */ |
73 | - final public function getName (): string { |
|
73 | + final public function getName(): string { |
|
74 | 74 | return $this->name; |
75 | 75 | } |
76 | 76 | |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | * @param array $values |
81 | 81 | * @return int Insertion ID. |
82 | 82 | */ |
83 | - public function insert (array $values): int { |
|
83 | + public function insert(array $values): int { |
|
84 | 84 | $columns = implode(',', array_keys($values)); |
85 | 85 | $values = implode(',', $this->db->quote($values)); |
86 | 86 | $this->db->exec("INSERT INTO {$this} ($columns) VALUES ($values)"); |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | * @param string $name |
92 | 92 | * @return bool |
93 | 93 | */ |
94 | - public function offsetExists ($name): bool { |
|
94 | + public function offsetExists($name): bool { |
|
95 | 95 | return isset($this->columns[$name]); |
96 | 96 | } |
97 | 97 | |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | * @param string $name |
100 | 100 | * @return Column |
101 | 101 | */ |
102 | - public function offsetGet ($name): Column { |
|
102 | + public function offsetGet($name): Column { |
|
103 | 103 | return $this->columns[$name]; |
104 | 104 | } |
105 | 105 | |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | * @param string[] $columns Defaults to all columns. |
110 | 110 | * @return Select |
111 | 111 | */ |
112 | - public function select (array $columns = []): Select { |
|
112 | + public function select(array $columns = []): Select { |
|
113 | 113 | if (!$columns) { |
114 | 114 | $columns = $this->columns; |
115 | 115 | } |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | * @param string $name |
123 | 123 | * @return Table |
124 | 124 | */ |
125 | - public function setName (string $name) { |
|
125 | + public function setName(string $name) { |
|
126 | 126 | $clone = clone $this; |
127 | 127 | $clone->name = $name; |
128 | 128 | foreach ($this->columns as $name => $column) { |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | * @param array $match |
141 | 141 | * @return int Rows affected. |
142 | 142 | */ |
143 | - public function update (array $values, array $match): int { |
|
143 | + public function update(array $values, array $match): int { |
|
144 | 144 | $values = implode(', ', SQL::isEqual($this->db->quote($values))); |
145 | 145 | $match = SQL::all($this->db->match($match)); |
146 | 146 | return $this->db->exec("UPDATE {$this} SET {$values} WHERE {$match}"); |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | * @param DB $db |
32 | 32 | * @param string $interface |
33 | 33 | */ |
34 | - public function __construct (DB $db, string $interface) { |
|
34 | + public function __construct(DB $db, string $interface) { |
|
35 | 35 | $this->interface = $interface; |
36 | 36 | try { |
37 | 37 | $interface = new ReflectionClass($interface); |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | * @param EntityInterface $entity |
58 | 58 | * @return int |
59 | 59 | */ |
60 | - public function count (EntityInterface $entity): int { |
|
60 | + public function count(EntityInterface $entity): int { |
|
61 | 61 | $key = $this->getKey($entity); |
62 | 62 | return $this->cache("count.{$key}", function() use ($key) { |
63 | 63 | return $this->select(['COUNT(*)'])->where("{$key} = ?")->prepare(); |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | * @param string $class |
74 | 74 | * @return Select |
75 | 75 | */ |
76 | - public function getCollection (EntityInterface $owner, string $class): Select { |
|
76 | + public function getCollection(EntityInterface $owner, string $class): Select { |
|
77 | 77 | $record = $this->db->getRecord($class); |
78 | 78 | $select = $record->select(); |
79 | 79 | $select->join($this, $this[$class]->isEqual($record['id'])); |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | /** |
85 | 85 | * @return string |
86 | 86 | */ |
87 | - final public function getInterface (): string { |
|
87 | + final public function getInterface(): string { |
|
88 | 88 | return $this->interface; |
89 | 89 | } |
90 | 90 | |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | * @param EntityInterface|string $class |
95 | 95 | * @return string |
96 | 96 | */ |
97 | - public function getKey ($class): string { |
|
97 | + public function getKey($class): string { |
|
98 | 98 | if (is_object($class)) { |
99 | 99 | $class = get_class($class); |
100 | 100 | } |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | * @param EntityInterface[] $entities |
113 | 113 | * @return int Rows affected. |
114 | 114 | */ |
115 | - public function link (array $entities): int { |
|
115 | + public function link(array $entities): int { |
|
116 | 116 | $ids = array_fill_keys($this->keys, null); |
117 | 117 | foreach ($entities as $entity) { |
118 | 118 | $ids[$this->getKey($entity)] = $entity->getId(); |
@@ -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 | $ids = array_fill_keys($this->keys, null); |
161 | 161 | foreach ($entities as $entity) { |
162 | 162 | $ids[$this->getKey($entity)] = $entity->getId(); |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | * @param Record $record The entity's storage access. |
19 | 19 | * @param $name |
20 | 20 | */ |
21 | - public function __construct (Record $record, $name) { |
|
21 | + public function __construct(Record $record, $name) { |
|
22 | 22 | $this->record = $record; |
23 | 23 | parent::__construct($record->db, $name, ['entity', 'attribute', 'value']); |
24 | 24 | } |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | * @param int $id |
30 | 30 | * @return int |
31 | 31 | */ |
32 | - public function count (int $id): int { |
|
32 | + public function count(int $id): int { |
|
33 | 33 | return $this->cache(__FUNCTION__, function() { |
34 | 34 | return $this->select(['COUNT(*)'])->where('entity=?')->prepare(); |
35 | 35 | })->execute([$id])->fetchColumn(); |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | * @param string $attribute |
43 | 43 | * @return bool |
44 | 44 | */ |
45 | - public function exists (int $id, string $attribute): bool { |
|
45 | + public function exists(int $id, string $attribute): bool { |
|
46 | 46 | return $this->cache(__FUNCTION__, function() { |
47 | 47 | return $this->select(['COUNT(*) > 0'])->where('entity = ? AND attribute = ?')->prepare(); |
48 | 48 | })->execute([$id, $attribute])->fetchColumn(); |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | * @param array $match `[attribute => value]`. If empty, selects all IDs for entities having at least one attribute. |
58 | 58 | * @return Select |
59 | 59 | */ |
60 | - public function find (array $match): Select { |
|
60 | + public function find(array $match): Select { |
|
61 | 61 | $select = $this->select([$this['entity']]); |
62 | 62 | $prior = $this; |
63 | 63 | foreach ($match as $attribute => $value) { |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | * @param int $id |
80 | 80 | * @return array `[attribute => value]` |
81 | 81 | */ |
82 | - public function load (int $id): array { |
|
82 | + public function load(int $id): array { |
|
83 | 83 | return $this->cache(__FUNCTION__, function() { |
84 | 84 | return $this->select(['attribute', 'value'])->where('entity = ?')->prepare(); |
85 | 85 | })->execute([$id])->fetchAll(DB::FETCH_KEY_PAIR); |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | * @param int[] $ids |
92 | 92 | * @return array[] `[id => attribute => value] |
93 | 93 | */ |
94 | - public function loadAll (array $ids): array { |
|
94 | + public function loadAll(array $ids): array { |
|
95 | 95 | if (count($ids) === 1) { |
96 | 96 | return [current($ids) => $this->load(current($ids))]; |
97 | 97 | } |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | * @param array $values `[attribute => value]` |
112 | 112 | * @return $this |
113 | 113 | */ |
114 | - public function save (int $id, array $values) { |
|
114 | + public function save(int $id, array $values) { |
|
115 | 115 | $this->delete([ |
116 | 116 | $this['entity']->isEqual($id), |
117 | 117 | $this['attribute']->isNotEqual(array_keys($values)) |
@@ -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 | |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | * |
31 | 31 | * @return string |
32 | 32 | */ |
33 | - public function __toString () { |
|
33 | + public function __toString() { |
|
34 | 34 | return $this->queryString; |
35 | 35 | } |
36 | 36 | |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | * @return $this |
45 | 45 | * @throws ArgumentCountError |
46 | 46 | */ |
47 | - public function execute ($args = null) { |
|
47 | + public function execute($args = null) { |
|
48 | 48 | $this->db->getLogger()->__invoke($this->queryString); |
49 | 49 | if (!parent::execute($args)) { |
50 | 50 | $info = $this->errorInfo(); |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | * |
62 | 62 | * @return int |
63 | 63 | */ |
64 | - public function getId (): int { |
|
64 | + public function getId(): int { |
|
65 | 65 | return $this->db->lastInsertId(); |
66 | 66 | } |
67 | 67 | } |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | * @param string $name |
30 | 30 | * @param string $qualifier |
31 | 31 | */ |
32 | - public function __construct (DB $db, string $name, string $qualifier = '') { |
|
32 | + public function __construct(DB $db, string $name, string $qualifier = '') { |
|
33 | 33 | parent::__construct($db); |
34 | 34 | $this->name = $name; |
35 | 35 | $this->qualifier = $qualifier; |
@@ -40,21 +40,21 @@ discard block |
||
40 | 40 | * |
41 | 41 | * @return string |
42 | 42 | */ |
43 | - public function __toString (): string { |
|
43 | + public function __toString(): string { |
|
44 | 44 | return strlen($this->qualifier) ? "{$this->qualifier}.{$this->name}" : $this->name; |
45 | 45 | } |
46 | 46 | |
47 | 47 | /** |
48 | 48 | * @return string |
49 | 49 | */ |
50 | - final public function getName (): string { |
|
50 | + final public function getName(): string { |
|
51 | 51 | return $this->name; |
52 | 52 | } |
53 | 53 | |
54 | 54 | /** |
55 | 55 | * @return string |
56 | 56 | */ |
57 | - final public function getQualifier (): string { |
|
57 | + final public function getQualifier(): string { |
|
58 | 58 | return $this->qualifier; |
59 | 59 | } |
60 | 60 | |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | * @param null|bool|string|Select $arg |
68 | 68 | * @return string |
69 | 69 | */ |
70 | - public function is ($arg): string { |
|
70 | + public function is($arg): string { |
|
71 | 71 | if ($arg === null or is_bool($arg)) { |
72 | 72 | $arg = ['' => 'NULL', 1 => 'TRUE', 0 => 'FALSE'][$arg]; |
73 | 73 | } |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | * @param string|array|Select $arg |
85 | 85 | * @return string |
86 | 86 | */ |
87 | - public function isEqual ($arg): string { |
|
87 | + public function isEqual($arg): string { |
|
88 | 88 | return SQL::isEqual($this, $this->db->quote($arg)); |
89 | 89 | } |
90 | 90 | |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | * @param string|Select $arg |
95 | 95 | * @return string |
96 | 96 | */ |
97 | - public function isGreater ($arg): string { |
|
97 | + public function isGreater($arg): string { |
|
98 | 98 | return SQL::isGreater($this, $this->db->quote($arg)); |
99 | 99 | } |
100 | 100 | |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | * @param string|Select $arg |
105 | 105 | * @return string |
106 | 106 | */ |
107 | - public function isGreaterOrEqual ($arg): string { |
|
107 | + public function isGreaterOrEqual($arg): string { |
|
108 | 108 | return SQL::isGreaterOrEqual($this, $this->db->quote($arg)); |
109 | 109 | } |
110 | 110 | |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | * @param string|Select $arg |
115 | 115 | * @return string |
116 | 116 | */ |
117 | - public function isLess ($arg): string { |
|
117 | + public function isLess($arg): string { |
|
118 | 118 | return SQL::isLess($this, $this->db->quote($arg)); |
119 | 119 | } |
120 | 120 | |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | * @param string|Select $arg |
125 | 125 | * @return string |
126 | 126 | */ |
127 | - public function isLessOrEqual ($arg): string { |
|
127 | + public function isLessOrEqual($arg): string { |
|
128 | 128 | return SQL::isLessOrEqual($this, $this->db->quote($arg)); |
129 | 129 | } |
130 | 130 | |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | * @param string $pattern |
135 | 135 | * @return string |
136 | 136 | */ |
137 | - public function isLike (string $pattern): string { |
|
137 | + public function isLike(string $pattern): string { |
|
138 | 138 | return SQL::isLike($this, $this->db->quote($pattern)); |
139 | 139 | } |
140 | 140 | |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | * @param null|bool|string|Select $arg |
147 | 147 | * @return string |
148 | 148 | */ |
149 | - public function isNot ($arg): string { |
|
149 | + public function isNot($arg): string { |
|
150 | 150 | return SQL::not($this->is($arg)); |
151 | 151 | } |
152 | 152 | |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | * @param string|array|Select $arg |
157 | 157 | * @return string |
158 | 158 | */ |
159 | - public function isNotEqual ($arg): string { |
|
159 | + public function isNotEqual($arg): string { |
|
160 | 160 | return SQL::isNotEqual($this, $this->db->quote($arg)); |
161 | 161 | } |
162 | 162 | |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | * @param string $pattern |
167 | 167 | * @return string |
168 | 168 | */ |
169 | - public function isNotLike (string $pattern): string { |
|
169 | + public function isNotLike(string $pattern): string { |
|
170 | 170 | return SQL::isNotLike($this, $this->db->quote($pattern)); |
171 | 171 | } |
172 | 172 | |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | * |
176 | 176 | * @return string |
177 | 177 | */ |
178 | - public function isNotNull (): string { |
|
178 | + public function isNotNull(): string { |
|
179 | 179 | return SQL::isNotNull($this); |
180 | 180 | } |
181 | 181 | |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | * @param string $pattern |
186 | 186 | * @return string |
187 | 187 | */ |
188 | - public function isNotRegExp (string $pattern): string { |
|
188 | + public function isNotRegExp(string $pattern): string { |
|
189 | 189 | return SQL::isNotRegExp($this, $this->db->quote($pattern)); |
190 | 190 | } |
191 | 191 | |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | * @param string $pattern |
196 | 196 | * @return string |
197 | 197 | */ |
198 | - public function isRegExp (string $pattern): string { |
|
198 | + public function isRegExp(string $pattern): string { |
|
199 | 199 | return SQL::isRegExp($this, $this->db->quote($pattern)); |
200 | 200 | } |
201 | 201 | |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | * @param string $name |
204 | 204 | * @return $this |
205 | 205 | */ |
206 | - public function setName (string $name) { |
|
206 | + public function setName(string $name) { |
|
207 | 207 | $clone = clone $this; |
208 | 208 | $clone->name = $name; |
209 | 209 | return $clone; |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | * @param string $qualifier |
214 | 214 | * @return $this |
215 | 215 | */ |
216 | - public function setQualifier (string $qualifier) { |
|
216 | + public function setQualifier(string $qualifier) { |
|
217 | 217 | $clone = clone $this; |
218 | 218 | $clone->qualifier = $qualifier; |
219 | 219 | return $clone; |