@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | * @param string|Select $table |
| 104 | 104 | * @param string[] $columns |
| 105 | 105 | */ |
| 106 | - public function __construct (DB $db, $table, array $columns) { |
|
| 106 | + public function __construct(DB $db, $table, array $columns) { |
|
| 107 | 107 | parent::__construct($db); |
| 108 | 108 | if ($table instanceof Select) { |
| 109 | 109 | $this->table = $table->toSubquery(); |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | * @param array $args |
| 124 | 124 | * @return Statement |
| 125 | 125 | */ |
| 126 | - public function __invoke (array $args = []) { |
|
| 126 | + public function __invoke(array $args = []) { |
|
| 127 | 127 | return $this->execute($args); |
| 128 | 128 | } |
| 129 | 129 | |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | * |
| 133 | 133 | * @return string |
| 134 | 134 | */ |
| 135 | - final public function __toString () { |
|
| 135 | + final public function __toString() { |
|
| 136 | 136 | return $this->alias; |
| 137 | 137 | } |
| 138 | 138 | |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | * @param array $args Execution arguments. |
| 143 | 143 | * @return int |
| 144 | 144 | */ |
| 145 | - public function count (array $args = []): int { |
|
| 145 | + public function count(array $args = []): int { |
|
| 146 | 146 | $clone = clone $this; |
| 147 | 147 | $clone->_columns = 'COUNT(*)'; |
| 148 | 148 | $clone->_order = ''; |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | * @param array $args |
| 156 | 156 | * @return Statement |
| 157 | 157 | */ |
| 158 | - public function execute (array $args = []) { |
|
| 158 | + public function execute(array $args = []) { |
|
| 159 | 159 | if (empty($args)) { |
| 160 | 160 | return $this->db->query($this->toSql()); |
| 161 | 161 | } |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | * @param array $args Execution arguments. |
| 171 | 171 | * @return array |
| 172 | 172 | */ |
| 173 | - public function getAll (array $args = []): array { |
|
| 173 | + public function getAll(array $args = []): array { |
|
| 174 | 174 | return iterator_to_array($this->fetcher->__invoke($this->execute($args))); |
| 175 | 175 | } |
| 176 | 176 | |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | * @param array $args Execution arguments. |
| 184 | 184 | * @return Generator |
| 185 | 185 | */ |
| 186 | - public function getEach (array $args = []) { |
|
| 186 | + public function getEach(array $args = []) { |
|
| 187 | 187 | yield from $this->fetcher->__invoke($this->execute($args)); |
| 188 | 188 | } |
| 189 | 189 | |
@@ -195,7 +195,7 @@ discard block |
||
| 195 | 195 | * @param array $args |
| 196 | 196 | * @return mixed |
| 197 | 197 | */ |
| 198 | - public function getFirst (array $args = []) { |
|
| 198 | + public function getFirst(array $args = []) { |
|
| 199 | 199 | return $this->getEach($args)->current(); |
| 200 | 200 | } |
| 201 | 201 | |
@@ -206,7 +206,7 @@ discard block |
||
| 206 | 206 | * |
| 207 | 207 | * @return Generator |
| 208 | 208 | */ |
| 209 | - public function getIterator () { |
|
| 209 | + public function getIterator() { |
|
| 210 | 210 | yield from $this->getEach(); |
| 211 | 211 | } |
| 212 | 212 | |
@@ -216,7 +216,7 @@ discard block |
||
| 216 | 216 | * @param string $column |
| 217 | 217 | * @return $this |
| 218 | 218 | */ |
| 219 | - public function group (string $column) { |
|
| 219 | + public function group(string $column) { |
|
| 220 | 220 | if (!strlen($this->_group)) { |
| 221 | 221 | $this->_group = " GROUP BY {$column}"; |
| 222 | 222 | } |
@@ -232,7 +232,7 @@ discard block |
||
| 232 | 232 | * @param string $condition |
| 233 | 233 | * @return $this |
| 234 | 234 | */ |
| 235 | - public function having (string $condition) { |
|
| 235 | + public function having(string $condition) { |
|
| 236 | 236 | if (!strlen($this->_having)) { |
| 237 | 237 | $this->_having = " HAVING {$condition}"; |
| 238 | 238 | } |
@@ -247,7 +247,7 @@ discard block |
||
| 247 | 247 | * |
| 248 | 248 | * @return Predicate |
| 249 | 249 | */ |
| 250 | - public function isCorrelated () { |
|
| 250 | + public function isCorrelated() { |
|
| 251 | 251 | return new Predicate("EXISTS ({$this->toSql()})"); |
| 252 | 252 | } |
| 253 | 253 | |
@@ -256,7 +256,7 @@ discard block |
||
| 256 | 256 | * |
| 257 | 257 | * @return Predicate |
| 258 | 258 | */ |
| 259 | - public function isNotCorrelated () { |
|
| 259 | + public function isNotCorrelated() { |
|
| 260 | 260 | return new Predicate("NOT EXISTS ({$this->toSql()})"); |
| 261 | 261 | } |
| 262 | 262 | |
@@ -268,7 +268,7 @@ discard block |
||
| 268 | 268 | * @param string $type |
| 269 | 269 | * @return $this |
| 270 | 270 | */ |
| 271 | - public function join ($table, string $condition, string $type = 'INNER') { |
|
| 271 | + public function join($table, string $condition, string $type = 'INNER') { |
|
| 272 | 272 | if ($table instanceof Select) { |
| 273 | 273 | $table = $table->toSubquery(); |
| 274 | 274 | } |
@@ -283,7 +283,7 @@ discard block |
||
| 283 | 283 | * @param int $offset |
| 284 | 284 | * @return $this |
| 285 | 285 | */ |
| 286 | - public function limit (int $limit, int $offset = 0) { |
|
| 286 | + public function limit(int $limit, int $offset = 0) { |
|
| 287 | 287 | if ($limit == 0) { |
| 288 | 288 | $this->_limit = ''; |
| 289 | 289 | } |
@@ -302,7 +302,7 @@ discard block |
||
| 302 | 302 | * @param mixed $offset Ordinal or reference name. |
| 303 | 303 | * @return bool |
| 304 | 304 | */ |
| 305 | - public function offsetExists ($offset): bool { |
|
| 305 | + public function offsetExists($offset): bool { |
|
| 306 | 306 | return isset($this->references[$offset]); |
| 307 | 307 | } |
| 308 | 308 | |
@@ -312,7 +312,7 @@ discard block |
||
| 312 | 312 | * @param mixed $offset Ordinal or reference name. |
| 313 | 313 | * @return Column |
| 314 | 314 | */ |
| 315 | - public function offsetGet ($offset) { |
|
| 315 | + public function offsetGet($offset) { |
|
| 316 | 316 | return $this->references[$offset]; |
| 317 | 317 | } |
| 318 | 318 | |
@@ -322,7 +322,7 @@ discard block |
||
| 322 | 322 | * @param string $order |
| 323 | 323 | * @return $this |
| 324 | 324 | */ |
| 325 | - public function order (string $order) { |
|
| 325 | + public function order(string $order) { |
|
| 326 | 326 | if (strlen($order)) { |
| 327 | 327 | $order = " ORDER BY {$order}"; |
| 328 | 328 | } |
@@ -333,7 +333,7 @@ discard block |
||
| 333 | 333 | /** |
| 334 | 334 | * @return Statement |
| 335 | 335 | */ |
| 336 | - public function prepare () { |
|
| 336 | + public function prepare() { |
|
| 337 | 337 | return $this->db->prepare($this->toSql()); |
| 338 | 338 | } |
| 339 | 339 | |
@@ -341,7 +341,7 @@ discard block |
||
| 341 | 341 | * @param string $alias |
| 342 | 342 | * @return $this |
| 343 | 343 | */ |
| 344 | - public function setAlias (string $alias) { |
|
| 344 | + public function setAlias(string $alias) { |
|
| 345 | 345 | $this->alias = $alias; |
| 346 | 346 | return $this; |
| 347 | 347 | } |
@@ -350,7 +350,7 @@ discard block |
||
| 350 | 350 | * @param string[] $columns |
| 351 | 351 | * @return $this |
| 352 | 352 | */ |
| 353 | - public function setColumns (array $columns) { |
|
| 353 | + public function setColumns(array $columns) { |
|
| 354 | 354 | $this->references = []; |
| 355 | 355 | $_columns = []; |
| 356 | 356 | $i = 0; |
@@ -380,7 +380,7 @@ discard block |
||
| 380 | 380 | * @param Closure $fetcher |
| 381 | 381 | * @return $this |
| 382 | 382 | */ |
| 383 | - public function setFetcher (Closure $fetcher) { |
|
| 383 | + public function setFetcher(Closure $fetcher) { |
|
| 384 | 384 | $this->fetcher = $fetcher; |
| 385 | 385 | return $this; |
| 386 | 386 | } |
@@ -390,7 +390,7 @@ discard block |
||
| 390 | 390 | * |
| 391 | 391 | * @return string |
| 392 | 392 | */ |
| 393 | - public function toSql (): string { |
|
| 393 | + public function toSql(): string { |
|
| 394 | 394 | $sql = "SELECT {$this->_columns} FROM {$this->table}"; |
| 395 | 395 | $sql .= $this->_join; |
| 396 | 396 | $sql .= $this->_where; |
@@ -406,7 +406,7 @@ discard block |
||
| 406 | 406 | * |
| 407 | 407 | * @return string |
| 408 | 408 | */ |
| 409 | - public function toSubquery (): string { |
|
| 409 | + public function toSubquery(): string { |
|
| 410 | 410 | return "({$this->toSql()}) AS {$this->alias}"; |
| 411 | 411 | } |
| 412 | 412 | |
@@ -416,7 +416,7 @@ discard block |
||
| 416 | 416 | * @param string $condition |
| 417 | 417 | * @return $this |
| 418 | 418 | */ |
| 419 | - public function where (string $condition) { |
|
| 419 | + public function where(string $condition) { |
|
| 420 | 420 | if (!strlen($this->_where)) { |
| 421 | 421 | $this->_where = " WHERE {$condition}"; |
| 422 | 422 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | * @param string[] $conditions |
| 18 | 18 | * @return Predicate |
| 19 | 19 | */ |
| 20 | - public static function all (array $conditions) { |
|
| 20 | + public static function all(array $conditions) { |
|
| 21 | 21 | if (count($conditions) === 1) { |
| 22 | 22 | return reset($conditions); |
| 23 | 23 | } |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | * @param string[] $conditions |
| 31 | 31 | * @return Predicate |
| 32 | 32 | */ |
| 33 | - public static function any (array $conditions) { |
|
| 33 | + public static function any(array $conditions) { |
|
| 34 | 34 | if (count($conditions) === 1) { |
| 35 | 35 | return reset($conditions); |
| 36 | 36 | } |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | * @param string $multiOper |
| 57 | 57 | * @return Predicate |
| 58 | 58 | */ |
| 59 | - public static function compare ($a, $b, $oper = '=', $multiOper = 'IN') { |
|
| 59 | + public static function compare($a, $b, $oper = '=', $multiOper = 'IN') { |
|
| 60 | 60 | if (is_array($b)) { |
| 61 | 61 | return new static("{$a} {$multiOper} (" . implode(',', $b) . ")"); |
| 62 | 62 | } |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | * @param string $listOper |
| 78 | 78 | * @return Predicate[] |
| 79 | 79 | */ |
| 80 | - public static function compareArray (array $values, $oper = '=', $listOper = 'IN') { |
|
| 80 | + public static function compareArray(array $values, $oper = '=', $listOper = 'IN') { |
|
| 81 | 81 | foreach ($values as $a => $b) { |
| 82 | 82 | $values[$a] = static::compare($a, $b, $oper, $listOper); |
| 83 | 83 | } |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | * |
| 90 | 90 | * @return Predicate |
| 91 | 91 | */ |
| 92 | - public function invert () { |
|
| 92 | + public function invert() { |
|
| 93 | 93 | return new static("NOT({$this})"); |
| 94 | 94 | } |
| 95 | 95 | } |
| 96 | 96 | \ No newline at end of file |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | * @param array $values |
| 29 | 29 | * @return Value |
| 30 | 30 | */ |
| 31 | - public function coalesce (array $values) { |
|
| 31 | + public function coalesce(array $values) { |
|
| 32 | 32 | array_unshift($values, $this); |
| 33 | 33 | $values = $this->db->quoteList($values); |
| 34 | 34 | return new Value($this->db, "COALESCE({$values})"); |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | * @param array $values `[when => then]` |
| 41 | 41 | * @return Choice |
| 42 | 42 | */ |
| 43 | - public function getChoice (array $values) { |
|
| 43 | + public function getChoice(array $values) { |
|
| 44 | 44 | return new Choice($this->db, "{$this}", $values); |
| 45 | 45 | } |
| 46 | 46 | |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | * @param null|bool|number|string|Select $arg |
| 54 | 54 | * @return Predicate |
| 55 | 55 | */ |
| 56 | - public function is ($arg): Predicate { |
|
| 56 | + public function is($arg): Predicate { |
|
| 57 | 57 | if ($arg === null or is_bool($arg)) { |
| 58 | 58 | $arg = ['' => 'NULL', 1 => 'TRUE', 0 => 'FALSE'][$arg]; |
| 59 | 59 | } |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | * @param number|string $max |
| 80 | 80 | * @return Predicate |
| 81 | 81 | */ |
| 82 | - public function isBetween ($min, $max) { |
|
| 82 | + public function isBetween($min, $max) { |
|
| 83 | 83 | $min = $this->db->quote($min); |
| 84 | 84 | $max = $this->db->quote($max); |
| 85 | 85 | return new Predicate("{$this} BETWEEN {$min} AND {$max}"); |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | * @param bool|number|string|array|Select $arg |
| 92 | 92 | * @return Predicate |
| 93 | 93 | */ |
| 94 | - public function isEqual ($arg) { |
|
| 94 | + public function isEqual($arg) { |
|
| 95 | 95 | return Predicate::compare($this, $this->db->quoteMixed($arg)); |
| 96 | 96 | } |
| 97 | 97 | |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | * @param string $multi `ALL|ANY` |
| 108 | 108 | * @return Predicate |
| 109 | 109 | */ |
| 110 | - public function isGreater ($arg, string $multi = 'ALL') { |
|
| 110 | + public function isGreater($arg, string $multi = 'ALL') { |
|
| 111 | 111 | if ($arg instanceof Select and $this->db == 'sqlite') { |
| 112 | 112 | $sub = new Select($this->db, $arg, [$arg[0]]); |
| 113 | 113 | switch ($multi) { |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | * @param string $multi `ALL|ANY` |
| 133 | 133 | * @return Predicate |
| 134 | 134 | */ |
| 135 | - public function isGreaterOrEqual ($arg, string $multi = 'ALL') { |
|
| 135 | + public function isGreaterOrEqual($arg, string $multi = 'ALL') { |
|
| 136 | 136 | if ($arg instanceof Select and $this->db == 'sqlite') { |
| 137 | 137 | $sub = new Select($this->db, $arg, [$arg[0]]); |
| 138 | 138 | switch ($multi) { |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | * @param string $multi `ALL|ANY` |
| 158 | 158 | * @return Predicate |
| 159 | 159 | */ |
| 160 | - public function isLess ($arg, string $multi = 'ALL') { |
|
| 160 | + public function isLess($arg, string $multi = 'ALL') { |
|
| 161 | 161 | if ($arg instanceof Select and $this->db == 'sqlite') { |
| 162 | 162 | $sub = new Select($this->db, $arg, [$arg[0]]); |
| 163 | 163 | switch ($multi) { |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | * @param string $multi `ALL|ANY` |
| 183 | 183 | * @return Predicate |
| 184 | 184 | */ |
| 185 | - public function isLessOrEqual ($arg, string $multi = 'ALL') { |
|
| 185 | + public function isLessOrEqual($arg, string $multi = 'ALL') { |
|
| 186 | 186 | if ($arg instanceof Select and $this->db == 'sqlite') { |
| 187 | 187 | $sub = new Select($this->db, $arg, [$arg[0]]); |
| 188 | 188 | switch ($multi) { |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | * @param string $pattern |
| 202 | 202 | * @return Predicate |
| 203 | 203 | */ |
| 204 | - public function isLike (string $pattern) { |
|
| 204 | + public function isLike(string $pattern) { |
|
| 205 | 205 | $pattern = $this->db->quote($pattern); |
| 206 | 206 | return new Predicate("{$this} LIKE {$pattern}"); |
| 207 | 207 | } |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | * @param null|bool|number|string|Select $arg |
| 213 | 213 | * @return Predicate |
| 214 | 214 | */ |
| 215 | - public function isNot ($arg) { |
|
| 215 | + public function isNot($arg) { |
|
| 216 | 216 | return $this->is($arg)->invert(); |
| 217 | 217 | } |
| 218 | 218 | |
@@ -223,7 +223,7 @@ discard block |
||
| 223 | 223 | * @param number|string $max |
| 224 | 224 | * @return Predicate |
| 225 | 225 | */ |
| 226 | - public function isNotBetween ($min, $max) { |
|
| 226 | + public function isNotBetween($min, $max) { |
|
| 227 | 227 | $min = $this->db->quote($min); |
| 228 | 228 | $max = $this->db->quote($max); |
| 229 | 229 | return new Predicate("{$this} NOT BETWEEN {$min} AND {$max}"); |
@@ -235,7 +235,7 @@ discard block |
||
| 235 | 235 | * @param bool|number|string|array|Select $arg |
| 236 | 236 | * @return Predicate |
| 237 | 237 | */ |
| 238 | - public function isNotEqual ($arg) { |
|
| 238 | + public function isNotEqual($arg) { |
|
| 239 | 239 | return Predicate::compare($this, $this->db->quoteMixed($arg), '<>', 'NOT IN'); |
| 240 | 240 | } |
| 241 | 241 | |
@@ -245,7 +245,7 @@ discard block |
||
| 245 | 245 | * @param string $pattern |
| 246 | 246 | * @return Predicate |
| 247 | 247 | */ |
| 248 | - public function isNotLike (string $pattern) { |
|
| 248 | + public function isNotLike(string $pattern) { |
|
| 249 | 249 | $pattern = $this->db->quote($pattern); |
| 250 | 250 | return new Predicate("{$this} NOT LIKE {$pattern}"); |
| 251 | 251 | } |
@@ -256,7 +256,7 @@ discard block |
||
| 256 | 256 | * @param string $pattern |
| 257 | 257 | * @return Predicate |
| 258 | 258 | */ |
| 259 | - public function isNotRegExp (string $pattern) { |
|
| 259 | + public function isNotRegExp(string $pattern) { |
|
| 260 | 260 | $pattern = $this->db->quote($pattern); |
| 261 | 261 | return new Predicate("{$this} NOT REGEXP {$pattern}"); |
| 262 | 262 | } |
@@ -267,7 +267,7 @@ discard block |
||
| 267 | 267 | * @param string $pattern |
| 268 | 268 | * @return Predicate |
| 269 | 269 | */ |
| 270 | - public function isRegExp (string $pattern) { |
|
| 270 | + public function isRegExp(string $pattern) { |
|
| 271 | 271 | $pattern = $this->db->quote($pattern); |
| 272 | 272 | return new Predicate("{$this} REGEXP {$pattern}"); |
| 273 | 273 | } |