@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | * @param string $passwd |
| 46 | 46 | * @param array $options |
| 47 | 47 | */ |
| 48 | - public function __construct ($dsn, $username = null, $passwd = null, $options = null) { |
|
| 48 | + public function __construct($dsn, $username = null, $passwd = null, $options = null) { |
|
| 49 | 49 | /** @scrutinizer ignore-call */ |
| 50 | 50 | parent::__construct(...func_get_args()); |
| 51 | 51 | $this->setAttribute(self::ATTR_DEFAULT_FETCH_MODE, self::FETCH_ASSOC); |
@@ -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 | } |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | * @param mixed $b |
| 128 | 128 | * @return string |
| 129 | 129 | */ |
| 130 | - public function match ($a, $b = null) { |
|
| 130 | + public function match($a, $b = null) { |
|
| 131 | 131 | if (is_int($a) and is_string($b)) { |
| 132 | 132 | return $b; |
| 133 | 133 | } |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | * @param array $match |
| 151 | 151 | * @return string[] |
| 152 | 152 | */ |
| 153 | - public function matchArray (array $match) { |
|
| 153 | + public function matchArray(array $match) { |
|
| 154 | 154 | return array_map([$this, 'match'], array_keys($match), $match); |
| 155 | 155 | } |
| 156 | 156 | |
@@ -162,7 +162,7 @@ discard block |
||
| 162 | 162 | * @param mixed $match |
| 163 | 163 | * @return string|string[] |
| 164 | 164 | */ |
| 165 | - public function matchMixed ($match) { |
|
| 165 | + public function matchMixed($match) { |
|
| 166 | 166 | if (is_array($match)) { |
| 167 | 167 | return $this->matchArray($match); |
| 168 | 168 | } |
@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | * @param string $access Class or interface name. |
| 174 | 174 | * @return bool |
| 175 | 175 | */ |
| 176 | - public function offsetExists ($access): bool { |
|
| 176 | + public function offsetExists($access): bool { |
|
| 177 | 177 | return (bool)$this->offsetGet($access); |
| 178 | 178 | } |
| 179 | 179 | |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | * @param string $access Class or interface name. |
| 182 | 182 | * @return Record|Junction|null |
| 183 | 183 | */ |
| 184 | - public function offsetGet ($access) { |
|
| 184 | + public function offsetGet($access) { |
|
| 185 | 185 | if (class_exists($access)) { |
| 186 | 186 | return $this->getRecord($access); |
| 187 | 187 | } |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | * @param void $value |
| 199 | 199 | * @throws Exception |
| 200 | 200 | */ |
| 201 | - final public function offsetSet ($access, $value): void { |
|
| 201 | + final public function offsetSet($access, $value): void { |
|
| 202 | 202 | throw new Exception('The schema is immutable.'); |
| 203 | 203 | } |
| 204 | 204 | |
@@ -208,7 +208,7 @@ discard block |
||
| 208 | 208 | * @param void $access |
| 209 | 209 | * @throws Exception |
| 210 | 210 | */ |
| 211 | - final public function offsetUnset ($access): void { |
|
| 211 | + final public function offsetUnset($access): void { |
|
| 212 | 212 | $this->offsetSet($access, null); |
| 213 | 213 | } |
| 214 | 214 | |
@@ -219,7 +219,7 @@ discard block |
||
| 219 | 219 | * @param array $options |
| 220 | 220 | * @return Statement |
| 221 | 221 | */ |
| 222 | - public function prepare ($sql, $options = null): Statement { |
|
| 222 | + public function prepare($sql, $options = null): Statement { |
|
| 223 | 223 | $this->logger->__invoke($sql); |
| 224 | 224 | /** @var Statement $statement */ |
| 225 | 225 | /** @scrutinizer ignore-call */ |
@@ -236,7 +236,7 @@ discard block |
||
| 236 | 236 | * @param array $ctorargs |
| 237 | 237 | * @return Statement |
| 238 | 238 | */ |
| 239 | - public function query ($sql, $mode = PDO::ATTR_DEFAULT_FETCH_MODE, $arg3 = null, array $ctorargs = []): Statement { |
|
| 239 | + public function query($sql, $mode = PDO::ATTR_DEFAULT_FETCH_MODE, $arg3 = null, array $ctorargs = []): Statement { |
|
| 240 | 240 | $this->logger->__invoke($sql); |
| 241 | 241 | /** @var Statement $statement */ |
| 242 | 242 | /** @scrutinizer ignore-call */ |
@@ -256,7 +256,7 @@ discard block |
||
| 256 | 256 | * @param int $type Ignored. |
| 257 | 257 | * @return string |
| 258 | 258 | */ |
| 259 | - public function quote ($value, $type = null) { |
|
| 259 | + public function quote($value, $type = null) { |
|
| 260 | 260 | if ($value instanceof ExpressionInterface) { |
| 261 | 261 | return $value; |
| 262 | 262 | } |
@@ -276,7 +276,7 @@ discard block |
||
| 276 | 276 | * @param array $values |
| 277 | 277 | * @return array |
| 278 | 278 | */ |
| 279 | - public function quoteArray (array $values): array { |
|
| 279 | + public function quoteArray(array $values): array { |
|
| 280 | 280 | return array_map([$this, 'quote'], $values); |
| 281 | 281 | } |
| 282 | 282 | |
@@ -286,7 +286,7 @@ discard block |
||
| 286 | 286 | * @param mixed $value |
| 287 | 287 | * @return array|string |
| 288 | 288 | */ |
| 289 | - public function quoteMixed ($value) { |
|
| 289 | + public function quoteMixed($value) { |
|
| 290 | 290 | if (is_array($value)) { |
| 291 | 291 | return $this->quoteArray($value); |
| 292 | 292 | } |
@@ -299,7 +299,7 @@ discard block |
||
| 299 | 299 | * @param EntityInterface $entity |
| 300 | 300 | * @return int ID |
| 301 | 301 | */ |
| 302 | - public function save (EntityInterface $entity): int { |
|
| 302 | + public function save(EntityInterface $entity): int { |
|
| 303 | 303 | return $this->getRecord($entity)->save($entity); |
| 304 | 304 | } |
| 305 | 305 | |
@@ -307,7 +307,7 @@ discard block |
||
| 307 | 307 | * @param Closure $logger |
| 308 | 308 | * @return $this |
| 309 | 309 | */ |
| 310 | - public function setLogger (Closure $logger) { |
|
| 310 | + public function setLogger(Closure $logger) { |
|
| 311 | 311 | $this->logger = $logger; |
| 312 | 312 | return $this; |
| 313 | 313 | } |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | * @param string|Select $table |
| 80 | 80 | * @param string[] $columns |
| 81 | 81 | */ |
| 82 | - public function __construct (DB $db, $table, array $columns) { |
|
| 82 | + public function __construct(DB $db, $table, array $columns) { |
|
| 83 | 83 | parent::__construct($db); |
| 84 | 84 | if ($table instanceof Select) { |
| 85 | 85 | $table = $table->toSubquery(); |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | /** |
| 96 | 96 | * Gives the clone a new alias. |
| 97 | 97 | */ |
| 98 | - public function __clone () { |
|
| 98 | + public function __clone() { |
|
| 99 | 99 | $this->alias = uniqid('_') . "__{$this->table}"; |
| 100 | 100 | } |
| 101 | 101 | |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | * @param array $args |
| 104 | 104 | * @return Statement |
| 105 | 105 | */ |
| 106 | - public function __invoke (array $args = []): Statement { |
|
| 106 | + public function __invoke(array $args = []): Statement { |
|
| 107 | 107 | return $this->execute($args); |
| 108 | 108 | } |
| 109 | 109 | |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | * |
| 113 | 113 | * @return string |
| 114 | 114 | */ |
| 115 | - public function __toString (): string { |
|
| 115 | + public function __toString(): string { |
|
| 116 | 116 | return $this->alias; |
| 117 | 117 | } |
| 118 | 118 | |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | * @param array $args Execution arguments. |
| 123 | 123 | * @return int |
| 124 | 124 | */ |
| 125 | - public function count (array $args = []): int { |
|
| 125 | + public function count(array $args = []): int { |
|
| 126 | 126 | $clone = clone $this; |
| 127 | 127 | $clone->columns = ['COUNT(*)']; |
| 128 | 128 | return (int)$clone->execute($args)->fetchColumn(); |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | * @param array $args |
| 135 | 135 | * @return Statement |
| 136 | 136 | */ |
| 137 | - public function execute (array $args = []): Statement { |
|
| 137 | + public function execute(array $args = []): Statement { |
|
| 138 | 138 | if (!empty($args)) { |
| 139 | 139 | return $this->prepare()($args); |
| 140 | 140 | } |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | * @param array $args Execution arguments. |
| 150 | 150 | * @return array |
| 151 | 151 | */ |
| 152 | - public function fetchAll (array $args = []): array { |
|
| 152 | + public function fetchAll(array $args = []): array { |
|
| 153 | 153 | return $this->fetcher->__invoke($this->execute($args)); |
| 154 | 154 | } |
| 155 | 155 | |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | * |
| 161 | 161 | * @return ArrayIterator |
| 162 | 162 | */ |
| 163 | - public function getIterator () { |
|
| 163 | + public function getIterator() { |
|
| 164 | 164 | return new ArrayIterator($this->fetchAll()); |
| 165 | 165 | } |
| 166 | 166 | |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | * @param string $column |
| 171 | 171 | * @return $this |
| 172 | 172 | */ |
| 173 | - public function group (string $column) { |
|
| 173 | + public function group(string $column) { |
|
| 174 | 174 | $this->_group[] = $column; |
| 175 | 175 | return $this; |
| 176 | 176 | } |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | * @param string $condition |
| 182 | 182 | * @return $this |
| 183 | 183 | */ |
| 184 | - public function having (string $condition) { |
|
| 184 | + public function having(string $condition) { |
|
| 185 | 185 | $this->_having[] = $condition; |
| 186 | 186 | return $this; |
| 187 | 187 | } |
@@ -194,7 +194,7 @@ discard block |
||
| 194 | 194 | * @param string $type |
| 195 | 195 | * @return $this |
| 196 | 196 | */ |
| 197 | - public function join ($table, string $condition, string $type = 'INNER') { |
|
| 197 | + public function join($table, string $condition, string $type = 'INNER') { |
|
| 198 | 198 | if ($table instanceof Select) { |
| 199 | 199 | $table = $table->toSubquery(); |
| 200 | 200 | } |
@@ -209,7 +209,7 @@ discard block |
||
| 209 | 209 | * @param int $offset |
| 210 | 210 | * @return $this |
| 211 | 211 | */ |
| 212 | - public function limit (int $limit, int $offset = 0) { |
|
| 212 | + public function limit(int $limit, int $offset = 0) { |
|
| 213 | 213 | $this->_limit = $limit; |
| 214 | 214 | $this->_offset = $offset; |
| 215 | 215 | return $this; |
@@ -221,7 +221,7 @@ discard block |
||
| 221 | 221 | * @param string $name Name or alias if used. |
| 222 | 222 | * @return bool |
| 223 | 223 | */ |
| 224 | - public function offsetExists ($name): bool { |
|
| 224 | + public function offsetExists($name): bool { |
|
| 225 | 225 | return true; |
| 226 | 226 | } |
| 227 | 227 | |
@@ -231,7 +231,7 @@ discard block |
||
| 231 | 231 | * @param string $name Name, or alias if used. |
| 232 | 232 | * @return Column |
| 233 | 233 | */ |
| 234 | - public function offsetGet ($name): Column { |
|
| 234 | + public function offsetGet($name): Column { |
|
| 235 | 235 | return new Column($this->db, $name, $this->alias); |
| 236 | 236 | } |
| 237 | 237 | |
@@ -241,7 +241,7 @@ discard block |
||
| 241 | 241 | * @param string $order |
| 242 | 242 | * @return $this |
| 243 | 243 | */ |
| 244 | - public function order (string $order) { |
|
| 244 | + public function order(string $order) { |
|
| 245 | 245 | $this->_order = $order; |
| 246 | 246 | return $this; |
| 247 | 247 | } |
@@ -249,7 +249,7 @@ discard block |
||
| 249 | 249 | /** |
| 250 | 250 | * @return Statement |
| 251 | 251 | */ |
| 252 | - public function prepare (): Statement { |
|
| 252 | + public function prepare(): Statement { |
|
| 253 | 253 | return $this->db->prepare($this->toSql()); |
| 254 | 254 | } |
| 255 | 255 | |
@@ -257,7 +257,7 @@ discard block |
||
| 257 | 257 | * @param Closure $fetcher |
| 258 | 258 | * @return $this |
| 259 | 259 | */ |
| 260 | - public function setFetcher (Closure $fetcher) { |
|
| 260 | + public function setFetcher(Closure $fetcher) { |
|
| 261 | 261 | $this->fetcher = $fetcher; |
| 262 | 262 | return $this; |
| 263 | 263 | } |
@@ -265,7 +265,7 @@ discard block |
||
| 265 | 265 | /** |
| 266 | 266 | * @return string |
| 267 | 267 | */ |
| 268 | - public function toSql (): string { |
|
| 268 | + public function toSql(): string { |
|
| 269 | 269 | $sql = SQL::select($this->table, $this->columns); |
| 270 | 270 | foreach ($this->_join as $join) { |
| 271 | 271 | $sql .= " {$join}"; |
@@ -283,7 +283,7 @@ discard block |
||
| 283 | 283 | * |
| 284 | 284 | * @return string |
| 285 | 285 | */ |
| 286 | - public function toSubquery (): string { |
|
| 286 | + public function toSubquery(): string { |
|
| 287 | 287 | return "({$this->toSql()}) AS {$this->alias}"; |
| 288 | 288 | } |
| 289 | 289 | |
@@ -293,7 +293,7 @@ discard block |
||
| 293 | 293 | * @param string $condition |
| 294 | 294 | * @return $this |
| 295 | 295 | */ |
| 296 | - public function where (string $condition) { |
|
| 296 | + public function where(string $condition) { |
|
| 297 | 297 | $this->_where[] = $condition; |
| 298 | 298 | return $this; |
| 299 | 299 | } |
@@ -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); |
@@ -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->matchArray($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 Statement |
| 82 | 82 | */ |
| 83 | - public function insert (array $values): Statement { |
|
| 83 | + public function insert(array $values): Statement { |
|
| 84 | 84 | $columns = implode(',', array_keys($values)); |
| 85 | 85 | $values = implode(', ', $this->db->quoteArray($values)); |
| 86 | 86 | return $this->db->query("INSERT INTO {$this} ($columns) VALUES ($values)"); |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | * @param string $name |
| 91 | 91 | * @return bool |
| 92 | 92 | */ |
| 93 | - public function offsetExists ($name): bool { |
|
| 93 | + public function offsetExists($name): bool { |
|
| 94 | 94 | return isset($this->columns[$name]); |
| 95 | 95 | } |
| 96 | 96 | |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | * @param string $name |
| 99 | 99 | * @return Column |
| 100 | 100 | */ |
| 101 | - public function offsetGet ($name): Column { |
|
| 101 | + public function offsetGet($name): Column { |
|
| 102 | 102 | return $this->columns[$name]; |
| 103 | 103 | } |
| 104 | 104 | |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | * @param string[] $columns Defaults to all columns. |
| 109 | 109 | * @return Select |
| 110 | 110 | */ |
| 111 | - public function select (array $columns = []): Select { |
|
| 111 | + public function select(array $columns = []): Select { |
|
| 112 | 112 | if (!$columns) { |
| 113 | 113 | $columns = $this->columns; |
| 114 | 114 | } |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | * @param string $name |
| 122 | 122 | * @return Table |
| 123 | 123 | */ |
| 124 | - public function setName (string $name) { |
|
| 124 | + public function setName(string $name) { |
|
| 125 | 125 | $clone = clone $this; |
| 126 | 126 | $clone->name = $name; |
| 127 | 127 | foreach ($this->columns as $name => $column) { |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | * @param array $match |
| 140 | 140 | * @return int Rows affected. |
| 141 | 141 | */ |
| 142 | - public function update (array $values, array $match): int { |
|
| 142 | + public function update(array $values, array $match): int { |
|
| 143 | 143 | $values = implode(', ', SQL::isEqual($this->db->quoteArray($values))); |
| 144 | 144 | $match = SQL::all($this->db->matchArray($match)); |
| 145 | 145 | 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 | $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}"); |
@@ -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 | $count = $this->cache(__FUNCTION__, function() { |
| 34 | 34 | return $this->select(['COUNT(*)'])->where('entity=?')->prepare(); |
| 35 | 35 | }); |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | * @param string $attribute |
| 44 | 44 | * @return bool |
| 45 | 45 | */ |
| 46 | - public function exists (int $id, string $attribute): bool { |
|
| 46 | + public function exists(int $id, string $attribute): bool { |
|
| 47 | 47 | $exists = $this->cache(__FUNCTION__, function() { |
| 48 | 48 | return $this->select(['COUNT(*) > 0'])->where('entity = ? AND attribute = ?')->prepare(); |
| 49 | 49 | }); |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | * @param array $match `[attribute => value]`. If empty, selects all IDs for entities having at least one attribute. |
| 60 | 60 | * @return Select |
| 61 | 61 | */ |
| 62 | - public function find (array $match): Select { |
|
| 62 | + public function find(array $match): Select { |
|
| 63 | 63 | $select = $this->select([$this['entity']]); |
| 64 | 64 | $prior = $this; |
| 65 | 65 | foreach ($match as $attribute => $value) { |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | * @param int $id |
| 82 | 82 | * @return array `[attribute => value]` |
| 83 | 83 | */ |
| 84 | - public function load (int $id): array { |
|
| 84 | + public function load(int $id): array { |
|
| 85 | 85 | $load = $this->cache(__FUNCTION__, function() { |
| 86 | 86 | return $this->select(['attribute', 'value'])->where('entity = ?')->prepare(); |
| 87 | 87 | }); |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | * @param int[] $ids |
| 95 | 95 | * @return array[] `[id => attribute => value] |
| 96 | 96 | */ |
| 97 | - public function loadAll (array $ids): array { |
|
| 97 | + public function loadAll(array $ids): array { |
|
| 98 | 98 | if (count($ids) === 1) { |
| 99 | 99 | return [current($ids) => $this->load(current($ids))]; |
| 100 | 100 | } |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | * @param array $values `[attribute => value]` |
| 115 | 115 | * @return $this |
| 116 | 116 | */ |
| 117 | - public function save (int $id, array $values) { |
|
| 117 | + public function save(int $id, array $values) { |
|
| 118 | 118 | $this->delete([ |
| 119 | 119 | $this['entity']->isEqual($id), |
| 120 | 120 | $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 | |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | * @param array $args |
| 32 | 32 | * @return $this |
| 33 | 33 | */ |
| 34 | - public function __invoke (array $args = null) { |
|
| 34 | + public function __invoke(array $args = null) { |
|
| 35 | 35 | $this->execute($args); |
| 36 | 36 | return $this; |
| 37 | 37 | } |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | * |
| 42 | 42 | * @return string |
| 43 | 43 | */ |
| 44 | - public function __toString () { |
|
| 44 | + public function __toString() { |
|
| 45 | 45 | return $this->queryString; |
| 46 | 46 | } |
| 47 | 47 | |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | * @return bool |
| 55 | 55 | * @throws ArgumentCountError |
| 56 | 56 | */ |
| 57 | - public function execute ($args = null) { |
|
| 57 | + public function execute($args = null) { |
|
| 58 | 58 | $this->db->getLogger()->__invoke($this->queryString); |
| 59 | 59 | if ($result = !parent::execute($args)) { |
| 60 | 60 | $info = $this->errorInfo(); |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | * |
| 72 | 72 | * @return int |
| 73 | 73 | */ |
| 74 | - public function getId (): int { |
|
| 74 | + public function getId(): int { |
|
| 75 | 75 | return (int)$this->db->lastInsertId(); |
| 76 | 76 | } |
| 77 | 77 | } |
@@ -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; |