@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | * @param string|Select $table |
| 75 | 75 | * @param string[] $columns |
| 76 | 76 | */ |
| 77 | - public function __construct (DB $db, $table, array $columns) { |
|
| 77 | + public function __construct(DB $db, $table, array $columns) { |
|
| 78 | 78 | parent::__construct($db); |
| 79 | 79 | if ($table instanceof Select) { |
| 80 | 80 | $table = $table->toSubquery(); |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | /** |
| 97 | 97 | * Gives the clone a new alias. |
| 98 | 98 | */ |
| 99 | - public function __clone () { |
|
| 99 | + public function __clone() { |
|
| 100 | 100 | $this->alias = uniqid('_') . "__{$this->table}"; |
| 101 | 101 | } |
| 102 | 102 | |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | * @param array $args |
| 105 | 105 | * @return Statement |
| 106 | 106 | */ |
| 107 | - public function __invoke (array $args = []) { |
|
| 107 | + public function __invoke(array $args = []) { |
|
| 108 | 108 | return $this->execute($args); |
| 109 | 109 | } |
| 110 | 110 | |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | * |
| 114 | 114 | * @return string |
| 115 | 115 | */ |
| 116 | - final public function __toString () { |
|
| 116 | + final public function __toString() { |
|
| 117 | 117 | return $this->alias; |
| 118 | 118 | } |
| 119 | 119 | |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | * @param array $args Execution arguments. |
| 124 | 124 | * @return int |
| 125 | 125 | */ |
| 126 | - public function count (array $args = []): int { |
|
| 126 | + public function count(array $args = []): int { |
|
| 127 | 127 | $clone = clone $this; |
| 128 | 128 | $clone->_columns = 'COUNT(*)'; |
| 129 | 129 | return (int)$clone->execute($args)->fetchColumn(); |
@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | * @param array $args |
| 136 | 136 | * @return Statement |
| 137 | 137 | */ |
| 138 | - public function execute (array $args = []) { |
|
| 138 | + public function execute(array $args = []) { |
|
| 139 | 139 | if (empty($args)) { |
| 140 | 140 | return $this->db->query($this->toSql()); |
| 141 | 141 | } |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | * @param array $args Execution arguments. |
| 151 | 151 | * @return array |
| 152 | 152 | */ |
| 153 | - public function fetchAll (array $args = []): array { |
|
| 153 | + public function fetchAll(array $args = []): array { |
|
| 154 | 154 | return iterator_to_array($this->fetcher->__invoke($this->execute($args))); |
| 155 | 155 | } |
| 156 | 156 | |
@@ -163,7 +163,7 @@ discard block |
||
| 163 | 163 | * @param array $args Execution arguments. |
| 164 | 164 | * @return Generator |
| 165 | 165 | */ |
| 166 | - public function fetchEach (array $args = []) { |
|
| 166 | + public function fetchEach(array $args = []) { |
|
| 167 | 167 | yield from $this->fetcher->__invoke($this->execute($args)); |
| 168 | 168 | } |
| 169 | 169 | |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | * |
| 175 | 175 | * @return Generator |
| 176 | 176 | */ |
| 177 | - public function getIterator () { |
|
| 177 | + public function getIterator() { |
|
| 178 | 178 | yield from $this->fetchEach(); |
| 179 | 179 | } |
| 180 | 180 | |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | * @param string $column |
| 185 | 185 | * @return $this |
| 186 | 186 | */ |
| 187 | - public function group (string $column) { |
|
| 187 | + public function group(string $column) { |
|
| 188 | 188 | if (!strlen($this->_group)) { |
| 189 | 189 | $this->_group = " GROUP BY {$column}"; |
| 190 | 190 | } |
@@ -200,7 +200,7 @@ discard block |
||
| 200 | 200 | * @param string $condition |
| 201 | 201 | * @return $this |
| 202 | 202 | */ |
| 203 | - public function having (string $condition) { |
|
| 203 | + public function having(string $condition) { |
|
| 204 | 204 | if (!strlen($this->_having)) { |
| 205 | 205 | $this->_having = " HAVING {$condition}"; |
| 206 | 206 | } |
@@ -215,7 +215,7 @@ discard block |
||
| 215 | 215 | * |
| 216 | 216 | * @return Predicate |
| 217 | 217 | */ |
| 218 | - public function isEmpty () { |
|
| 218 | + public function isEmpty() { |
|
| 219 | 219 | return new Predicate("NOT EXISTS ({$this->toSql()}"); |
| 220 | 220 | } |
| 221 | 221 | |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | * |
| 225 | 225 | * @return Predicate |
| 226 | 226 | */ |
| 227 | - public function isNotEmpty () { |
|
| 227 | + public function isNotEmpty() { |
|
| 228 | 228 | return new Predicate("EXISTS ({$this->toSql()})"); |
| 229 | 229 | } |
| 230 | 230 | |
@@ -236,7 +236,7 @@ discard block |
||
| 236 | 236 | * @param string $type |
| 237 | 237 | * @return $this |
| 238 | 238 | */ |
| 239 | - public function join ($table, string $condition, string $type = 'INNER') { |
|
| 239 | + public function join($table, string $condition, string $type = 'INNER') { |
|
| 240 | 240 | if ($table instanceof Select) { |
| 241 | 241 | $table = $table->toSubquery(); |
| 242 | 242 | } |
@@ -251,7 +251,7 @@ discard block |
||
| 251 | 251 | * @param int $offset |
| 252 | 252 | * @return $this |
| 253 | 253 | */ |
| 254 | - public function limit (int $limit, int $offset = 0) { |
|
| 254 | + public function limit(int $limit, int $offset = 0) { |
|
| 255 | 255 | if ($limit == 0) { |
| 256 | 256 | $this->_limit = ''; |
| 257 | 257 | } |
@@ -270,7 +270,7 @@ discard block |
||
| 270 | 270 | * @param string $name Name or alias if used. |
| 271 | 271 | * @return bool |
| 272 | 272 | */ |
| 273 | - public function offsetExists ($name): bool { |
|
| 273 | + public function offsetExists($name): bool { |
|
| 274 | 274 | return true; |
| 275 | 275 | } |
| 276 | 276 | |
@@ -280,7 +280,7 @@ discard block |
||
| 280 | 280 | * @param string $name Name, or alias if used. |
| 281 | 281 | * @return Column |
| 282 | 282 | */ |
| 283 | - public function offsetGet ($name) { |
|
| 283 | + public function offsetGet($name) { |
|
| 284 | 284 | return new Column($this->db, $name, $this->alias); |
| 285 | 285 | } |
| 286 | 286 | |
@@ -290,7 +290,7 @@ discard block |
||
| 290 | 290 | * @param string $order |
| 291 | 291 | * @return $this |
| 292 | 292 | */ |
| 293 | - public function order (string $order) { |
|
| 293 | + public function order(string $order) { |
|
| 294 | 294 | if (strlen($order)) { |
| 295 | 295 | $order = " ORDER BY {$order}"; |
| 296 | 296 | } |
@@ -301,7 +301,7 @@ discard block |
||
| 301 | 301 | /** |
| 302 | 302 | * @return Statement |
| 303 | 303 | */ |
| 304 | - public function prepare () { |
|
| 304 | + public function prepare() { |
|
| 305 | 305 | return $this->db->prepare($this->toSql()); |
| 306 | 306 | } |
| 307 | 307 | |
@@ -309,7 +309,7 @@ discard block |
||
| 309 | 309 | * @param Closure $fetcher |
| 310 | 310 | * @return $this |
| 311 | 311 | */ |
| 312 | - public function setFetcher (Closure $fetcher) { |
|
| 312 | + public function setFetcher(Closure $fetcher) { |
|
| 313 | 313 | $this->fetcher = $fetcher; |
| 314 | 314 | return $this; |
| 315 | 315 | } |
@@ -317,7 +317,7 @@ discard block |
||
| 317 | 317 | /** |
| 318 | 318 | * @return string |
| 319 | 319 | */ |
| 320 | - public function toSql (): string { |
|
| 320 | + public function toSql(): string { |
|
| 321 | 321 | $sql = "SELECT {$this->_columns} FROM {$this->table}"; |
| 322 | 322 | $sql .= $this->_join; |
| 323 | 323 | $sql .= $this->_where; |
@@ -333,7 +333,7 @@ discard block |
||
| 333 | 333 | * |
| 334 | 334 | * @return string |
| 335 | 335 | */ |
| 336 | - public function toSubquery (): string { |
|
| 336 | + public function toSubquery(): string { |
|
| 337 | 337 | return "({$this->toSql()}) AS {$this->alias}"; |
| 338 | 338 | } |
| 339 | 339 | |
@@ -343,7 +343,7 @@ discard block |
||
| 343 | 343 | * @param string $condition |
| 344 | 344 | * @return $this |
| 345 | 345 | */ |
| 346 | - public function where (string $condition) { |
|
| 346 | + public function where(string $condition) { |
|
| 347 | 347 | if (!strlen($this->_where)) { |
| 348 | 348 | $this->_where = " WHERE {$condition}"; |
| 349 | 349 | } |