@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | * @param string|Select $table |
| 77 | 77 | * @param string[] $columns |
| 78 | 78 | */ |
| 79 | - public function __construct (DB $db, $table, array $columns) { |
|
| 79 | + public function __construct(DB $db, $table, array $columns) { |
|
| 80 | 80 | parent::__construct($db); |
| 81 | 81 | if ($table instanceof Select) { |
| 82 | 82 | $table = $table->toSubquery(); |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | /** |
| 100 | 100 | * Gives the clone a new alias. |
| 101 | 101 | */ |
| 102 | - public function __clone () { |
|
| 102 | + public function __clone() { |
|
| 103 | 103 | $this->alias = uniqid('_') . "__{$this->table}"; |
| 104 | 104 | } |
| 105 | 105 | |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | * @param array $args |
| 108 | 108 | * @return Statement |
| 109 | 109 | */ |
| 110 | - public function __invoke (array $args = []): Statement { |
|
| 110 | + public function __invoke(array $args = []): Statement { |
|
| 111 | 111 | return $this->execute($args); |
| 112 | 112 | } |
| 113 | 113 | |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | * |
| 117 | 117 | * @return string |
| 118 | 118 | */ |
| 119 | - final public function __toString () { |
|
| 119 | + final public function __toString() { |
|
| 120 | 120 | return $this->alias; |
| 121 | 121 | } |
| 122 | 122 | |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | * @param array $args Execution arguments. |
| 127 | 127 | * @return int |
| 128 | 128 | */ |
| 129 | - public function count (array $args = []): int { |
|
| 129 | + public function count(array $args = []): int { |
|
| 130 | 130 | $clone = clone $this; |
| 131 | 131 | $clone->columns = ['COUNT(*)']; |
| 132 | 132 | return (int)$clone->execute($args)->fetchColumn(); |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | * @param array $args |
| 139 | 139 | * @return Statement |
| 140 | 140 | */ |
| 141 | - public function execute (array $args = []): Statement { |
|
| 141 | + public function execute(array $args = []): Statement { |
|
| 142 | 142 | if (!empty($args)) { |
| 143 | 143 | return $this->prepare()($args); |
| 144 | 144 | } |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | * @param array $args Execution arguments. |
| 154 | 154 | * @return array |
| 155 | 155 | */ |
| 156 | - public function fetchAll (array $args = []): array { |
|
| 156 | + public function fetchAll(array $args = []): array { |
|
| 157 | 157 | return $this->fetcher->__invoke($this->execute($args)); |
| 158 | 158 | } |
| 159 | 159 | |
@@ -164,7 +164,7 @@ discard block |
||
| 164 | 164 | * |
| 165 | 165 | * @return ArrayIterator |
| 166 | 166 | */ |
| 167 | - public function getIterator () { |
|
| 167 | + public function getIterator() { |
|
| 168 | 168 | return new ArrayIterator($this->fetchAll()); |
| 169 | 169 | } |
| 170 | 170 | |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | * @param string $column |
| 175 | 175 | * @return $this |
| 176 | 176 | */ |
| 177 | - public function group (string $column) { |
|
| 177 | + public function group(string $column) { |
|
| 178 | 178 | if (!strlen($this->_group)) { |
| 179 | 179 | $this->_group = " GROUP BY {$column}"; |
| 180 | 180 | } |
@@ -190,7 +190,7 @@ discard block |
||
| 190 | 190 | * @param string $condition |
| 191 | 191 | * @return $this |
| 192 | 192 | */ |
| 193 | - public function having (string $condition) { |
|
| 193 | + public function having(string $condition) { |
|
| 194 | 194 | if (!strlen($this->_having)) { |
| 195 | 195 | $this->_having = " HAVING {$condition}"; |
| 196 | 196 | } |
@@ -208,7 +208,7 @@ discard block |
||
| 208 | 208 | * @param string $type |
| 209 | 209 | * @return $this |
| 210 | 210 | */ |
| 211 | - public function join ($table, string $condition, string $type = 'INNER') { |
|
| 211 | + public function join($table, string $condition, string $type = 'INNER') { |
|
| 212 | 212 | if ($table instanceof Select) { |
| 213 | 213 | $table = $table->toSubquery(); |
| 214 | 214 | } |
@@ -223,7 +223,7 @@ discard block |
||
| 223 | 223 | * @param int $offset |
| 224 | 224 | * @return $this |
| 225 | 225 | */ |
| 226 | - public function limit (int $limit, int $offset = 0) { |
|
| 226 | + public function limit(int $limit, int $offset = 0) { |
|
| 227 | 227 | if ($limit == 0) { |
| 228 | 228 | $this->_limit = ''; |
| 229 | 229 | } |
@@ -242,7 +242,7 @@ discard block |
||
| 242 | 242 | * @param string $name Name or alias if used. |
| 243 | 243 | * @return bool |
| 244 | 244 | */ |
| 245 | - public function offsetExists ($name): bool { |
|
| 245 | + public function offsetExists($name): bool { |
|
| 246 | 246 | return true; |
| 247 | 247 | } |
| 248 | 248 | |
@@ -252,7 +252,7 @@ discard block |
||
| 252 | 252 | * @param string $name Name, or alias if used. |
| 253 | 253 | * @return Column |
| 254 | 254 | */ |
| 255 | - public function offsetGet ($name): Column { |
|
| 255 | + public function offsetGet($name): Column { |
|
| 256 | 256 | return new Column($this->db, $name, $this->alias); |
| 257 | 257 | } |
| 258 | 258 | |
@@ -262,7 +262,7 @@ discard block |
||
| 262 | 262 | * @param string $order |
| 263 | 263 | * @return $this |
| 264 | 264 | */ |
| 265 | - public function order (string $order) { |
|
| 265 | + public function order(string $order) { |
|
| 266 | 266 | if (strlen($order)) { |
| 267 | 267 | $order = " ORDER BY {$order}"; |
| 268 | 268 | } |
@@ -273,7 +273,7 @@ discard block |
||
| 273 | 273 | /** |
| 274 | 274 | * @return Statement |
| 275 | 275 | */ |
| 276 | - public function prepare (): Statement { |
|
| 276 | + public function prepare(): Statement { |
|
| 277 | 277 | return $this->db->prepare($this->toSql()); |
| 278 | 278 | } |
| 279 | 279 | |
@@ -281,7 +281,7 @@ discard block |
||
| 281 | 281 | * @param Closure $fetcher |
| 282 | 282 | * @return $this |
| 283 | 283 | */ |
| 284 | - public function setFetcher (Closure $fetcher) { |
|
| 284 | + public function setFetcher(Closure $fetcher) { |
|
| 285 | 285 | $this->fetcher = $fetcher; |
| 286 | 286 | return $this; |
| 287 | 287 | } |
@@ -289,7 +289,7 @@ discard block |
||
| 289 | 289 | /** |
| 290 | 290 | * @return string |
| 291 | 291 | */ |
| 292 | - public function toSql (): string { |
|
| 292 | + public function toSql(): string { |
|
| 293 | 293 | $sql = 'SELECT ' . implode(', ', $this->columns) . ' FROM ' . $this->table; |
| 294 | 294 | $sql .= $this->_join; |
| 295 | 295 | $sql .= $this->_where; |
@@ -305,7 +305,7 @@ discard block |
||
| 305 | 305 | * |
| 306 | 306 | * @return string |
| 307 | 307 | */ |
| 308 | - public function toSubquery (): string { |
|
| 308 | + public function toSubquery(): string { |
|
| 309 | 309 | return "({$this->toSql()}) AS {$this->alias}"; |
| 310 | 310 | } |
| 311 | 311 | |
@@ -315,7 +315,7 @@ discard block |
||
| 315 | 315 | * @param string $condition |
| 316 | 316 | * @return $this |
| 317 | 317 | */ |
| 318 | - public function where (string $condition) { |
|
| 318 | + public function where(string $condition) { |
|
| 319 | 319 | if (!strlen($this->_where)) { |
| 320 | 320 | $this->_where = " WHERE {$condition}"; |
| 321 | 321 | } |
@@ -86,8 +86,7 @@ discard block |
||
| 86 | 86 | foreach ($columns as $alias => $name) { |
| 87 | 87 | if (is_string($alias) and $name !== $alias) { |
| 88 | 88 | $this->columns[] = "{$name} AS {$alias}"; |
| 89 | - } |
|
| 90 | - else { |
|
| 89 | + } else { |
|
| 91 | 90 | $this->columns[] = $name; |
| 92 | 91 | } |
| 93 | 92 | } |
@@ -177,8 +176,7 @@ discard block |
||
| 177 | 176 | public function group (string $column) { |
| 178 | 177 | if (!strlen($this->_group)) { |
| 179 | 178 | $this->_group = " GROUP BY {$column}"; |
| 180 | - } |
|
| 181 | - else { |
|
| 179 | + } else { |
|
| 182 | 180 | $this->_group .= ", {$column}"; |
| 183 | 181 | } |
| 184 | 182 | return $this; |
@@ -193,8 +191,7 @@ discard block |
||
| 193 | 191 | public function having (string $condition) { |
| 194 | 192 | if (!strlen($this->_having)) { |
| 195 | 193 | $this->_having = " HAVING {$condition}"; |
| 196 | - } |
|
| 197 | - else { |
|
| 194 | + } else { |
|
| 198 | 195 | $this->_having .= " AND {$condition}"; |
| 199 | 196 | } |
| 200 | 197 | return $this; |
@@ -226,8 +223,7 @@ discard block |
||
| 226 | 223 | public function limit (int $limit, int $offset = 0) { |
| 227 | 224 | if ($limit == 0) { |
| 228 | 225 | $this->_limit = ''; |
| 229 | - } |
|
| 230 | - else { |
|
| 226 | + } else { |
|
| 231 | 227 | $this->_limit = " LIMIT {$limit}"; |
| 232 | 228 | if ($offset > 1) { |
| 233 | 229 | $this->_limit .= " OFFSET {$offset}"; |
@@ -318,8 +314,7 @@ discard block |
||
| 318 | 314 | public function where (string $condition) { |
| 319 | 315 | if (!strlen($this->_where)) { |
| 320 | 316 | $this->_where = " WHERE {$condition}"; |
| 321 | - } |
|
| 322 | - else { |
|
| 317 | + } else { |
|
| 323 | 318 | $this->_where .= " AND {$condition}"; |
| 324 | 319 | } |
| 325 | 320 | return $this; |