@@ -14,9 +14,9 @@ discard block |
||
| 14 | 14 | * @return $this |
| 15 | 15 | */ |
| 16 | 16 | public function groupBy(...$args) { |
| 17 | - foreach($args as $expression) { |
|
| 18 | - if(is_array($expression)) { |
|
| 19 | - if(!count($expression)) { |
|
| 17 | + foreach ($args as $expression) { |
|
| 18 | + if (is_array($expression)) { |
|
| 19 | + if (!count($expression)) { |
|
| 20 | 20 | continue; |
| 21 | 21 | } |
| 22 | 22 | $expression = $this->quoteExpr($expression[0], array_slice($expression, 1)); |
@@ -31,12 +31,12 @@ discard block |
||
| 31 | 31 | * @return string |
| 32 | 32 | */ |
| 33 | 33 | protected function buildGroups(string $query): string { |
| 34 | - if(!count($this->groupBy)) { |
|
| 34 | + if (!count($this->groupBy)) { |
|
| 35 | 35 | return $query; |
| 36 | 36 | } |
| 37 | 37 | $query .= "GROUP BY\n"; |
| 38 | 38 | $arr = []; |
| 39 | - foreach($this->groupBy as $expression) { |
|
| 39 | + foreach ($this->groupBy as $expression) { |
|
| 40 | 40 | $arr[] = "\t{$expression}"; |
| 41 | 41 | } |
| 42 | 42 | return $query.implode(",\n", $arr)."\n"; |
@@ -17,7 +17,7 @@ |
||
| 17 | 17 | * @return $this |
| 18 | 18 | */ |
| 19 | 19 | public function having($expression, ...$args): self { |
| 20 | - $fn = function ($expression, $args) { $this->having[] = [$expression, $args]; }; |
|
| 20 | + $fn = function($expression, $args) { $this->having[] = [$expression, $args]; }; |
|
| 21 | 21 | ConditionAddHelper::addCondition($fn, $expression, $args); |
| 22 | 22 | return $this; |
| 23 | 23 | } |
@@ -26,10 +26,10 @@ |
||
| 26 | 26 | */ |
| 27 | 27 | protected function buildTables(string $query): string { |
| 28 | 28 | $arr = []; |
| 29 | - foreach($this->tables as $table) { |
|
| 29 | + foreach ($this->tables as $table) { |
|
| 30 | 30 | $arr[] = "\t".$this->buildTableName($table['alias'], $table['name']); |
| 31 | 31 | } |
| 32 | - if(count($arr)) { |
|
| 32 | + if (count($arr)) { |
|
| 33 | 33 | $query .= implode(",\n", $arr)."\n"; |
| 34 | 34 | } |
| 35 | 35 | return $query; |
@@ -15,8 +15,8 @@ discard block |
||
| 15 | 15 | * @return $this |
| 16 | 16 | */ |
| 17 | 17 | public function orderBy($expression, string $direction = 'ASC'): self { |
| 18 | - if($expression instanceof OrderBySpecification) { |
|
| 19 | - foreach($expression->getFields() as $field) { |
|
| 18 | + if ($expression instanceof OrderBySpecification) { |
|
| 19 | + foreach ($expression->getFields() as $field) { |
|
| 20 | 20 | $this->addOrder($field[0], $field[1]); |
| 21 | 21 | } |
| 22 | 22 | return $this; |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | */ |
| 33 | 33 | public function orderByValues(string $fieldName, array $values): self { |
| 34 | 34 | $expr = []; |
| 35 | - foreach(array_values($values) as $idx => $value) { |
|
| 35 | + foreach (array_values($values) as $idx => $value) { |
|
| 36 | 36 | $expr[] = $this->db()->quoteExpression("WHEN ? THEN ?", [$value, $idx]); |
| 37 | 37 | } |
| 38 | 38 | $this->orderBy[] = [sprintf("CASE %s\n\t\t%s\n\tEND", $this->db()->quoteField($fieldName), implode("\n\t\t", $expr)), 'ASC']; |
@@ -44,12 +44,12 @@ discard block |
||
| 44 | 44 | * @return string |
| 45 | 45 | */ |
| 46 | 46 | protected function buildOrder(string $query): string { |
| 47 | - if(!count($this->orderBy)) { |
|
| 47 | + if (!count($this->orderBy)) { |
|
| 48 | 48 | return $query; |
| 49 | 49 | } |
| 50 | 50 | $query .= "ORDER BY\n"; |
| 51 | 51 | $arr = []; |
| 52 | - foreach($this->orderBy as [$expression, $direction]) { |
|
| 52 | + foreach ($this->orderBy as [$expression, $direction]) { |
|
| 53 | 53 | $arr[] = sprintf("\t%s %s", $expression, strtoupper($direction)); |
| 54 | 54 | } |
| 55 | 55 | return $query.implode(",\n", $arr)."\n"; |
@@ -61,8 +61,8 @@ discard block |
||
| 61 | 61 | */ |
| 62 | 62 | private function addOrder($expression, string $direction): void { |
| 63 | 63 | $direction = $this->fixDirection($direction); |
| 64 | - if(is_array($expression)) { |
|
| 65 | - if(count($expression) < 1) { |
|
| 64 | + if (is_array($expression)) { |
|
| 65 | + if (count($expression) < 1) { |
|
| 66 | 66 | return; |
| 67 | 67 | } |
| 68 | 68 | $expr = (string) $expression[0]; |
@@ -17,7 +17,7 @@ |
||
| 17 | 17 | * @return $this |
| 18 | 18 | */ |
| 19 | 19 | public function where($expression, ...$args): self { |
| 20 | - $fn = function ($expression, $args) { $this->where[] = [$expression, $args]; }; |
|
| 20 | + $fn = function($expression, $args) { $this->where[] = [$expression, $args]; }; |
|
| 21 | 21 | ConditionAddHelper::addCondition($fn, $expression, $args); |
| 22 | 22 | return $this; |
| 23 | 23 | } |
@@ -31,13 +31,13 @@ |
||
| 31 | 31 | */ |
| 32 | 32 | protected function buildFieldList(array $fields, array $query = []): array { |
| 33 | 33 | foreach ($fields as $fieldName => $fieldValue) { |
| 34 | - if($fieldValue instanceof DefaultValue) { |
|
| 34 | + if ($fieldValue instanceof DefaultValue) { |
|
| 35 | 35 | $fieldValue = 'DEFAULT'; |
| 36 | 36 | } |
| 37 | - if(is_array($this->mask) && !in_array($fieldName, $this->mask, true)) { |
|
| 37 | + if (is_array($this->mask) && !in_array($fieldName, $this->mask, true)) { |
|
| 38 | 38 | continue; |
| 39 | 39 | } |
| 40 | - if(is_int($fieldName)) { |
|
| 40 | + if (is_int($fieldName)) { |
|
| 41 | 41 | if (is_array($fieldValue)) { |
| 42 | 42 | $fieldValue = $this->db()->quoteExpression($fieldValue[0], array_slice($fieldValue, 1)); |
| 43 | 43 | } |
@@ -47,10 +47,10 @@ discard block |
||
| 47 | 47 | */ |
| 48 | 48 | public function setFetchMode(int $mode = PDO::FETCH_ASSOC, $arg0 = null, ?array $arg1 = null) { |
| 49 | 49 | $args = [$mode]; |
| 50 | - if($arg0 !== null) { |
|
| 50 | + if ($arg0 !== null) { |
|
| 51 | 51 | $args[] = $arg0; |
| 52 | 52 | } |
| 53 | - if($arg1 !== null) { |
|
| 53 | + if ($arg1 !== null) { |
|
| 54 | 54 | $args[] = $arg1; |
| 55 | 55 | } |
| 56 | 56 | $this->statement->setFetchMode(...$args); |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | $timer = microtime(true); |
| 68 | 68 | $response = $this->statement->execute($params); |
| 69 | 69 | $this->queryLoggers->log($this->query, microtime(true)-$timer); |
| 70 | - if(!$response) { |
|
| 70 | + if (!$response) { |
|
| 71 | 71 | throw new SqlException('Execution returned with "false".'); |
| 72 | 72 | } |
| 73 | 73 | }); |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | */ |
| 83 | 83 | public function fetchAll($fetchStyle = PDO::FETCH_ASSOC, $fetchArgument = null, array $ctorArgs = []): array { |
| 84 | 84 | return $this->exceptionHandler(function() use ($fetchStyle, $fetchArgument, $ctorArgs) { |
| 85 | - if($fetchArgument !== null) { |
|
| 85 | + if ($fetchArgument !== null) { |
|
| 86 | 86 | return $this->statement->fetchAll($fetchStyle, $fetchArgument, $ctorArgs); |
| 87 | 87 | } |
| 88 | 88 | return $this->statement->fetchAll($fetchStyle); |
@@ -29,10 +29,10 @@ discard block |
||
| 29 | 29 | * @return $this |
| 30 | 30 | */ |
| 31 | 31 | public function from(string $alias, $table = null) { |
| 32 | - if($table !== null) { |
|
| 32 | + if ($table !== null) { |
|
| 33 | 33 | $this->aliases[] = $alias; |
| 34 | 34 | } |
| 35 | - if($table === null) { |
|
| 35 | + if ($table === null) { |
|
| 36 | 36 | [$alias, $table] = [$table, $alias]; |
| 37 | 37 | } |
| 38 | 38 | $this->addTable($alias, $table); |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | public function __toString(): string { |
| 52 | 52 | $query = "DELETE "; |
| 53 | 53 | $query .= implode(', ', $this->aliases); |
| 54 | - $query = trim($query) . " FROM\n"; |
|
| 54 | + $query = trim($query)." FROM\n"; |
|
| 55 | 55 | $query = $this->buildTables($query); |
| 56 | 56 | $query = $this->buildJoins($query); |
| 57 | 57 | $query = $this->buildWhereConditions($query); |
@@ -10,13 +10,13 @@ discard block |
||
| 10 | 10 | * @param array<int, mixed> $args |
| 11 | 11 | */ |
| 12 | 12 | public static function addCondition(callable $addFn, $expression, array $args): void { |
| 13 | - if($expression instanceof OptionalExpression) { |
|
| 14 | - if($expression->isValid()) { |
|
| 13 | + if ($expression instanceof OptionalExpression) { |
|
| 14 | + if ($expression->isValid()) { |
|
| 15 | 15 | $addFn($expression->getExpression(), [$expression->getValue()]); |
| 16 | 16 | } |
| 17 | - } elseif(is_object($expression)) { |
|
| 17 | + } elseif (is_object($expression)) { |
|
| 18 | 18 | self::addAsArray($addFn, (array) $expression, $args); |
| 19 | - } elseif(is_array($expression)) { |
|
| 19 | + } elseif (is_array($expression)) { |
|
| 20 | 20 | self::addAsArray($addFn, $expression, $args); |
| 21 | 21 | } else { |
| 22 | 22 | $addFn($expression, $args); |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | * @param array<int, mixed> $args |
| 30 | 30 | */ |
| 31 | 31 | private static function addAsArray(callable $addFn, array $expression, array $args): void { |
| 32 | - if(count($expression) > 0) { |
|
| 32 | + if (count($expression) > 0) { |
|
| 33 | 33 | $addFn($expression, $args); |
| 34 | 34 | } |
| 35 | 35 | } |