@@ -25,7 +25,7 @@ |
||
25 | 25 | public function run(array $params = []) { |
26 | 26 | $this->query->execute($params); |
27 | 27 | $response = $this->query->getStatement()->rowCount(); |
28 | - if($this->callbackFn !== null) { |
|
28 | + if ($this->callbackFn !== null) { |
|
29 | 29 | $response = call_user_func($this->callbackFn, $response); |
30 | 30 | } |
31 | 31 | return $response; |
@@ -31,10 +31,10 @@ |
||
31 | 31 | * @return Select|null |
32 | 32 | */ |
33 | 33 | public function get($tableName): ?Select { |
34 | - if($this->has($tableName)) { |
|
34 | + if ($this->has($tableName)) { |
|
35 | 35 | $table = $this->virtualTables[(string) $tableName]; |
36 | - if($table instanceof Closure) { |
|
37 | - if($tableName instanceof VirtualTable) { |
|
36 | + if ($table instanceof Closure) { |
|
37 | + if ($tableName instanceof VirtualTable) { |
|
38 | 38 | $params = $tableName->getParams(); |
39 | 39 | return $table($params); |
40 | 40 | } |
@@ -49,15 +49,15 @@ |
||
49 | 49 | */ |
50 | 50 | protected function buildJoins(string $query): string { |
51 | 51 | $arr = []; |
52 | - foreach($this->joinTables as $table) { |
|
52 | + foreach ($this->joinTables as $table) { |
|
53 | 53 | $join = $table['type']." JOIN\n"; |
54 | - $join .= "\t" . $this->buildTableName($table['alias'], $table['name']); |
|
55 | - if($table['expression']) { |
|
56 | - $join .= " ON " . $this->db()->quoteExpression($table['expression'], $table['arguments']); |
|
54 | + $join .= "\t".$this->buildTableName($table['alias'], $table['name']); |
|
55 | + if ($table['expression']) { |
|
56 | + $join .= " ON ".$this->db()->quoteExpression($table['expression'], $table['arguments']); |
|
57 | 57 | } |
58 | 58 | $arr[] = $join; |
59 | 59 | } |
60 | - if(count($arr)) { |
|
60 | + if (count($arr)) { |
|
61 | 61 | $query .= implode("\n", $arr)."\n"; |
62 | 62 | } |
63 | 63 | 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; |
@@ -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"; |
@@ -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; |
@@ -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 | } |
@@ -9,8 +9,8 @@ |
||
9 | 9 | */ |
10 | 10 | public static function convertValues(array $row, array $columnDefinitions): array { |
11 | 11 | $result = []; |
12 | - foreach($row as $key => $value) { |
|
13 | - if($value !== null) { |
|
12 | + foreach ($row as $key => $value) { |
|
13 | + if ($value !== null) { |
|
14 | 14 | $result[$key] = self::convertValue($value, $columnDefinitions[$key]); |
15 | 15 | } else { |
16 | 16 | $result[$key] = $value; |
@@ -29,14 +29,14 @@ |
||
29 | 29 | * @return $this |
30 | 30 | */ |
31 | 31 | public function debug($stop = true) { |
32 | - if(array_key_exists('debug_formatter', $this->options)) { |
|
32 | + if (array_key_exists('debug_formatter', $this->options)) { |
|
33 | 33 | $this->options['debug_formatter'](); |
34 | - } elseif(PHP_SAPI === 'cli') { |
|
34 | + } elseif (PHP_SAPI === 'cli') { |
|
35 | 35 | echo "\n{$this->__toString()}\n"; |
36 | 36 | } else { |
37 | 37 | echo "<pre>{$this->__toString()}</pre>"; |
38 | 38 | } |
39 | - if($stop) { |
|
39 | + if ($stop) { |
|
40 | 40 | exit; |
41 | 41 | } |
42 | 42 | return $this; |