@@ -14,34 +14,34 @@ |
||
14 | 14 | * @return string |
15 | 15 | */ |
16 | 16 | protected function buildTableName(?string $alias, $name): string { |
17 | - if(is_object($name) && !($name instanceof VirtualTable) && method_exists($name, '__toString')) { |
|
17 | + if (is_object($name) && !($name instanceof VirtualTable) && method_exists($name, '__toString')) { |
|
18 | 18 | $name = (string) $name; |
19 | 19 | $lines = explode("\n", $name); |
20 | - $lines = array_map(static function (string $line) { return "\t{$line}"; }, $lines); |
|
20 | + $lines = array_map(static function(string $line) { return "\t{$line}"; }, $lines); |
|
21 | 21 | $name = implode("\n", $lines); |
22 | - $name = '(' . trim(rtrim(trim($name), ';')) . ')'; |
|
22 | + $name = '('.trim(rtrim(trim($name), ';')).')'; |
|
23 | 23 | } |
24 | - if(is_array($name)) { |
|
24 | + if (is_array($name)) { |
|
25 | 25 | $parts = []; |
26 | - foreach($name as $index => $bucket) { |
|
27 | - if(is_scalar($bucket) && ctype_digit((string) $index)) { |
|
26 | + foreach ($name as $index => $bucket) { |
|
27 | + if (is_scalar($bucket) && ctype_digit((string) $index)) { |
|
28 | 28 | $parts[] = "SELECT {$this->db()->quote($bucket)} AS {$this->db()->quoteField('value')}"; |
29 | 29 | } else { |
30 | 30 | $values = []; |
31 | - foreach($bucket as $field => $value) { |
|
31 | + foreach ($bucket as $field => $value) { |
|
32 | 32 | $values[] = sprintf('%s AS %s', $this->db()->quote($value), $this->db()->quoteField($field)); |
33 | 33 | } |
34 | 34 | $parts[] = sprintf("SELECT %s", implode(', ', $values)); |
35 | 35 | } |
36 | 36 | } |
37 | - $name = '(' . implode("\n\tUNION\n\t", $parts) . ')'; |
|
37 | + $name = '('.implode("\n\tUNION\n\t", $parts).')'; |
|
38 | 38 | } |
39 | - if((is_string($name) || $name instanceof VirtualTable) && $this->db()->getVirtualTables()->has($name)) { |
|
39 | + if ((is_string($name) || $name instanceof VirtualTable) && $this->db()->getVirtualTables()->has($name)) { |
|
40 | 40 | $select = (string) $this->db()->getVirtualTables()->get($name); |
41 | 41 | $name = sprintf('(%s)', implode("\n\t", explode("\n", trim($select)))); |
42 | 42 | } |
43 | 43 | $name = $this->aliasReplacer()->replace((string) $name); |
44 | - if($alias !== null) { |
|
44 | + if ($alias !== null) { |
|
45 | 45 | return sprintf("%s %s", $name, $alias); |
46 | 46 | } |
47 | 47 | return $name; |
@@ -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); |