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