@@ -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 | $count = $this->cache("count.{$key}", function() use ($key) { |
| 63 | 63 | return $this->select(['COUNT(*)'])->where("{$key} = ?")->prepare(); |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | * @param string $class |
| 75 | 75 | * @return Select |
| 76 | 76 | */ |
| 77 | - public function getCollection (EntityInterface $owner, string $class): Select { |
|
| 77 | + public function getCollection(EntityInterface $owner, string $class): Select { |
|
| 78 | 78 | $record = $this->db->getRecord($class); |
| 79 | 79 | $select = $record->select(); |
| 80 | 80 | $select->join($this, $this[$class]->isEqual($record['id'])); |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | /** |
| 86 | 86 | * @return string |
| 87 | 87 | */ |
| 88 | - final public function getInterface (): string { |
|
| 88 | + final public function getInterface(): string { |
|
| 89 | 89 | return $this->interface; |
| 90 | 90 | } |
| 91 | 91 | |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | * @param EntityInterface|string $class |
| 96 | 96 | * @return string |
| 97 | 97 | */ |
| 98 | - public function getKey ($class): string { |
|
| 98 | + public function getKey($class): string { |
|
| 99 | 99 | if (is_object($class)) { |
| 100 | 100 | $class = get_class($class); |
| 101 | 101 | } |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | * @param EntityInterface[] $entities |
| 114 | 114 | * @return int Rows affected. |
| 115 | 115 | */ |
| 116 | - public function link (array $entities): int { |
|
| 116 | + public function link(array $entities): int { |
|
| 117 | 117 | $link = $this->cache(__FUNCTION__, function() { |
| 118 | 118 | $slots = implode(',', SQL::slots($this->keys)); |
| 119 | 119 | $columns = implode(',', $this->keys); |
@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | * @param string $name |
| 136 | 136 | * @return bool |
| 137 | 137 | */ |
| 138 | - public function offsetExists ($name): bool { |
|
| 138 | + public function offsetExists($name): bool { |
|
| 139 | 139 | return isset($this->columns[$name]) or isset($this->keys[$name]); |
| 140 | 140 | } |
| 141 | 141 | |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | * @param string $name |
| 146 | 146 | * @return Column |
| 147 | 147 | */ |
| 148 | - public function offsetGet ($name): Column { |
|
| 148 | + public function offsetGet($name): Column { |
|
| 149 | 149 | return $this->columns[$name] ?? $this->columns[$this->keys[$name]]; |
| 150 | 150 | } |
| 151 | 151 | |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | * @param EntityInterface[] $entities |
| 159 | 159 | * @return int Rows affected. |
| 160 | 160 | */ |
| 161 | - public function unlink (array $entities): int { |
|
| 161 | + public function unlink(array $entities): int { |
|
| 162 | 162 | $unlink = $this->cache(__FUNCTION__, function() { |
| 163 | 163 | $slots = SQL::all(SQL::isEqual(SQL::slots($this->keys))); |
| 164 | 164 | return $this->db->prepare("DELETE FROM {$this} WHERE {$slots}"); |
@@ -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()]; |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | * @param string $name |
| 35 | 35 | * @param string $qualifier |
| 36 | 36 | */ |
| 37 | - public function __construct (DB $db, string $name, string $qualifier = '') { |
|
| 37 | + public function __construct(DB $db, string $name, string $qualifier = '') { |
|
| 38 | 38 | parent::__construct($db); |
| 39 | 39 | $this->name = $name; |
| 40 | 40 | $this->qualifier = $qualifier; |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | * @param array $arguments |
| 51 | 51 | * @return ExpressionInterface |
| 52 | 52 | */ |
| 53 | - public function __call (string $name, array $arguments): ExpressionInterface { |
|
| 53 | + public function __call(string $name, array $arguments): ExpressionInterface { |
|
| 54 | 54 | array_push($arguments, $this); |
| 55 | 55 | return Expression::__callStatic($name, $arguments); |
| 56 | 56 | } |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | * |
| 61 | 61 | * @return string |
| 62 | 62 | */ |
| 63 | - public function __toString (): string { |
|
| 63 | + public function __toString(): string { |
|
| 64 | 64 | if (strlen($this->qualifier)) { |
| 65 | 65 | return "{$this->qualifier}.{$this->name}"; |
| 66 | 66 | } |
@@ -70,14 +70,14 @@ discard block |
||
| 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 | |
| 77 | 77 | /** |
| 78 | 78 | * @return string |
| 79 | 79 | */ |
| 80 | - final public function getQualifier (): string { |
|
| 80 | + final public function getQualifier(): string { |
|
| 81 | 81 | return $this->qualifier; |
| 82 | 82 | } |
| 83 | 83 | |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | * @param null|bool|string|Select $arg |
| 91 | 91 | * @return string |
| 92 | 92 | */ |
| 93 | - public function is ($arg): string { |
|
| 93 | + public function is($arg): string { |
|
| 94 | 94 | if ($arg === null or is_bool($arg)) { |
| 95 | 95 | $arg = ['' => 'NULL', 1 => 'TRUE', 0 => 'FALSE'][$arg]; |
| 96 | 96 | } |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | * @param string|array|Select $arg |
| 108 | 108 | * @return string |
| 109 | 109 | */ |
| 110 | - public function isEqual ($arg): string { |
|
| 110 | + public function isEqual($arg): string { |
|
| 111 | 111 | return SQL::isEqual($this, $this->db->quoteMixed($arg)); |
| 112 | 112 | } |
| 113 | 113 | |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | * @param string|Select $arg |
| 118 | 118 | * @return string |
| 119 | 119 | */ |
| 120 | - public function isGreater ($arg): string { |
|
| 120 | + public function isGreater($arg): string { |
|
| 121 | 121 | return SQL::isGreater($this, $this->db->quote($arg)); |
| 122 | 122 | } |
| 123 | 123 | |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | * @param string|Select $arg |
| 128 | 128 | * @return string |
| 129 | 129 | */ |
| 130 | - public function isGreaterOrEqual ($arg): string { |
|
| 130 | + public function isGreaterOrEqual($arg): string { |
|
| 131 | 131 | return SQL::isGreaterOrEqual($this, $this->db->quote($arg)); |
| 132 | 132 | } |
| 133 | 133 | |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | * @param string|Select $arg |
| 138 | 138 | * @return string |
| 139 | 139 | */ |
| 140 | - public function isLess ($arg): string { |
|
| 140 | + public function isLess($arg): string { |
|
| 141 | 141 | return SQL::isLess($this, $this->db->quote($arg)); |
| 142 | 142 | } |
| 143 | 143 | |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | * @param string|Select $arg |
| 148 | 148 | * @return string |
| 149 | 149 | */ |
| 150 | - public function isLessOrEqual ($arg): string { |
|
| 150 | + public function isLessOrEqual($arg): string { |
|
| 151 | 151 | return SQL::isLessOrEqual($this, $this->db->quote($arg)); |
| 152 | 152 | } |
| 153 | 153 | |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | * @param string $pattern |
| 158 | 158 | * @return string |
| 159 | 159 | */ |
| 160 | - public function isLike (string $pattern): string { |
|
| 160 | + public function isLike(string $pattern): string { |
|
| 161 | 161 | return SQL::isLike($this, $this->db->quote($pattern)); |
| 162 | 162 | } |
| 163 | 163 | |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | * @param null|bool|string|Select $arg |
| 170 | 170 | * @return string |
| 171 | 171 | */ |
| 172 | - public function isNot ($arg): string { |
|
| 172 | + public function isNot($arg): string { |
|
| 173 | 173 | return SQL::not($this->is($arg)); |
| 174 | 174 | } |
| 175 | 175 | |
@@ -179,7 +179,7 @@ discard block |
||
| 179 | 179 | * @param string|array|Select $arg |
| 180 | 180 | * @return string |
| 181 | 181 | */ |
| 182 | - public function isNotEqual ($arg): string { |
|
| 182 | + public function isNotEqual($arg): string { |
|
| 183 | 183 | return SQL::isNotEqual($this, $this->db->quoteMixed($arg)); |
| 184 | 184 | } |
| 185 | 185 | |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | * @param string $pattern |
| 190 | 190 | * @return string |
| 191 | 191 | */ |
| 192 | - public function isNotLike (string $pattern): string { |
|
| 192 | + public function isNotLike(string $pattern): string { |
|
| 193 | 193 | return SQL::isNotLike($this, $this->db->quote($pattern)); |
| 194 | 194 | } |
| 195 | 195 | |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | * |
| 199 | 199 | * @return string |
| 200 | 200 | */ |
| 201 | - public function isNotNull (): string { |
|
| 201 | + public function isNotNull(): string { |
|
| 202 | 202 | return SQL::isNotNull($this); |
| 203 | 203 | } |
| 204 | 204 | |
@@ -208,7 +208,7 @@ discard block |
||
| 208 | 208 | * @param string $pattern |
| 209 | 209 | * @return string |
| 210 | 210 | */ |
| 211 | - public function isNotRegExp (string $pattern): string { |
|
| 211 | + public function isNotRegExp(string $pattern): string { |
|
| 212 | 212 | return SQL::isNotRegExp($this, $this->db->quote($pattern)); |
| 213 | 213 | } |
| 214 | 214 | |
@@ -218,7 +218,7 @@ discard block |
||
| 218 | 218 | * @param string $pattern |
| 219 | 219 | * @return string |
| 220 | 220 | */ |
| 221 | - public function isRegExp (string $pattern): string { |
|
| 221 | + public function isRegExp(string $pattern): string { |
|
| 222 | 222 | return SQL::isRegExp($this, $this->db->quote($pattern)); |
| 223 | 223 | } |
| 224 | 224 | |
@@ -226,7 +226,7 @@ discard block |
||
| 226 | 226 | * @param string $name |
| 227 | 227 | * @return $this |
| 228 | 228 | */ |
| 229 | - public function setName (string $name) { |
|
| 229 | + public function setName(string $name) { |
|
| 230 | 230 | $clone = clone $this; |
| 231 | 231 | $clone->name = $name; |
| 232 | 232 | return $clone; |
@@ -236,7 +236,7 @@ discard block |
||
| 236 | 236 | * @param string $qualifier |
| 237 | 237 | * @return $this |
| 238 | 238 | */ |
| 239 | - public function setQualifier (string $qualifier) { |
|
| 239 | + public function setQualifier(string $qualifier) { |
|
| 240 | 240 | $clone = clone $this; |
| 241 | 241 | $clone->qualifier = $qualifier; |
| 242 | 242 | 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 | |
@@ -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 | |
@@ -66,8 +66,7 @@ discard block |
||
| 66 | 66 | $this->class = $class; |
| 67 | 67 | try { |
| 68 | 68 | $class = new ReflectionClass($class); |
| 69 | - } |
|
| 70 | - catch (ReflectionException $exception) { |
|
| 69 | + } catch (ReflectionException $exception) { |
|
| 71 | 70 | throw new LogicException('Unexpected ReflectionException', 0, $exception); |
| 72 | 71 | } |
| 73 | 72 | $this->proto = $class->newInstanceWithoutConstructor(); |
@@ -84,8 +83,7 @@ discard block |
||
| 84 | 83 | if (preg_match('/@var\s+(?<type>[a-z]+)[\s$]/', $doc, $match)) { |
| 85 | 84 | $types[$name] = $match['type']; |
| 86 | 85 | } |
| 87 | - } |
|
| 88 | - elseif (preg_match('/@eav\s+(?<table>\S+)/', $doc, $match)) { |
|
| 86 | + } elseif (preg_match('/@eav\s+(?<table>\S+)/', $doc, $match)) { |
|
| 89 | 87 | $eav[$name] = $match['table']; |
| 90 | 88 | $this->properties[$name] = $property; |
| 91 | 89 | } |
@@ -213,8 +211,7 @@ discard block |
||
| 213 | 211 | public function save (EntityInterface $entity): int { |
| 214 | 212 | if (!$entity->getId()) { |
| 215 | 213 | $this->saveInsert($entity); |
| 216 | - } |
|
| 217 | - else { |
|
| 214 | + } else { |
|
| 218 | 215 | $this->saveUpdate($entity); |
| 219 | 216 | } |
| 220 | 217 | $this->saveEav($entity); |
@@ -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->class = $class; |
| 67 | 67 | try { |
| 68 | 68 | $class = new ReflectionClass($class); |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | * @param Statement $statement |
| 106 | 106 | * @return EntityInterface[] Enumerated |
| 107 | 107 | */ |
| 108 | - public function fetchAll (Statement $statement): array { |
|
| 108 | + public function fetchAll(Statement $statement): array { |
|
| 109 | 109 | $entities = []; |
| 110 | 110 | foreach ($statement->fetchAll() as $row) { |
| 111 | 111 | $clone = clone $this->proto; |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | * @param array[] $eavMatch Additional `[eav property => attribute => mixed]` |
| 126 | 126 | * @return Select |
| 127 | 127 | */ |
| 128 | - public function find (array $match, array $eavMatch = []): Select { |
|
| 128 | + public function find(array $match, array $eavMatch = []): Select { |
|
| 129 | 129 | $select = $this->select(); |
| 130 | 130 | foreach ($match as $column => $value) { |
| 131 | 131 | $select->where($this->db->match($column, $value)); |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | /** |
| 141 | 141 | * @return string |
| 142 | 142 | */ |
| 143 | - final public function getClass (): string { |
|
| 143 | + final public function getClass(): string { |
|
| 144 | 144 | return $this->class; |
| 145 | 145 | } |
| 146 | 146 | |
@@ -148,14 +148,14 @@ discard block |
||
| 148 | 148 | * @param string $property |
| 149 | 149 | * @return EAV |
| 150 | 150 | */ |
| 151 | - final public function getEav (string $property): EAV { |
|
| 151 | + final public function getEav(string $property): EAV { |
|
| 152 | 152 | return $this->eav[$property]; |
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | /** |
| 156 | 156 | * @return EntityInterface |
| 157 | 157 | */ |
| 158 | - public function getProto (): EntityInterface { |
|
| 158 | + public function getProto(): EntityInterface { |
|
| 159 | 159 | return $this->proto; |
| 160 | 160 | } |
| 161 | 161 | |
@@ -163,7 +163,7 @@ discard block |
||
| 163 | 163 | * @param EntityInterface $entity |
| 164 | 164 | * @return array |
| 165 | 165 | */ |
| 166 | - protected function getValues (EntityInterface $entity): array { |
|
| 166 | + protected function getValues(EntityInterface $entity): array { |
|
| 167 | 167 | $values = []; |
| 168 | 168 | foreach (array_keys($this->columns) as $name) { |
| 169 | 169 | $values[$name] = $this->properties[$name]->getValue($entity); |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | * @param int $id |
| 178 | 178 | * @return null|EntityInterface |
| 179 | 179 | */ |
| 180 | - public function load (int $id): ?EntityInterface { |
|
| 180 | + public function load(int $id): ?EntityInterface { |
|
| 181 | 181 | $load = $this->cache(__FUNCTION__, function() { |
| 182 | 182 | return $this->select()->where('id = ?')->prepare(); |
| 183 | 183 | }); |
@@ -195,7 +195,7 @@ discard block |
||
| 195 | 195 | * |
| 196 | 196 | * @param EntityInterface[] $entities |
| 197 | 197 | */ |
| 198 | - protected function loadEav (array $entities): void { |
|
| 198 | + protected function loadEav(array $entities): void { |
|
| 199 | 199 | $ids = array_keys($entities); |
| 200 | 200 | foreach ($this->eav as $name => $eav) { |
| 201 | 201 | foreach ($eav->loadAll($ids) as $id => $values) { |
@@ -210,7 +210,7 @@ discard block |
||
| 210 | 210 | * @param EntityInterface $entity |
| 211 | 211 | * @return int ID |
| 212 | 212 | */ |
| 213 | - public function save (EntityInterface $entity): int { |
|
| 213 | + public function save(EntityInterface $entity): int { |
|
| 214 | 214 | if (!$entity->getId()) { |
| 215 | 215 | $this->saveInsert($entity); |
| 216 | 216 | } |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | /** |
| 225 | 225 | * @param EntityInterface $entity |
| 226 | 226 | */ |
| 227 | - protected function saveEav (EntityInterface $entity): void { |
|
| 227 | + protected function saveEav(EntityInterface $entity): void { |
|
| 228 | 228 | $id = $entity->getId(); |
| 229 | 229 | foreach ($this->eav as $name => $eav) { |
| 230 | 230 | $values = $this->properties[$name]->getValue($entity); |
@@ -239,7 +239,7 @@ discard block |
||
| 239 | 239 | * |
| 240 | 240 | * @param EntityInterface $entity |
| 241 | 241 | */ |
| 242 | - protected function saveInsert (EntityInterface $entity): void { |
|
| 242 | + protected function saveInsert(EntityInterface $entity): void { |
|
| 243 | 243 | $insert = $this->cache(__FUNCTION__, function() { |
| 244 | 244 | $slots = SQL::slots(array_keys($this->columns)); |
| 245 | 245 | unset($slots['id']); |
@@ -257,7 +257,7 @@ discard block |
||
| 257 | 257 | * |
| 258 | 258 | * @param EntityInterface $entity |
| 259 | 259 | */ |
| 260 | - protected function saveUpdate (EntityInterface $entity): void { |
|
| 260 | + protected function saveUpdate(EntityInterface $entity): void { |
|
| 261 | 261 | $this->cache(__FUNCTION__, function() { |
| 262 | 262 | $slots = SQL::slots(array_keys($this->columns)); |
| 263 | 263 | unset($slots['id']); |
@@ -272,7 +272,7 @@ discard block |
||
| 272 | 272 | * @param array $columns Defaults to all columns. |
| 273 | 273 | * @return Select |
| 274 | 274 | */ |
| 275 | - public function select (array $columns = []): Select { |
|
| 275 | + public function select(array $columns = []): Select { |
|
| 276 | 276 | return parent::select($columns)->setFetcher(function(Statement $statement) { |
| 277 | 277 | return $this->fetchAll($statement); |
| 278 | 278 | }); |
@@ -282,7 +282,7 @@ discard block |
||
| 282 | 282 | * @param EntityInterface $proto |
| 283 | 283 | * @return $this |
| 284 | 284 | */ |
| 285 | - public function setProto (EntityInterface $proto) { |
|
| 285 | + public function setProto(EntityInterface $proto) { |
|
| 286 | 286 | $this->proto = $proto; |
| 287 | 287 | return $this; |
| 288 | 288 | } |
@@ -291,7 +291,7 @@ discard block |
||
| 291 | 291 | * @param EntityInterface $entity |
| 292 | 292 | * @param array $values |
| 293 | 293 | */ |
| 294 | - protected function setValues (EntityInterface $entity, array $values): void { |
|
| 294 | + protected function setValues(EntityInterface $entity, array $values): void { |
|
| 295 | 295 | foreach ($values as $name => $value) { |
| 296 | 296 | settype($value, $this->types[$name]); |
| 297 | 297 | $this->properties[$name]->setValue($entity, $value); |
@@ -7,6 +7,6 @@ |
||
| 7 | 7 | */ |
| 8 | 8 | interface ExpressionInterface { |
| 9 | 9 | |
| 10 | - public function __toString (); |
|
| 10 | + public function __toString(); |
|
| 11 | 11 | |
| 12 | 12 | } |
| 13 | 13 | \ No newline at end of file |
@@ -86,11 +86,9 @@ discard block |
||
| 86 | 86 | $cmp[$k] = static::compare($k, $operator, $v, $subOperator, $listOperator); |
| 87 | 87 | } |
| 88 | 88 | return $cmp; |
| 89 | - } |
|
| 90 | - elseif (is_array($b)) { |
|
| 89 | + } elseif (is_array($b)) { |
|
| 91 | 90 | return "{$a} {$listOperator} (" . implode(',', $b) . ")"; |
| 92 | - } |
|
| 93 | - elseif ($b instanceof Select) { |
|
| 91 | + } elseif ($b instanceof Select) { |
|
| 94 | 92 | return "{$a} {$operator} {$subOperator} ({$b->toSql()})"; |
| 95 | 93 | } |
| 96 | 94 | return "{$a} {$operator} {$b}"; |
@@ -359,8 +357,7 @@ discard block |
||
| 359 | 357 | foreach ($columns as $alias => $name) { |
| 360 | 358 | if (is_string($alias) and $alias !== $name) { |
| 361 | 359 | $names[] = $name . ' AS ' . $alias; |
| 362 | - } |
|
| 363 | - else { |
|
| 360 | + } else { |
|
| 364 | 361 | $names[] = $name; |
| 365 | 362 | } |
| 366 | 363 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | * @param string[] $conditions |
| 18 | 18 | * @return string |
| 19 | 19 | */ |
| 20 | - public static function all (array $conditions): string { |
|
| 20 | + public static function all(array $conditions): string { |
|
| 21 | 21 | if (count($conditions) === 1) { |
| 22 | 22 | return reset($conditions); |
| 23 | 23 | } |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | * @param string[] $conditions |
| 31 | 31 | * @return string |
| 32 | 32 | */ |
| 33 | - public static function any (array $conditions): string { |
|
| 33 | + public static function any(array $conditions): string { |
|
| 34 | 34 | if (count($conditions) === 1) { |
| 35 | 35 | return reset($conditions); |
| 36 | 36 | } |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | * @param string $listOperator |
| 70 | 70 | * @return string|array |
| 71 | 71 | */ |
| 72 | - public static function compare ($a, $operator, $b = null, $subOperator = null, $listOperator = null) { |
|
| 72 | + public static function compare($a, $operator, $b = null, $subOperator = null, $listOperator = null) { |
|
| 73 | 73 | if (is_array($a)) { |
| 74 | 74 | $cmp = []; |
| 75 | 75 | foreach ($a as $k => $v) { |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | * @param array $columns |
| 94 | 94 | * @return string |
| 95 | 95 | */ |
| 96 | - public static function group (array $columns): string { |
|
| 96 | + public static function group(array $columns): string { |
|
| 97 | 97 | if (!empty($columns)) { |
| 98 | 98 | return ' GROUP BY ' . implode(',', $columns); |
| 99 | 99 | } |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | * @param array $conditions |
| 108 | 108 | * @return string |
| 109 | 109 | */ |
| 110 | - public static function having (array $conditions): string { |
|
| 110 | + public static function having(array $conditions): string { |
|
| 111 | 111 | if (!empty($conditions)) { |
| 112 | 112 | return ' HAVING ' . static::all($conditions); |
| 113 | 113 | } |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | * @param string|array|Select $b |
| 122 | 122 | * @return string|array |
| 123 | 123 | */ |
| 124 | - public static function isEqual ($a, $b = null) { |
|
| 124 | + public static function isEqual($a, $b = null) { |
|
| 125 | 125 | return static::compare($a, '=', $b, 'ANY', 'IN'); |
| 126 | 126 | } |
| 127 | 127 | |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | * @param string|Select $b |
| 133 | 133 | * @return string|array |
| 134 | 134 | */ |
| 135 | - public static function isGreater ($a, $b = null) { |
|
| 135 | + public static function isGreater($a, $b = null) { |
|
| 136 | 136 | return static::compare($a, '>', $b, 'ALL'); |
| 137 | 137 | } |
| 138 | 138 | |
@@ -143,7 +143,7 @@ discard block |
||
| 143 | 143 | * @param string|Select $b |
| 144 | 144 | * @return string|array |
| 145 | 145 | */ |
| 146 | - public static function isGreaterOrEqual ($a, $b = null) { |
|
| 146 | + public static function isGreaterOrEqual($a, $b = null) { |
|
| 147 | 147 | return static::compare($a, '>=', $b, 'ALL'); |
| 148 | 148 | } |
| 149 | 149 | |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | * @param string|Select $b |
| 155 | 155 | * @return string|array |
| 156 | 156 | */ |
| 157 | - public static function isLess ($a, $b = null) { |
|
| 157 | + public static function isLess($a, $b = null) { |
|
| 158 | 158 | return static::compare($a, '<', $b, 'ALL'); |
| 159 | 159 | } |
| 160 | 160 | |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | * @param string|Select $b |
| 166 | 166 | * @return string|array |
| 167 | 167 | */ |
| 168 | - public static function isLessOrEqual ($a, $b = null) { |
|
| 168 | + public static function isLessOrEqual($a, $b = null) { |
|
| 169 | 169 | return static::compare($a, '<=', $b, 'ALL'); |
| 170 | 170 | } |
| 171 | 171 | |
@@ -176,7 +176,7 @@ discard block |
||
| 176 | 176 | * @param string $pattern |
| 177 | 177 | * @return string|array |
| 178 | 178 | */ |
| 179 | - public static function isLike ($x, string $pattern = null) { |
|
| 179 | + public static function isLike($x, string $pattern = null) { |
|
| 180 | 180 | return static::compare($x, 'LIKE', $pattern); |
| 181 | 181 | } |
| 182 | 182 | |
@@ -187,7 +187,7 @@ discard block |
||
| 187 | 187 | * @param null|bool $identity |
| 188 | 188 | * @return string|array |
| 189 | 189 | */ |
| 190 | - public static function isNot ($x, $identity) { |
|
| 190 | + public static function isNot($x, $identity) { |
|
| 191 | 191 | return static::compare($x, 'IS NOT', ['' => 'UNKNOWN', 1 => 'TRUE', 0 => 'FALSE'][$identity]); |
| 192 | 192 | } |
| 193 | 193 | |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | * @param string|array|Select $b |
| 199 | 199 | * @return string|array |
| 200 | 200 | */ |
| 201 | - public static function isNotEqual ($a, $b = null) { |
|
| 201 | + public static function isNotEqual($a, $b = null) { |
|
| 202 | 202 | return static::compare($a, '<>', $b, 'ALL', 'NOT IN'); |
| 203 | 203 | } |
| 204 | 204 | |
@@ -209,7 +209,7 @@ discard block |
||
| 209 | 209 | * @param string $pattern |
| 210 | 210 | * @return string|array |
| 211 | 211 | */ |
| 212 | - public static function isNotLike ($x, string $pattern = null) { |
|
| 212 | + public static function isNotLike($x, string $pattern = null) { |
|
| 213 | 213 | return static::compare($x, 'NOT LIKE', $pattern); |
| 214 | 214 | } |
| 215 | 215 | |
@@ -219,7 +219,7 @@ discard block |
||
| 219 | 219 | * @param string|array $x |
| 220 | 220 | * @return string|array |
| 221 | 221 | */ |
| 222 | - public static function isNotNull ($x) { |
|
| 222 | + public static function isNotNull($x) { |
|
| 223 | 223 | if (is_array($x)) { |
| 224 | 224 | return array_map(__METHOD__, $x); |
| 225 | 225 | } |
@@ -233,7 +233,7 @@ discard block |
||
| 233 | 233 | * @param string $pattern |
| 234 | 234 | * @return string|array |
| 235 | 235 | */ |
| 236 | - public static function isNotRegExp ($x, string $pattern = null) { |
|
| 236 | + public static function isNotRegExp($x, string $pattern = null) { |
|
| 237 | 237 | return static::compare($x, 'NOT REGEXP', $pattern); |
| 238 | 238 | } |
| 239 | 239 | |
@@ -244,7 +244,7 @@ discard block |
||
| 244 | 244 | * @param string $pattern |
| 245 | 245 | * @return string|array |
| 246 | 246 | */ |
| 247 | - public static function isRegExp ($x, string $pattern = null) { |
|
| 247 | + public static function isRegExp($x, string $pattern = null) { |
|
| 248 | 248 | return static::compare($x, 'REGEXP', $pattern); |
| 249 | 249 | } |
| 250 | 250 | |
@@ -256,7 +256,7 @@ discard block |
||
| 256 | 256 | * @param int $offset |
| 257 | 257 | * @return string |
| 258 | 258 | */ |
| 259 | - public static function limit (int $limit, int $offset = 0): string { |
|
| 259 | + public static function limit(int $limit, int $offset = 0): string { |
|
| 260 | 260 | if ($limit) { |
| 261 | 261 | $limit = " LIMIT {$limit}"; |
| 262 | 262 | if ($offset) { |
@@ -273,7 +273,7 @@ discard block |
||
| 273 | 273 | * @param int|array|Countable $count |
| 274 | 274 | * @return string[] |
| 275 | 275 | */ |
| 276 | - public static function marks ($count): array { |
|
| 276 | + public static function marks($count): array { |
|
| 277 | 277 | if (is_array($count) or $count instanceof Countable) { |
| 278 | 278 | $count = count($count); |
| 279 | 279 | } |
@@ -286,7 +286,7 @@ discard block |
||
| 286 | 286 | * @param string|array $x |
| 287 | 287 | * @return string|array |
| 288 | 288 | */ |
| 289 | - public static function not ($x) { |
|
| 289 | + public static function not($x) { |
|
| 290 | 290 | if (is_array($x)) { |
| 291 | 291 | return array_map(__METHOD__, $x); |
| 292 | 292 | } |
@@ -300,7 +300,7 @@ discard block |
||
| 300 | 300 | * @param string $order |
| 301 | 301 | * @return string |
| 302 | 302 | */ |
| 303 | - public static function order (string $order): string { |
|
| 303 | + public static function order(string $order): string { |
|
| 304 | 304 | if (strlen($order)) { |
| 305 | 305 | return ' ORDER BY ' . $order; |
| 306 | 306 | } |
@@ -314,7 +314,7 @@ discard block |
||
| 314 | 314 | * @param array $columns String keys are used for aliasing. |
| 315 | 315 | * @return string |
| 316 | 316 | */ |
| 317 | - public static function select (string $table, array $columns): string { |
|
| 317 | + public static function select(string $table, array $columns): string { |
|
| 318 | 318 | $names = []; |
| 319 | 319 | foreach ($columns as $alias => $name) { |
| 320 | 320 | if (is_string($alias) and $alias !== $name) { |
@@ -335,7 +335,7 @@ discard block |
||
| 335 | 335 | * @param string[] $columns |
| 336 | 336 | * @return string[] `[column => :column]` |
| 337 | 337 | */ |
| 338 | - public static function slots (array $columns): array { |
|
| 338 | + public static function slots(array $columns): array { |
|
| 339 | 339 | $slots = []; |
| 340 | 340 | foreach ($columns as $column) { |
| 341 | 341 | $slots[(string)$column] = ':' . str_replace('.', '__', $column); |
@@ -350,12 +350,12 @@ discard block |
||
| 350 | 350 | * @param array $conditions |
| 351 | 351 | * @return string |
| 352 | 352 | */ |
| 353 | - public static function where (array $conditions): string { |
|
| 353 | + public static function where(array $conditions): string { |
|
| 354 | 354 | if (!empty($conditions)) { |
| 355 | 355 | return ' WHERE ' . static::all($conditions); |
| 356 | 356 | } |
| 357 | 357 | return ''; |
| 358 | 358 | } |
| 359 | 359 | |
| 360 | - final private function __construct () { } |
|
| 360 | + final private function __construct() { } |
|
| 361 | 361 | } |
| 362 | 362 | \ No newline at end of file |