@@ -17,34 +17,34 @@ |
||
17 | 17 | * @return string |
18 | 18 | */ |
19 | 19 | protected function buildTableName(?string $alias, $name): string { |
20 | - if(is_object($name) && !($name instanceof VirtualTable) && method_exists($name, '__toString')) { |
|
20 | + if (is_object($name) && !($name instanceof VirtualTable) && method_exists($name, '__toString')) { |
|
21 | 21 | $name = (string) $name; |
22 | 22 | $lines = explode("\n", $name); |
23 | 23 | $lines = array_map(static fn(string $line) => "\t{$line}", $lines); |
24 | 24 | $name = implode("\n", $lines); |
25 | - $name = '(' . trim(rtrim(trim($name), ';')) . ')'; |
|
25 | + $name = '('.trim(rtrim(trim($name), ';')).')'; |
|
26 | 26 | } |
27 | - if(is_array($name)) { |
|
27 | + if (is_array($name)) { |
|
28 | 28 | $parts = []; |
29 | - foreach($name as /*$index => */$bucket) { |
|
30 | - if(is_scalar($bucket)/* && ctype_digit((string) $index)*/) { |
|
29 | + foreach ($name as /*$index => */$bucket) { |
|
30 | + if (is_scalar($bucket)/* && ctype_digit((string) $index)*/) { |
|
31 | 31 | $parts[] = "SELECT {$this->db()->quote($bucket)} AS {$this->db()->quoteField('value')}"; |
32 | 32 | } else { |
33 | 33 | $values = []; |
34 | - foreach($bucket as $field => $value) { |
|
34 | + foreach ($bucket as $field => $value) { |
|
35 | 35 | $values[] = sprintf('%s AS %s', $this->db()->quote($value), $this->db()->quoteField($field)); |
36 | 36 | } |
37 | 37 | $parts[] = sprintf("SELECT %s", implode(', ', $values)); |
38 | 38 | } |
39 | 39 | } |
40 | - $name = '(' . implode("\n\tUNION ALL\n\t", $parts) . ')'; |
|
40 | + $name = '('.implode("\n\tUNION ALL\n\t", $parts).')'; |
|
41 | 41 | } |
42 | - if((is_string($name) || $name instanceof VirtualTable) && $this->db()->getVirtualTables()->has($name)) { |
|
42 | + if ((is_string($name) || $name instanceof VirtualTable) && $this->db()->getVirtualTables()->has($name)) { |
|
43 | 43 | $select = (string) $this->db()->getVirtualTables()->get($name); |
44 | 44 | $name = sprintf('(%s)', implode("\n\t", explode("\n", trim($select)))); |
45 | 45 | } |
46 | 46 | $name = $this->aliasReplacer()->replace((string) $name); |
47 | - if($alias !== null) { |
|
47 | + if ($alias !== null) { |
|
48 | 48 | return sprintf("%s %s", $name, $alias); |
49 | 49 | } |
50 | 50 | return $name; |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | * @return $this |
34 | 34 | */ |
35 | 35 | public function table($alias, $table = null): self { |
36 | - if($table === null) { |
|
36 | + if ($table === null) { |
|
37 | 37 | [$alias, $table] = [$table, $alias]; |
38 | 38 | } |
39 | 39 | $this->addTable($alias, $table); |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | * @return $this |
69 | 69 | */ |
70 | 70 | public function setExpr(string $expr, ...$args): self { |
71 | - if(count($args) > 0) { |
|
71 | + if (count($args) > 0) { |
|
72 | 72 | $this->fields[] = func_get_args(); |
73 | 73 | } else { |
74 | 74 | $this->fields[] = $expr; |
@@ -82,15 +82,15 @@ discard block |
||
82 | 82 | * @return $this |
83 | 83 | */ |
84 | 84 | public function setAll(array $data, ?array $allowedFields = null): self { |
85 | - if($allowedFields !== null) { |
|
86 | - foreach($data as $fieldName => $value) { |
|
87 | - if(in_array($fieldName, $allowedFields)) { |
|
85 | + if ($allowedFields !== null) { |
|
86 | + foreach ($data as $fieldName => $value) { |
|
87 | + if (in_array($fieldName, $allowedFields)) { |
|
88 | 88 | $this->set($fieldName, $value); |
89 | 89 | } |
90 | 90 | } |
91 | 91 | } else { |
92 | 92 | $values = $this->clearValues($data); |
93 | - foreach($values as $fieldName => $value) { |
|
93 | + foreach ($values as $fieldName => $value) { |
|
94 | 94 | $this->set($fieldName, $value); |
95 | 95 | } |
96 | 96 | } |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | */ |
126 | 126 | private function buildAssignments(string $query): string { |
127 | 127 | $sqlFields = $this->buildFieldList($this->fields); |
128 | - if(!count($sqlFields)) { |
|
128 | + if (!count($sqlFields)) { |
|
129 | 129 | throw new RuntimeException('No field-data found'); |
130 | 130 | } |
131 | 131 | return sprintf("%s%s\n", $query, implode(",\n", $sqlFields)); |
@@ -136,14 +136,14 @@ discard block |
||
136 | 136 | * @return array<string, mixed> |
137 | 137 | */ |
138 | 138 | private function clearValues(array $values): array { |
139 | - if(!count($values)) { |
|
139 | + if (!count($values)) { |
|
140 | 140 | return []; |
141 | 141 | } |
142 | 142 | $tables = $this->getTables(); |
143 | - if(!count($tables)) { |
|
143 | + if (!count($tables)) { |
|
144 | 144 | throw new RuntimeException('Table name is missing'); |
145 | 145 | } |
146 | - if(count($tables) > 1) { |
|
146 | + if (count($tables) > 1) { |
|
147 | 147 | throw new RuntimeException('Batch values only work with max. one table'); |
148 | 148 | } |
149 | 149 | |
@@ -151,11 +151,11 @@ discard block |
||
151 | 151 | $tableName = $table['name']; |
152 | 152 | |
153 | 153 | $result = []; |
154 | - if(is_string($tableName)) { |
|
154 | + if (is_string($tableName)) { |
|
155 | 155 | $fields = $this->db()->getTableFields($tableName); |
156 | 156 | |
157 | - foreach($values as $fieldName => $fieldValue) { |
|
158 | - if(in_array($fieldName, $fields, true)) { |
|
157 | + foreach ($values as $fieldName => $fieldValue) { |
|
158 | + if (in_array($fieldName, $fields, true)) { |
|
159 | 159 | $result[$fieldName] = $fieldValue; |
160 | 160 | } |
161 | 161 | } |
@@ -33,10 +33,10 @@ discard block |
||
33 | 33 | * @return $this |
34 | 34 | */ |
35 | 35 | public function from($alias, $table = null) { |
36 | - if($table !== null) { |
|
36 | + if ($table !== null) { |
|
37 | 37 | $this->aliases[] = $alias; |
38 | 38 | } |
39 | - if($table === null) { |
|
39 | + if ($table === null) { |
|
40 | 40 | [$alias, $table] = [$table, $alias]; |
41 | 41 | } |
42 | 42 | $this->addTable($alias, $table); |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | public function __toString(): string { |
56 | 56 | $query = 'DELETE '; |
57 | 57 | $query .= implode(', ', $this->aliases); |
58 | - $query = trim($query) . " FROM\n"; |
|
58 | + $query = trim($query)." FROM\n"; |
|
59 | 59 | $query = $this->buildTables($query); |
60 | 60 | $query = $this->buildJoins($query); |
61 | 61 | $query = $this->buildWhereConditions($query); |
@@ -123,7 +123,7 @@ |
||
123 | 123 | * @return $this |
124 | 124 | */ |
125 | 125 | public function from($alias, $table = null) { |
126 | - if($table === null) { |
|
126 | + if ($table === null) { |
|
127 | 127 | [$alias, $table] = [$table, $alias]; |
128 | 128 | $this->addTable($alias, (string) $table); |
129 | 129 | } else { |