@@ -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 | } |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | * @param string $listOper |
| 58 | 58 | * @return Predicate |
| 59 | 59 | */ |
| 60 | - public static function compare ($a, $b, $oper = '=', $subOper = 'ANY', $listOper = 'IN') { |
|
| 60 | + public static function compare($a, $b, $oper = '=', $subOper = 'ANY', $listOper = 'IN') { |
|
| 61 | 61 | if (is_array($b)) { |
| 62 | 62 | return new static("{$a} {$listOper} (" . implode(',', $b) . ")"); |
| 63 | 63 | } |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | * @param string $listOper |
| 80 | 80 | * @return Predicate[] |
| 81 | 81 | */ |
| 82 | - public static function compareArray (array $values, $oper = '=', $subOper = 'ANY', $listOper = 'IN') { |
|
| 82 | + public static function compareArray(array $values, $oper = '=', $subOper = 'ANY', $listOper = 'IN') { |
|
| 83 | 83 | foreach ($values as $a => $b) { |
| 84 | 84 | $values[$a] = static::compare($a, $b, $oper, $subOper, $listOper); |
| 85 | 85 | } |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | * |
| 92 | 92 | * @return Predicate |
| 93 | 93 | */ |
| 94 | - public function invert () { |
|
| 94 | + public function invert() { |
|
| 95 | 95 | return new static("NOT({$this})"); |
| 96 | 96 | } |
| 97 | 97 | } |
| 98 | 98 | \ No newline at end of file |
@@ -60,8 +60,7 @@ |
||
| 60 | 60 | public static function compare ($a, $b, $oper = '=', $subOper = 'ANY', $listOper = 'IN') { |
| 61 | 61 | if (is_array($b)) { |
| 62 | 62 | return new static("{$a} {$listOper} (" . implode(',', $b) . ")"); |
| 63 | - } |
|
| 64 | - elseif ($b instanceof Select) { |
|
| 63 | + } elseif ($b instanceof Select) { |
|
| 65 | 64 | return new static("{$a} {$oper} {$subOper} ({$b->toSql()})"); |
| 66 | 65 | } |
| 67 | 66 | return new static("{$a} {$oper} {$b}"); |
@@ -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 | $this->_having[] = $condition; |
| 195 | 195 | return $this; |
| 196 | 196 | } |
@@ -203,7 +203,7 @@ discard block |
||
| 203 | 203 | * @param string $type |
| 204 | 204 | * @return $this |
| 205 | 205 | */ |
| 206 | - public function join ($table, string $condition, string $type = 'INNER') { |
|
| 206 | + public function join($table, string $condition, string $type = 'INNER') { |
|
| 207 | 207 | if ($table instanceof Select) { |
| 208 | 208 | $table = $table->toSubquery(); |
| 209 | 209 | } |
@@ -218,7 +218,7 @@ discard block |
||
| 218 | 218 | * @param int $offset |
| 219 | 219 | * @return $this |
| 220 | 220 | */ |
| 221 | - public function limit (int $limit, int $offset = 0) { |
|
| 221 | + public function limit(int $limit, int $offset = 0) { |
|
| 222 | 222 | if ($limit == 0) { |
| 223 | 223 | $this->_limit = ''; |
| 224 | 224 | } |
@@ -237,7 +237,7 @@ discard block |
||
| 237 | 237 | * @param string $name Name or alias if used. |
| 238 | 238 | * @return bool |
| 239 | 239 | */ |
| 240 | - public function offsetExists ($name): bool { |
|
| 240 | + public function offsetExists($name): bool { |
|
| 241 | 241 | return true; |
| 242 | 242 | } |
| 243 | 243 | |
@@ -247,7 +247,7 @@ discard block |
||
| 247 | 247 | * @param string $name Name, or alias if used. |
| 248 | 248 | * @return Column |
| 249 | 249 | */ |
| 250 | - public function offsetGet ($name): Column { |
|
| 250 | + public function offsetGet($name): Column { |
|
| 251 | 251 | return new Column($this->db, $name, $this->alias); |
| 252 | 252 | } |
| 253 | 253 | |
@@ -257,7 +257,7 @@ discard block |
||
| 257 | 257 | * @param string $order |
| 258 | 258 | * @return $this |
| 259 | 259 | */ |
| 260 | - public function order (string $order) { |
|
| 260 | + public function order(string $order) { |
|
| 261 | 261 | if (strlen($order)) { |
| 262 | 262 | $order = " ORDER BY {$order}"; |
| 263 | 263 | } |
@@ -268,7 +268,7 @@ discard block |
||
| 268 | 268 | /** |
| 269 | 269 | * @return Statement |
| 270 | 270 | */ |
| 271 | - public function prepare (): Statement { |
|
| 271 | + public function prepare(): Statement { |
|
| 272 | 272 | return $this->db->prepare($this->toSql()); |
| 273 | 273 | } |
| 274 | 274 | |
@@ -276,7 +276,7 @@ discard block |
||
| 276 | 276 | * @param Closure $fetcher |
| 277 | 277 | * @return $this |
| 278 | 278 | */ |
| 279 | - public function setFetcher (Closure $fetcher) { |
|
| 279 | + public function setFetcher(Closure $fetcher) { |
|
| 280 | 280 | $this->fetcher = $fetcher; |
| 281 | 281 | return $this; |
| 282 | 282 | } |
@@ -284,7 +284,7 @@ discard block |
||
| 284 | 284 | /** |
| 285 | 285 | * @return string |
| 286 | 286 | */ |
| 287 | - public function toSql (): string { |
|
| 287 | + public function toSql(): string { |
|
| 288 | 288 | $sql = 'SELECT ' . implode(', ', $this->columns) . ' FROM ' . $this->table; |
| 289 | 289 | $sql .= $this->_join; |
| 290 | 290 | if (!empty($this->_where)) { |
@@ -304,7 +304,7 @@ discard block |
||
| 304 | 304 | * |
| 305 | 305 | * @return string |
| 306 | 306 | */ |
| 307 | - public function toSubquery (): string { |
|
| 307 | + public function toSubquery(): string { |
|
| 308 | 308 | return "({$this->toSql()}) AS {$this->alias}"; |
| 309 | 309 | } |
| 310 | 310 | |
@@ -314,7 +314,7 @@ discard block |
||
| 314 | 314 | * @param string $condition |
| 315 | 315 | * @return $this |
| 316 | 316 | */ |
| 317 | - public function where (string $condition) { |
|
| 317 | + public function where(string $condition) { |
|
| 318 | 318 | $this->_where[] = $condition; |
| 319 | 319 | return $this; |
| 320 | 320 | } |
@@ -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; |
@@ -221,8 +219,7 @@ discard block |
||
| 221 | 219 | public function limit (int $limit, int $offset = 0) { |
| 222 | 220 | if ($limit == 0) { |
| 223 | 221 | $this->_limit = ''; |
| 224 | - } |
|
| 225 | - else { |
|
| 222 | + } else { |
|
| 226 | 223 | $this->_limit = " LIMIT {$limit}"; |
| 227 | 224 | if ($offset > 1) { |
| 228 | 225 | $this->_limit .= " OFFSET {$offset}"; |