@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | * @param string|Select $table |
| 74 | 74 | * @param string[] $columns |
| 75 | 75 | */ |
| 76 | - public function __construct (DB $db, $table, array $columns) { |
|
| 76 | + public function __construct(DB $db, $table, array $columns) { |
|
| 77 | 77 | parent::__construct($db); |
| 78 | 78 | if ($table instanceof Select) { |
| 79 | 79 | $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 | - final public function __toString () { |
|
| 115 | + final public function __toString() { |
|
| 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 | if (!strlen($this->_group)) { |
| 175 | 175 | $this->_group = " GROUP BY {$column}"; |
| 176 | 176 | } |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | * @param string $condition |
| 187 | 187 | * @return $this |
| 188 | 188 | */ |
| 189 | - public function having (string $condition) { |
|
| 189 | + public function having(string $condition) { |
|
| 190 | 190 | if (!strlen($this->_having)) { |
| 191 | 191 | $this->_having = " HAVING {$condition}"; |
| 192 | 192 | } |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | * @param string $type |
| 205 | 205 | * @return $this |
| 206 | 206 | */ |
| 207 | - public function join ($table, string $condition, string $type = 'INNER') { |
|
| 207 | + public function join($table, string $condition, string $type = 'INNER') { |
|
| 208 | 208 | if ($table instanceof Select) { |
| 209 | 209 | $table = $table->toSubquery(); |
| 210 | 210 | } |
@@ -219,7 +219,7 @@ discard block |
||
| 219 | 219 | * @param int $offset |
| 220 | 220 | * @return $this |
| 221 | 221 | */ |
| 222 | - public function limit (int $limit, int $offset = 0) { |
|
| 222 | + public function limit(int $limit, int $offset = 0) { |
|
| 223 | 223 | if ($limit == 0) { |
| 224 | 224 | $this->_limit = ''; |
| 225 | 225 | } |
@@ -238,7 +238,7 @@ discard block |
||
| 238 | 238 | * @param string $name Name or alias if used. |
| 239 | 239 | * @return bool |
| 240 | 240 | */ |
| 241 | - public function offsetExists ($name): bool { |
|
| 241 | + public function offsetExists($name): bool { |
|
| 242 | 242 | return true; |
| 243 | 243 | } |
| 244 | 244 | |
@@ -248,7 +248,7 @@ discard block |
||
| 248 | 248 | * @param string $name Name, or alias if used. |
| 249 | 249 | * @return Column |
| 250 | 250 | */ |
| 251 | - public function offsetGet ($name): Column { |
|
| 251 | + public function offsetGet($name): Column { |
|
| 252 | 252 | return new Column($this->db, $name, $this->alias); |
| 253 | 253 | } |
| 254 | 254 | |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | * @param string $order |
| 259 | 259 | * @return $this |
| 260 | 260 | */ |
| 261 | - public function order (string $order) { |
|
| 261 | + public function order(string $order) { |
|
| 262 | 262 | if (strlen($order)) { |
| 263 | 263 | $order = " ORDER BY {$order}"; |
| 264 | 264 | } |
@@ -269,7 +269,7 @@ discard block |
||
| 269 | 269 | /** |
| 270 | 270 | * @return Statement |
| 271 | 271 | */ |
| 272 | - public function prepare (): Statement { |
|
| 272 | + public function prepare(): Statement { |
|
| 273 | 273 | return $this->db->prepare($this->toSql()); |
| 274 | 274 | } |
| 275 | 275 | |
@@ -277,7 +277,7 @@ discard block |
||
| 277 | 277 | * @param Closure $fetcher |
| 278 | 278 | * @return $this |
| 279 | 279 | */ |
| 280 | - public function setFetcher (Closure $fetcher) { |
|
| 280 | + public function setFetcher(Closure $fetcher) { |
|
| 281 | 281 | $this->fetcher = $fetcher; |
| 282 | 282 | return $this; |
| 283 | 283 | } |
@@ -285,7 +285,7 @@ discard block |
||
| 285 | 285 | /** |
| 286 | 286 | * @return string |
| 287 | 287 | */ |
| 288 | - public function toSql (): string { |
|
| 288 | + public function toSql(): string { |
|
| 289 | 289 | $sql = "SELECT {$this->_columns} FROM {$this->table}"; |
| 290 | 290 | $sql .= $this->_join; |
| 291 | 291 | $sql .= $this->_where; |
@@ -301,7 +301,7 @@ discard block |
||
| 301 | 301 | * |
| 302 | 302 | * @return string |
| 303 | 303 | */ |
| 304 | - public function toSubquery (): string { |
|
| 304 | + public function toSubquery(): string { |
|
| 305 | 305 | return "({$this->toSql()}) AS {$this->alias}"; |
| 306 | 306 | } |
| 307 | 307 | |
@@ -311,7 +311,7 @@ discard block |
||
| 311 | 311 | * @param string $condition |
| 312 | 312 | * @return $this |
| 313 | 313 | */ |
| 314 | - public function where (string $condition) { |
|
| 314 | + public function where(string $condition) { |
|
| 315 | 315 | if (!strlen($this->_where)) { |
| 316 | 316 | $this->_where = " WHERE {$condition}"; |
| 317 | 317 | } |
@@ -173,8 +173,7 @@ discard block |
||
| 173 | 173 | public function group (string $column) { |
| 174 | 174 | if (!strlen($this->_group)) { |
| 175 | 175 | $this->_group = " GROUP BY {$column}"; |
| 176 | - } |
|
| 177 | - else { |
|
| 176 | + } else { |
|
| 178 | 177 | $this->_group .= ", {$column}"; |
| 179 | 178 | } |
| 180 | 179 | return $this; |
@@ -189,8 +188,7 @@ discard block |
||
| 189 | 188 | public function having (string $condition) { |
| 190 | 189 | if (!strlen($this->_having)) { |
| 191 | 190 | $this->_having = " HAVING {$condition}"; |
| 192 | - } |
|
| 193 | - else { |
|
| 191 | + } else { |
|
| 194 | 192 | $this->_having .= " AND {$condition}"; |
| 195 | 193 | } |
| 196 | 194 | return $this; |
@@ -222,8 +220,7 @@ discard block |
||
| 222 | 220 | public function limit (int $limit, int $offset = 0) { |
| 223 | 221 | if ($limit == 0) { |
| 224 | 222 | $this->_limit = ''; |
| 225 | - } |
|
| 226 | - else { |
|
| 223 | + } else { |
|
| 227 | 224 | $this->_limit = " LIMIT {$limit}"; |
| 228 | 225 | if ($offset > 1) { |
| 229 | 226 | $this->_limit .= " OFFSET {$offset}"; |
@@ -314,8 +311,7 @@ discard block |
||
| 314 | 311 | public function where (string $condition) { |
| 315 | 312 | if (!strlen($this->_where)) { |
| 316 | 313 | $this->_where = " WHERE {$condition}"; |
| 317 | - } |
|
| 318 | - else { |
|
| 314 | + } else { |
|
| 319 | 315 | $this->_where .= " AND {$condition}"; |
| 320 | 316 | } |
| 321 | 317 | return $this; |