@@ -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()->execute($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 | } |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | * @param array $arguments |
| 29 | 29 | * @return ExpressionInterface |
| 30 | 30 | */ |
| 31 | - public static function __callStatic (string $name, array $arguments): ExpressionInterface { |
|
| 31 | + public static function __callStatic(string $name, array $arguments): ExpressionInterface { |
|
| 32 | 32 | $arguments = implode(' ', $arguments); |
| 33 | 33 | $name = strtoupper(preg_replace('/(?<!^)[A-Z]/', '_$0', $name)); |
| 34 | 34 | return new static("{$name}({$arguments})"); |
@@ -37,14 +37,14 @@ discard block |
||
| 37 | 37 | /** |
| 38 | 38 | * @param string $string |
| 39 | 39 | */ |
| 40 | - public function __construct (string $string) { |
|
| 40 | + public function __construct(string $string) { |
|
| 41 | 41 | $this->string = $string; |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | /** |
| 45 | 45 | * @return string |
| 46 | 46 | */ |
| 47 | - public function __toString () { |
|
| 47 | + public function __toString() { |
|
| 48 | 48 | return $this->string; |
| 49 | 49 | } |
| 50 | 50 | } |
| 51 | 51 | \ No newline at end of file |
@@ -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 (int)$this->db->lastInsertId(); |
| 66 | 66 | } |
| 67 | 67 | } |
@@ -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((array)$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 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(',', (array)$this->db->quote($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(', ', (array)SQL::isEqual($this->db->quote($values))); |
| 144 | 144 | $match = SQL::all((array)$this->db->match($match)); |
| 145 | 145 | return $this->db->exec("UPDATE {$this} SET {$values} WHERE {$match}"); |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | * @param string $passwd |
| 47 | 47 | * @param array $options |
| 48 | 48 | */ |
| 49 | - public function __construct ($dsn, $username = null, $passwd = null, $options = null) { |
|
| 49 | + public function __construct($dsn, $username = null, $passwd = null, $options = null) { |
|
| 50 | 50 | /** @scrutinizer ignore-call */ |
| 51 | 51 | parent::__construct(...func_get_args()); |
| 52 | 52 | $this->setAttribute(self::ATTR_DEFAULT_FETCH_MODE, self::FETCH_ASSOC); |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | * @param string $sql |
| 64 | 64 | * @return int |
| 65 | 65 | */ |
| 66 | - public function exec ($sql): int { |
|
| 66 | + public function exec($sql): int { |
|
| 67 | 67 | $this->logger->__invoke($sql); |
| 68 | 68 | return parent::exec($sql); |
| 69 | 69 | } |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | * |
| 74 | 74 | * @return string |
| 75 | 75 | */ |
| 76 | - final public function getDriver (): string { |
|
| 76 | + final public function getDriver(): string { |
|
| 77 | 77 | return $this->getAttribute(self::ATTR_DRIVER_NAME); |
| 78 | 78 | } |
| 79 | 79 | |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | * @param string $interface |
| 84 | 84 | * @return Junction |
| 85 | 85 | */ |
| 86 | - public function getJunction ($interface): Junction { |
|
| 86 | + public function getJunction($interface): Junction { |
|
| 87 | 87 | if (!isset($this->junctions[$interface])) { |
| 88 | 88 | $this->junctions[$interface] = new Junction($this, $interface); |
| 89 | 89 | } |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | /** |
| 94 | 94 | * @return Closure |
| 95 | 95 | */ |
| 96 | - public function getLogger (): Closure { |
|
| 96 | + public function getLogger(): Closure { |
|
| 97 | 97 | return $this->logger; |
| 98 | 98 | } |
| 99 | 99 | |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | * @param string|EntityInterface $class |
| 104 | 104 | * @return Record |
| 105 | 105 | */ |
| 106 | - public function getRecord ($class): Record { |
|
| 106 | + public function getRecord($class): Record { |
|
| 107 | 107 | if (is_object($class)) { |
| 108 | 108 | $class = get_class($class); |
| 109 | 109 | } |
@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | * @param string|array|Select|Closure $b |
| 136 | 136 | * @return string|string[] Same type as `$a`, keys are not preserved. |
| 137 | 137 | */ |
| 138 | - public function match ($a, $b = null) { |
|
| 138 | + public function match($a, $b = null) { |
|
| 139 | 139 | if (is_array($a)) { |
| 140 | 140 | return array_map([$this, __FUNCTION__], array_keys($a), $a); |
| 141 | 141 | } |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | * @param string $access Class or interface name. |
| 153 | 153 | * @return bool |
| 154 | 154 | */ |
| 155 | - public function offsetExists ($access): bool { |
|
| 155 | + public function offsetExists($access): bool { |
|
| 156 | 156 | return (bool)$this->offsetGet($access); |
| 157 | 157 | } |
| 158 | 158 | |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | * @param string $access Class or interface name. |
| 161 | 161 | * @return Record|Junction|null |
| 162 | 162 | */ |
| 163 | - public function offsetGet ($access) { |
|
| 163 | + public function offsetGet($access) { |
|
| 164 | 164 | if (class_exists($access)) { |
| 165 | 165 | return $this->getRecord($access); |
| 166 | 166 | } |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | * @param void $value |
| 178 | 178 | * @throws Exception |
| 179 | 179 | */ |
| 180 | - final public function offsetSet ($access, $value): void { |
|
| 180 | + final public function offsetSet($access, $value): void { |
|
| 181 | 181 | throw new Exception('The schema is immutable.'); |
| 182 | 182 | } |
| 183 | 183 | |
@@ -187,7 +187,7 @@ discard block |
||
| 187 | 187 | * @param void $access |
| 188 | 188 | * @throws Exception |
| 189 | 189 | */ |
| 190 | - final public function offsetUnset ($access): void { |
|
| 190 | + final public function offsetUnset($access): void { |
|
| 191 | 191 | $this->offsetSet($access, null); |
| 192 | 192 | } |
| 193 | 193 | |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | * @param array $options |
| 199 | 199 | * @return Statement |
| 200 | 200 | */ |
| 201 | - public function prepare ($sql, $options = null): Statement { |
|
| 201 | + public function prepare($sql, $options = null): Statement { |
|
| 202 | 202 | $this->logger->__invoke($sql); |
| 203 | 203 | /** @var Statement $statement */ |
| 204 | 204 | /** @scrutinizer ignore-call */ |
@@ -215,7 +215,7 @@ discard block |
||
| 215 | 215 | * @param array $ctorargs |
| 216 | 216 | * @return Statement |
| 217 | 217 | */ |
| 218 | - public function query ($sql, $mode = PDO::ATTR_DEFAULT_FETCH_MODE, $arg3 = null, array $ctorargs = []): Statement { |
|
| 218 | + public function query($sql, $mode = PDO::ATTR_DEFAULT_FETCH_MODE, $arg3 = null, array $ctorargs = []): Statement { |
|
| 219 | 219 | $this->logger->__invoke($sql); |
| 220 | 220 | /** @var Statement $statement */ |
| 221 | 221 | /** @scrutinizer ignore-call */ |
@@ -236,7 +236,7 @@ discard block |
||
| 236 | 236 | * @param int $type Ignored. |
| 237 | 237 | * @return mixed |
| 238 | 238 | */ |
| 239 | - public function quote ($value, $type = null) { |
|
| 239 | + public function quote($value, $type = null) { |
|
| 240 | 240 | if ($value instanceof ExpressionInterface) { |
| 241 | 241 | return $value; |
| 242 | 242 | } |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | * @param EntityInterface $entity |
| 259 | 259 | * @return int ID |
| 260 | 260 | */ |
| 261 | - public function save (EntityInterface $entity): int { |
|
| 261 | + public function save(EntityInterface $entity): int { |
|
| 262 | 262 | return $this->getRecord($entity)->save($entity); |
| 263 | 263 | } |
| 264 | 264 | |
@@ -266,7 +266,7 @@ discard block |
||
| 266 | 266 | * @param Closure $logger |
| 267 | 267 | * @return $this |
| 268 | 268 | */ |
| 269 | - public function setLogger (Closure $logger) { |
|
| 269 | + public function setLogger(Closure $logger) { |
|
| 270 | 270 | $this->logger = $logger; |
| 271 | 271 | return $this; |
| 272 | 272 | } |