@@ -61,7 +61,7 @@ |
||
| 61 | 61 | * @return $this |
| 62 | 62 | */ |
| 63 | 63 | public function setExpr($expr, ...$args) { |
| 64 | - if(count($args) > 0) { |
|
| 64 | + if (count($args) > 0) { |
|
| 65 | 65 | $this->fields[] = func_get_args(); |
| 66 | 66 | } else { |
| 67 | 67 | $this->fields[] = $expr; |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | * @return $this |
| 87 | 87 | */ |
| 88 | 88 | public function addExpr($str, ...$args) { |
| 89 | - if(count($args) > 0) { |
|
| 89 | + if (count($args) > 0) { |
|
| 90 | 90 | $this->fields[] = func_get_args(); |
| 91 | 91 | } else { |
| 92 | 92 | $this->fields[] = $str; |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | * @return $this |
| 101 | 101 | */ |
| 102 | 102 | public function updateExpr($str, ...$args) { |
| 103 | - if(count($args) > 0) { |
|
| 103 | + if (count($args) > 0) { |
|
| 104 | 104 | $this->update[] = func_get_args(); |
| 105 | 105 | } else { |
| 106 | 106 | $this->update[] = $str; |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | * @return $this |
| 115 | 115 | */ |
| 116 | 116 | public function addOrUpdateExpr($expr, ...$args) { |
| 117 | - if(count($args) > 0) { |
|
| 117 | + if (count($args) > 0) { |
|
| 118 | 118 | $this->fields[] = func_get_args(); |
| 119 | 119 | $this->update[] = func_get_args(); |
| 120 | 120 | } else { |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | * @return $this |
| 132 | 132 | */ |
| 133 | 133 | public function addAll(array $data, array $mask = null, array $excludeFields = null) { |
| 134 | - $this->addAllTo($data, $mask, $excludeFields, function ($field, $value) { |
|
| 134 | + $this->addAllTo($data, $mask, $excludeFields, function($field, $value) { |
|
| 135 | 135 | $this->add($field, $value); |
| 136 | 136 | }); |
| 137 | 137 | return $this; |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | * @return $this |
| 145 | 145 | */ |
| 146 | 146 | public function updateAll(array $data, array $mask = null, array $excludeFields = null) { |
| 147 | - $this->addAllTo($data, $mask, $excludeFields, function ($field, $value) { |
|
| 147 | + $this->addAllTo($data, $mask, $excludeFields, function($field, $value) { |
|
| 148 | 148 | if ($field !== $this->keyField) { |
| 149 | 149 | $this->update($field, $value); |
| 150 | 150 | } |
@@ -187,7 +187,7 @@ discard block |
||
| 187 | 187 | $ignoreStr = $this->ignore ? ' IGNORE' : ''; |
| 188 | 188 | $queryArr[] = "INSERT{$ignoreStr} INTO\n\t{$tableName}\n"; |
| 189 | 189 | |
| 190 | - if($this->from !== null) { |
|
| 190 | + if ($this->from !== null) { |
|
| 191 | 191 | $fields = $this->from->getFields(); |
| 192 | 192 | $queryArr[] = sprintf("\t(%s)\n", join(', ', array_keys($fields))); |
| 193 | 193 | $queryArr[] = $this->from; |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | $updateData = $this->buildUpdate(); |
| 204 | - if($updateData) { |
|
| 204 | + if ($updateData) { |
|
| 205 | 205 | $queryArr[] = "{$updateData}\n"; |
| 206 | 206 | } |
| 207 | 207 | |
@@ -234,12 +234,12 @@ discard block |
||
| 234 | 234 | * @return $this |
| 235 | 235 | */ |
| 236 | 236 | private function addAllTo(array $data, array $mask = null, array $excludeFields = null, $fn) { |
| 237 | - if($mask !== null) { |
|
| 237 | + if ($mask !== null) { |
|
| 238 | 238 | $data = array_intersect_key($data, array_combine($mask, $mask)); |
| 239 | 239 | } |
| 240 | - if($excludeFields !== null) { |
|
| 241 | - foreach($excludeFields as $excludeField) { |
|
| 242 | - if(array_key_exists($excludeField, $data)) { |
|
| 240 | + if ($excludeFields !== null) { |
|
| 241 | + foreach ($excludeFields as $excludeField) { |
|
| 242 | + if (array_key_exists($excludeField, $data)) { |
|
| 243 | 243 | unset($data[$excludeField]); |
| 244 | 244 | } |
| 245 | 245 | } |
@@ -256,10 +256,10 @@ discard block |
||
| 256 | 256 | */ |
| 257 | 257 | private function buildUpdate() { |
| 258 | 258 | $queryArr = []; |
| 259 | - if(!empty($this->update)) { |
|
| 259 | + if (!empty($this->update)) { |
|
| 260 | 260 | $queryArr[] = "ON DUPLICATE KEY UPDATE\n"; |
| 261 | 261 | $updateArr = []; |
| 262 | - if($this->keyField !== null) { |
|
| 262 | + if ($this->keyField !== null) { |
|
| 263 | 263 | $updateArr[] = "\t`{$this->keyField}` = LAST_INSERT_ID({$this->keyField})"; |
| 264 | 264 | } |
| 265 | 265 | $updateArr = $this->buildFieldList($this->update, $updateArr); |
@@ -282,7 +282,7 @@ discard block |
||
| 282 | 282 | * @return array |
| 283 | 283 | */ |
| 284 | 284 | private function clearValues(array $values) { |
| 285 | - if(!count($values)) { |
|
| 285 | + if (!count($values)) { |
|
| 286 | 286 | return []; |
| 287 | 287 | } |
| 288 | 288 | |
@@ -291,7 +291,7 @@ discard block |
||
| 291 | 291 | $result = []; |
| 292 | 292 | |
| 293 | 293 | foreach ($values as $fieldName => $fieldValue) { |
| 294 | - if(in_array($fieldName, $fields)) { |
|
| 294 | + if (in_array($fieldName, $fields)) { |
|
| 295 | 295 | $result[$fieldName] = $fieldValue; |
| 296 | 296 | } |
| 297 | 297 | } |
@@ -12,9 +12,9 @@ discard block |
||
| 12 | 12 | * @return $this |
| 13 | 13 | */ |
| 14 | 14 | public function groupBy(...$args) { |
| 15 | - foreach($args as $expression) { |
|
| 16 | - if(is_array($expression)) { |
|
| 17 | - if(!count($expression)) { |
|
| 15 | + foreach ($args as $expression) { |
|
| 16 | + if (is_array($expression)) { |
|
| 17 | + if (!count($expression)) { |
|
| 18 | 18 | continue; |
| 19 | 19 | } |
| 20 | 20 | $arguments = [ |
@@ -33,12 +33,12 @@ discard block |
||
| 33 | 33 | * @return string |
| 34 | 34 | */ |
| 35 | 35 | protected function buildGroups($query) { |
| 36 | - if(!count($this->groupBy)) { |
|
| 36 | + if (!count($this->groupBy)) { |
|
| 37 | 37 | return $query; |
| 38 | 38 | } |
| 39 | 39 | $query .= "GROUP BY\n"; |
| 40 | 40 | $arr = []; |
| 41 | - foreach($this->groupBy as $expression) { |
|
| 41 | + foreach ($this->groupBy as $expression) { |
|
| 42 | 42 | $arr[] = "\t{$expression}"; |
| 43 | 43 | } |
| 44 | 44 | return $query.join(",\n", $arr)."\n"; |
@@ -17,8 +17,8 @@ |
||
| 17 | 17 | * @return $this |
| 18 | 18 | */ |
| 19 | 19 | public function where($expression, ...$args) { |
| 20 | - if($expression instanceof OptionalExpression) { |
|
| 21 | - if($expression->isValid()) { |
|
| 20 | + if ($expression instanceof OptionalExpression) { |
|
| 21 | + if ($expression->isValid()) { |
|
| 22 | 22 | $this->where[] = [$expression->getExpression(), $expression->getValue()]; |
| 23 | 23 | } |
| 24 | 24 | } else { |
@@ -16,8 +16,8 @@ |
||
| 16 | 16 | * @return $this |
| 17 | 17 | */ |
| 18 | 18 | public function having($expression, ...$args) { |
| 19 | - if($expression instanceof OptionalExpression) { |
|
| 20 | - if($expression->isValid()) { |
|
| 19 | + if ($expression instanceof OptionalExpression) { |
|
| 20 | + if ($expression->isValid()) { |
|
| 21 | 21 | $this->having[] = [$expression->getExpression(), $expression->getValue()]; |
| 22 | 22 | } |
| 23 | 23 | } else { |
@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | * @return $this |
| 15 | 15 | */ |
| 16 | 16 | public function union(...$queries) { |
| 17 | - foreach($queries as $query) { |
|
| 17 | + foreach ($queries as $query) { |
|
| 18 | 18 | $this->unions[] = ['', $query]; |
| 19 | 19 | } |
| 20 | 20 | return $this; |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | * @return $this |
| 26 | 26 | */ |
| 27 | 27 | public function unionAll(...$queries) { |
| 28 | - foreach($queries as $query) { |
|
| 28 | + foreach ($queries as $query) { |
|
| 29 | 29 | $this->unions[] = ['ALL', $query]; |
| 30 | 30 | } |
| 31 | 31 | return $this; |
@@ -36,21 +36,21 @@ discard block |
||
| 36 | 36 | * @return string |
| 37 | 37 | */ |
| 38 | 38 | protected function buildUnions($query) { |
| 39 | - $wrap = function ($query) { |
|
| 39 | + $wrap = function($query) { |
|
| 40 | 40 | $query = trim($query); |
| 41 | 41 | $query = join("\n\t", explode("\n", $query)); |
| 42 | 42 | return sprintf("(\n\t%s\n)", $query); |
| 43 | 43 | }; |
| 44 | 44 | $queries = [$wrap($query)]; |
| 45 | - foreach($this->unions as $unionQuery) { |
|
| 46 | - if($unionQuery[0] === 'ALL') { |
|
| 45 | + foreach ($this->unions as $unionQuery) { |
|
| 46 | + if ($unionQuery[0] === 'ALL') { |
|
| 47 | 47 | $queries[] = 'UNION ALL'; |
| 48 | 48 | } else { |
| 49 | 49 | $queries[] = 'UNION'; |
| 50 | 50 | } |
| 51 | 51 | $queries[] = $wrap($unionQuery[1]); |
| 52 | 52 | } |
| 53 | - if(count($queries) > 1) { |
|
| 53 | + if (count($queries) > 1) { |
|
| 54 | 54 | return join(" ", $queries); |
| 55 | 55 | } |
| 56 | 56 | return $query; |