@@ -35,8 +35,7 @@ |
||
| 35 | 35 | $this->interface = $interface; |
| 36 | 36 | try { |
| 37 | 37 | $interface = new ReflectionClass($interface); |
| 38 | - } |
|
| 39 | - catch (ReflectionException $exception) { |
|
| 38 | + } catch (ReflectionException $exception) { |
|
| 40 | 39 | throw new LogicException('Unexpected ReflectionException', 0, $exception); |
| 41 | 40 | } |
| 42 | 41 | $doc = $interface->getDocComment(); |
@@ -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(); |
@@ -70,8 +70,7 @@ |
||
| 70 | 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 | - } |
|
| 74 | - else { |
|
| 73 | + } else { |
|
| 75 | 74 | $arg = $this->db->quote($arg); |
| 76 | 75 | } |
| 77 | 76 | $operator = ['mysql' => '<=>', 'sqlite' => 'IS'][$this->db->getDriver()]; |
@@ -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,7 +40,7 @@ discard block |
||
| 40 | 40 | * |
| 41 | 41 | * @return string |
| 42 | 42 | */ |
| 43 | - public function __toString (): string { |
|
| 43 | + public function __toString(): string { |
|
| 44 | 44 | if (strlen($this->qualifier)) { |
| 45 | 45 | return "{$this->qualifier}.{$this->name}"; |
| 46 | 46 | } |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | * |
| 53 | 53 | * @return ExpressionInterface |
| 54 | 54 | */ |
| 55 | - public function avg (): ExpressionInterface { |
|
| 55 | + public function avg(): ExpressionInterface { |
|
| 56 | 56 | return SQL::avg($this); |
| 57 | 57 | } |
| 58 | 58 | |
@@ -61,21 +61,21 @@ discard block |
||
| 61 | 61 | * |
| 62 | 62 | * @return ExpressionInterface |
| 63 | 63 | */ |
| 64 | - public function count (): ExpressionInterface { |
|
| 64 | + public function count(): ExpressionInterface { |
|
| 65 | 65 | return SQL::count($this); |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | /** |
| 69 | 69 | * @return string |
| 70 | 70 | */ |
| 71 | - final public function getName (): string { |
|
| 71 | + final public function getName(): string { |
|
| 72 | 72 | return $this->name; |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | /** |
| 76 | 76 | * @return string |
| 77 | 77 | */ |
| 78 | - final public function getQualifier (): string { |
|
| 78 | + final public function getQualifier(): string { |
|
| 79 | 79 | return $this->qualifier; |
| 80 | 80 | } |
| 81 | 81 | |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | * @param null|bool|string|Select $arg |
| 89 | 89 | * @return string |
| 90 | 90 | */ |
| 91 | - public function is ($arg): string { |
|
| 91 | + public function is($arg): string { |
|
| 92 | 92 | if ($arg === null or is_bool($arg)) { |
| 93 | 93 | $arg = ['' => 'NULL', 1 => 'TRUE', 0 => 'FALSE'][$arg]; |
| 94 | 94 | } |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | * @param string|array|Select $arg |
| 106 | 106 | * @return string |
| 107 | 107 | */ |
| 108 | - public function isEqual ($arg): string { |
|
| 108 | + public function isEqual($arg): string { |
|
| 109 | 109 | return SQL::isEqual($this, $this->db->quote($arg)); |
| 110 | 110 | } |
| 111 | 111 | |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | * @param string|Select $arg |
| 116 | 116 | * @return string |
| 117 | 117 | */ |
| 118 | - public function isGreater ($arg): string { |
|
| 118 | + public function isGreater($arg): string { |
|
| 119 | 119 | return SQL::isGreater($this, $this->db->quote($arg)); |
| 120 | 120 | } |
| 121 | 121 | |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | * @param string|Select $arg |
| 126 | 126 | * @return string |
| 127 | 127 | */ |
| 128 | - public function isGreaterOrEqual ($arg): string { |
|
| 128 | + public function isGreaterOrEqual($arg): string { |
|
| 129 | 129 | return SQL::isGreaterOrEqual($this, $this->db->quote($arg)); |
| 130 | 130 | } |
| 131 | 131 | |
@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | * @param string|Select $arg |
| 136 | 136 | * @return string |
| 137 | 137 | */ |
| 138 | - public function isLess ($arg): string { |
|
| 138 | + public function isLess($arg): string { |
|
| 139 | 139 | return SQL::isLess($this, $this->db->quote($arg)); |
| 140 | 140 | } |
| 141 | 141 | |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | * @param string|Select $arg |
| 146 | 146 | * @return string |
| 147 | 147 | */ |
| 148 | - public function isLessOrEqual ($arg): string { |
|
| 148 | + public function isLessOrEqual($arg): string { |
|
| 149 | 149 | return SQL::isLessOrEqual($this, $this->db->quote($arg)); |
| 150 | 150 | } |
| 151 | 151 | |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | * @param string $pattern |
| 156 | 156 | * @return string |
| 157 | 157 | */ |
| 158 | - public function isLike (string $pattern): string { |
|
| 158 | + public function isLike(string $pattern): string { |
|
| 159 | 159 | return SQL::isLike($this, $this->db->quote($pattern)); |
| 160 | 160 | } |
| 161 | 161 | |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | * @param null|bool|string|Select $arg |
| 168 | 168 | * @return string |
| 169 | 169 | */ |
| 170 | - public function isNot ($arg): string { |
|
| 170 | + public function isNot($arg): string { |
|
| 171 | 171 | return SQL::not($this->is($arg)); |
| 172 | 172 | } |
| 173 | 173 | |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | * @param string|array|Select $arg |
| 178 | 178 | * @return string |
| 179 | 179 | */ |
| 180 | - public function isNotEqual ($arg): string { |
|
| 180 | + public function isNotEqual($arg): string { |
|
| 181 | 181 | return SQL::isNotEqual($this, $this->db->quote($arg)); |
| 182 | 182 | } |
| 183 | 183 | |
@@ -187,7 +187,7 @@ discard block |
||
| 187 | 187 | * @param string $pattern |
| 188 | 188 | * @return string |
| 189 | 189 | */ |
| 190 | - public function isNotLike (string $pattern): string { |
|
| 190 | + public function isNotLike(string $pattern): string { |
|
| 191 | 191 | return SQL::isNotLike($this, $this->db->quote($pattern)); |
| 192 | 192 | } |
| 193 | 193 | |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | * |
| 197 | 197 | * @return string |
| 198 | 198 | */ |
| 199 | - public function isNotNull (): string { |
|
| 199 | + public function isNotNull(): string { |
|
| 200 | 200 | return SQL::isNotNull($this); |
| 201 | 201 | } |
| 202 | 202 | |
@@ -206,7 +206,7 @@ discard block |
||
| 206 | 206 | * @param string $pattern |
| 207 | 207 | * @return string |
| 208 | 208 | */ |
| 209 | - public function isNotRegExp (string $pattern): string { |
|
| 209 | + public function isNotRegExp(string $pattern): string { |
|
| 210 | 210 | return SQL::isNotRegExp($this, $this->db->quote($pattern)); |
| 211 | 211 | } |
| 212 | 212 | |
@@ -216,7 +216,7 @@ discard block |
||
| 216 | 216 | * @param string $pattern |
| 217 | 217 | * @return string |
| 218 | 218 | */ |
| 219 | - public function isRegExp (string $pattern): string { |
|
| 219 | + public function isRegExp(string $pattern): string { |
|
| 220 | 220 | return SQL::isRegExp($this, $this->db->quote($pattern)); |
| 221 | 221 | } |
| 222 | 222 | |
@@ -225,7 +225,7 @@ discard block |
||
| 225 | 225 | * |
| 226 | 226 | * @return ExpressionInterface |
| 227 | 227 | */ |
| 228 | - public function max (): ExpressionInterface { |
|
| 228 | + public function max(): ExpressionInterface { |
|
| 229 | 229 | return SQL::max($this); |
| 230 | 230 | } |
| 231 | 231 | |
@@ -234,7 +234,7 @@ discard block |
||
| 234 | 234 | * |
| 235 | 235 | * @return ExpressionInterface |
| 236 | 236 | */ |
| 237 | - public function min (): ExpressionInterface { |
|
| 237 | + public function min(): ExpressionInterface { |
|
| 238 | 238 | return SQL::min($this); |
| 239 | 239 | } |
| 240 | 240 | |
@@ -242,7 +242,7 @@ discard block |
||
| 242 | 242 | * @param string $name |
| 243 | 243 | * @return $this |
| 244 | 244 | */ |
| 245 | - public function setName (string $name) { |
|
| 245 | + public function setName(string $name) { |
|
| 246 | 246 | $clone = clone $this; |
| 247 | 247 | $clone->name = $name; |
| 248 | 248 | return $clone; |
@@ -252,7 +252,7 @@ discard block |
||
| 252 | 252 | * @param string $qualifier |
| 253 | 253 | * @return $this |
| 254 | 254 | */ |
| 255 | - public function setQualifier (string $qualifier) { |
|
| 255 | + public function setQualifier(string $qualifier) { |
|
| 256 | 256 | $clone = clone $this; |
| 257 | 257 | $clone->qualifier = $qualifier; |
| 258 | 258 | return $clone; |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | /** |
| 23 | 23 | * @return array |
| 24 | 24 | */ |
| 25 | - public function getAttributes (): array { |
|
| 25 | + public function getAttributes(): array { |
|
| 26 | 26 | return $this->attributes ?: []; |
| 27 | 27 | } |
| 28 | 28 | |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | * @param mixed $offset |
| 31 | 31 | * @return bool |
| 32 | 32 | */ |
| 33 | - public function offsetExists ($offset): bool { |
|
| 33 | + public function offsetExists($offset): bool { |
|
| 34 | 34 | return $this->attributes and array_key_exists($offset, $this->attributes); |
| 35 | 35 | } |
| 36 | 36 | |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | * @param mixed $offset |
| 39 | 39 | * @return mixed Returns `NULL` for nonexistent attributes. |
| 40 | 40 | */ |
| 41 | - public function offsetGet ($offset) { |
|
| 41 | + public function offsetGet($offset) { |
|
| 42 | 42 | return $this->attributes[$offset] ?? null; |
| 43 | 43 | } |
| 44 | 44 | |
@@ -46,14 +46,14 @@ discard block |
||
| 46 | 46 | * @param mixed $offset |
| 47 | 47 | * @param mixed $value |
| 48 | 48 | */ |
| 49 | - public function offsetSet ($offset, $value): void { |
|
| 49 | + public function offsetSet($offset, $value): void { |
|
| 50 | 50 | $this->attributes[$offset] = $value; |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | /** |
| 54 | 54 | * @param mixed $offset |
| 55 | 55 | */ |
| 56 | - public function offsetUnset ($offset): void { |
|
| 56 | + public function offsetUnset($offset): void { |
|
| 57 | 57 | unset($this->attributes[$offset]); |
| 58 | 58 | } |
| 59 | 59 | |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | * @param array $attributes |
| 62 | 62 | * @return $this |
| 63 | 63 | */ |
| 64 | - public function setAttributes (array $attributes) { |
|
| 64 | + public function setAttributes(array $attributes) { |
|
| 65 | 65 | $this->attributes = $attributes; |
| 66 | 66 | return $this; |
| 67 | 67 | } |
@@ -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 |
@@ -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 | |
@@ -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}"); |
@@ -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 | } |
@@ -15,19 +15,19 @@ discard block |
||
| 15 | 15 | * |
| 16 | 16 | * @return string |
| 17 | 17 | */ |
| 18 | - abstract public function __toString (): string; |
|
| 18 | + abstract public function __toString(): string; |
|
| 19 | 19 | |
| 20 | 20 | /** |
| 21 | 21 | * @param string $name |
| 22 | 22 | * @return bool |
| 23 | 23 | */ |
| 24 | - abstract public function offsetExists ($name): bool; |
|
| 24 | + abstract public function offsetExists($name): bool; |
|
| 25 | 25 | |
| 26 | 26 | /** |
| 27 | 27 | * @param string $name |
| 28 | 28 | * @return Column |
| 29 | 29 | */ |
| 30 | - abstract public function offsetGet ($name): Column; |
|
| 30 | + abstract public function offsetGet($name): Column; |
|
| 31 | 31 | |
| 32 | 32 | /** |
| 33 | 33 | * Throws. |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | * @param void $value |
| 37 | 37 | * @throws Exception |
| 38 | 38 | */ |
| 39 | - final public function offsetSet ($name, $value): void { |
|
| 39 | + final public function offsetSet($name, $value): void { |
|
| 40 | 40 | throw new Exception('Tables are immutable.'); |
| 41 | 41 | } |
| 42 | 42 | |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | * @param void $name |
| 47 | 47 | * @throws Exception |
| 48 | 48 | */ |
| 49 | - final public function offsetUnset ($name): void { |
|
| 49 | + final public function offsetUnset($name): void { |
|
| 50 | 50 | $this->offsetSet($name, null); |
| 51 | 51 | } |
| 52 | 52 | |