@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | |
41 | 41 | /** @var array<string> $result */ |
42 | 42 | $result = []; |
43 | - foreach($rows as $row) { |
|
43 | + foreach ($rows as $row) { |
|
44 | 44 | $result[] = $row['Field']; |
45 | 45 | } |
46 | 46 | |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | |
60 | 60 | /** @var array<string> $result */ |
61 | 61 | $result = []; |
62 | - foreach($rows as $row) { |
|
62 | + foreach ($rows as $row) { |
|
63 | 63 | $result[] = $row['Field']; |
64 | 64 | } |
65 | 65 |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | $this->query .= 'SELECT '; |
67 | 67 | |
68 | 68 | $buf = []; |
69 | - foreach($arSelect as $alias => $field) { |
|
69 | + foreach ($arSelect as $alias => $field) { |
|
70 | 70 | $buf[] = addslashes($field).' AS '.addslashes($alias); |
71 | 71 | } |
72 | 72 | |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | { |
83 | 83 | $this->query .= ' FROM '; |
84 | 84 | |
85 | - foreach($mapFrom as $alias => $tableName) { |
|
85 | + foreach ($mapFrom as $alias => $tableName) { |
|
86 | 86 | $this->query .= ' '.addslashes($tableName).' '.addslashes($alias).' '; |
87 | 87 | break; |
88 | 88 | } |
@@ -101,14 +101,14 @@ discard block |
||
101 | 101 | ): QueryWrapperInterface { |
102 | 102 | $this->query .= " ".addslashes($type)." JOIN "; |
103 | 103 | |
104 | - foreach($mapTable as $alias => $tableName) { |
|
104 | + foreach ($mapTable as $alias => $tableName) { |
|
105 | 105 | $this->query .= addslashes($tableName).' '.addslashes($alias).' '; |
106 | 106 | break; |
107 | 107 | } |
108 | 108 | |
109 | 109 | $this->query .= " ON {$condition} "; |
110 | 110 | |
111 | - foreach($extraJoinParams as $key => $val) { |
|
111 | + foreach ($extraJoinParams as $key => $val) { |
|
112 | 112 | $this->mapParams[$key] = $val; |
113 | 113 | } |
114 | 114 | |
@@ -125,13 +125,13 @@ discard block |
||
125 | 125 | { |
126 | 126 | $db = $db ?? static::$pdo; |
127 | 127 | |
128 | - if(!$db) { |
|
128 | + if (!$db) { |
|
129 | 129 | throw new QueryRelationManagerException('no pdo connection opened'); |
130 | 130 | } |
131 | 131 | |
132 | 132 | $q = $db->prepare($this->query); |
133 | 133 | |
134 | - foreach($this->mapParams as $key => $val) { |
|
134 | + foreach ($this->mapParams as $key => $val) { |
|
135 | 135 | $q->bindValue($key, $val); |
136 | 136 | } |
137 | 137 | |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | { |
148 | 148 | $from = array_keys($this->mapParams); |
149 | 149 | $to = array_values($this->mapParams); |
150 | - foreach($to as &$param) { |
|
150 | + foreach ($to as &$param) { |
|
151 | 151 | $param = "'{$param}'"; |
152 | 152 | } |
153 | 153 | unset($param); |
@@ -92,7 +92,7 @@ |
||
92 | 92 | public function stringify(): string |
93 | 93 | { |
94 | 94 | $joins = []; |
95 | - foreach($this->joinCondition as $linkBy => $linkTo) { |
|
95 | + foreach ($this->joinCondition as $linkBy => $linkTo) { |
|
96 | 96 | $joins[] = "{$this->table->alias}.{$linkBy} = {$this->joinTo->alias}.{$linkTo}"; |
97 | 97 | } |
98 | 98 |
@@ -83,14 +83,14 @@ discard block |
||
83 | 83 | $this->containerFieldAlias = $containerFieldAlias; |
84 | 84 | |
85 | 85 | $bufMap = []; |
86 | - foreach($fields as $field) { |
|
86 | + foreach ($fields as $field) { |
|
87 | 87 | $bufMap[$field] = "{$this->alias}_{$field}"; |
88 | 88 | $this->fieldMap["{$this->alias}.{$field}"] = "{$this->alias}_{$field}"; |
89 | 89 | $this->fieldMapReverse["{$this->alias}_{$field}"] = $field; |
90 | 90 | } |
91 | 91 | |
92 | - foreach($this->primaryKey as $field) { |
|
93 | - if(!isset($bufMap[$field])) { |
|
92 | + foreach ($this->primaryKey as $field) { |
|
93 | + if (!isset($bufMap[$field])) { |
|
94 | 94 | throw new QueryRelationManagerException("pk field {$field} not found in field list"); |
95 | 95 | } |
96 | 96 | $this->pkFieldMapReverse[$bufMap[$field]] = $field; |
@@ -132,8 +132,8 @@ discard block |
||
132 | 132 | */ |
133 | 133 | public function issetDataInRow(array &$row): bool |
134 | 134 | { |
135 | - foreach($this->pkFieldMapReverse as $prefixedKey => $key) { |
|
136 | - if($row[$prefixedKey] !== null) { |
|
135 | + foreach ($this->pkFieldMapReverse as $prefixedKey => $key) { |
|
136 | + if ($row[$prefixedKey] !== null) { |
|
137 | 137 | return true; |
138 | 138 | } |
139 | 139 | } |
@@ -159,13 +159,13 @@ discard block |
||
159 | 159 | { |
160 | 160 | $item = []; |
161 | 161 | |
162 | - foreach($this->fieldMapReverse as $fieldPrefixed => $field) { |
|
162 | + foreach ($this->fieldMapReverse as $fieldPrefixed => $field) { |
|
163 | 163 | $item[$field] = $row[$fieldPrefixed]; |
164 | 164 | } |
165 | 165 | |
166 | 166 | /** @var JoinCondition $cond */ |
167 | - foreach($conditionCollection->byJoinTo($this->alias) as $cond) { |
|
168 | - switch($cond->type) { |
|
167 | + foreach ($conditionCollection->byJoinTo($this->alias) as $cond) { |
|
168 | + switch ($cond->type) { |
|
169 | 169 | case JoinCondition::TYPE_MULTIPLE: |
170 | 170 | $item[$cond->table->containerFieldAlias] = []; |
171 | 171 | break; |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | |
180 | 180 | $primaryKeyValue = $this->stringifyPrimaryKeyValue($row); |
181 | 181 | |
182 | - if($conditionCollection->issetByJoinAs($this->alias)) { |
|
182 | + if ($conditionCollection->issetByJoinAs($this->alias)) { |
|
183 | 183 | $cond = $conditionCollection->byJoinAs($this->alias); |
184 | 184 | $joinTo = $cond->joinTo; |
185 | 185 | $aliasTo = $joinTo->alias; |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | public function getPrimaryKeyForSelect(): array |
203 | 203 | { |
204 | 204 | $result = []; |
205 | - foreach($this->primaryKey as $field) { |
|
205 | + foreach ($this->primaryKey as $field) { |
|
206 | 206 | $result[] = "{$this->alias}.{$field}"; |
207 | 207 | } |
208 | 208 | |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | { |
230 | 230 | $primaryKeyValues = []; |
231 | 231 | |
232 | - foreach($this->pkFieldChain as $field) { |
|
232 | + foreach ($this->pkFieldChain as $field) { |
|
233 | 233 | $primaryKeyValues[] = $row[$field]; |
234 | 234 | } |
235 | 235 |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | */ |
33 | 33 | public function add(Table $table): self |
34 | 34 | { |
35 | - if($this->mainTable === null) { |
|
35 | + if ($this->mainTable === null) { |
|
36 | 36 | $this->mainTable = $table; |
37 | 37 | } |
38 | 38 | |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | */ |
49 | 49 | public function getMainTable(): Table |
50 | 50 | { |
51 | - if($this->mainTable === null) { |
|
51 | + if ($this->mainTable === null) { |
|
52 | 52 | throw new QueryRelationManagerException('no main table found in TableManager'); |
53 | 53 | } |
54 | 54 | |
@@ -78,10 +78,10 @@ discard block |
||
78 | 78 | $tableAliasChain = $this->getTableAliasChain($tableAlias, $joinConditions); |
79 | 79 | $result = []; |
80 | 80 | |
81 | - foreach($tableAliasChain as $alias) { |
|
81 | + foreach ($tableAliasChain as $alias) { |
|
82 | 82 | $table = $this->byAlias($alias); |
83 | 83 | |
84 | - foreach($table->primaryKey as $field) { |
|
84 | + foreach ($table->primaryKey as $field) { |
|
85 | 85 | $result[] = "{$alias}_{$field}"; |
86 | 86 | } |
87 | 87 | } |
@@ -99,10 +99,10 @@ discard block |
||
99 | 99 | { |
100 | 100 | $result = []; |
101 | 101 | |
102 | - while(true) { |
|
102 | + while (true) { |
|
103 | 103 | $result[] = $tableAlias; |
104 | 104 | |
105 | - if(!$joinConditions->issetByJoinAs($tableAlias)) { |
|
105 | + if (!$joinConditions->issetByJoinAs($tableAlias)) { |
|
106 | 106 | break; |
107 | 107 | } |
108 | 108 | |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | */ |
119 | 119 | public function getIterator(): iterable |
120 | 120 | { |
121 | - foreach($this->mapByAlias as $table) { |
|
121 | + foreach ($this->mapByAlias as $table) { |
|
122 | 122 | yield $table; |
123 | 123 | } |
124 | 124 | } |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | */ |
142 | 142 | protected function addToMap(string $mapName, string $key, Table $table): self |
143 | 143 | { |
144 | - if(isset($this->{$mapName}[$table->{$key}])) { |
|
144 | + if (isset($this->{$mapName}[$table->{$key}])) { |
|
145 | 145 | throw new QueryRelationManagerException("duplicate key '{$key}' in map '{$mapName}' of TableManager"); |
146 | 146 | } |
147 | 147 | $this->{$mapName}[$table->{$key}] = $table; |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | */ |
159 | 159 | protected function getFromMap(string $mapName, string $key): Table |
160 | 160 | { |
161 | - if(!isset($this->{$mapName}[$key])) { |
|
161 | + if (!isset($this->{$mapName}[$key])) { |
|
162 | 162 | throw new QueryRelationManagerException("key '{$key}' not found in map '{$mapName}' of TableManager"); |
163 | 163 | } |
164 | 164 |
@@ -33,15 +33,15 @@ discard block |
||
33 | 33 | */ |
34 | 34 | public function add(JoinCondition $condition): self |
35 | 35 | { |
36 | - if(isset($this->mapByJoinAs[$condition->table->alias])) { |
|
36 | + if (isset($this->mapByJoinAs[$condition->table->alias])) { |
|
37 | 37 | throw new QueryRelationManagerException("duplicate table alias '{$condition->table->alias}'"); |
38 | 38 | } |
39 | 39 | $this->mapByJoinAs[$condition->table->alias] = $condition; |
40 | 40 | |
41 | - if(!isset($this->matrixByJoinTo[$condition->joinTo->alias])) { |
|
41 | + if (!isset($this->matrixByJoinTo[$condition->joinTo->alias])) { |
|
42 | 42 | $this->matrixByJoinTo[$condition->joinTo->alias] = []; |
43 | 43 | } |
44 | - if(isset($this->matrixByJoinTo[$condition->joinTo->alias][$condition->table->alias])) { |
|
44 | + if (isset($this->matrixByJoinTo[$condition->joinTo->alias][$condition->table->alias])) { |
|
45 | 45 | throw new QueryRelationManagerException("duplicate table alias '{$condition->table->alias}'"); |
46 | 46 | } |
47 | 47 | $this->matrixByJoinTo[$condition->joinTo->alias][$condition->table->alias] = $condition; |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | */ |
57 | 57 | public function issetByJoinAs(string $joinAs): bool |
58 | 58 | { |
59 | - if(!isset($this->mapByJoinAs[$joinAs])) { |
|
59 | + if (!isset($this->mapByJoinAs[$joinAs])) { |
|
60 | 60 | return false; |
61 | 61 | } |
62 | 62 | |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | */ |
82 | 82 | public function byJoinTo(string $joinTo): array |
83 | 83 | { |
84 | - if(!isset($this->matrixByJoinTo[$joinTo])) { |
|
84 | + if (!isset($this->matrixByJoinTo[$joinTo])) { |
|
85 | 85 | return []; |
86 | 86 | } |
87 | 87 | return $this->matrixByJoinTo[$joinTo]; |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | */ |
94 | 94 | public function getIterator(): iterable |
95 | 95 | { |
96 | - foreach($this->mapByJoinAs as $condition) { |
|
96 | + foreach ($this->mapByJoinAs as $condition) { |
|
97 | 97 | yield $condition; |
98 | 98 | } |
99 | 99 | } |
@@ -184,38 +184,38 @@ discard block |
||
184 | 184 | $rows = $this->query->all($db); |
185 | 185 | |
186 | 186 | $map = []; |
187 | - foreach($this->tableCollection as $table) { |
|
187 | + foreach ($this->tableCollection as $table) { |
|
188 | 188 | $map[$table->alias] = []; |
189 | 189 | } |
190 | 190 | |
191 | 191 | $bufMap = []; |
192 | 192 | |
193 | - foreach($rows as $row) { |
|
194 | - foreach($this->tableCollection as $table) { |
|
195 | - if(!$table->issetDataInRow($row)) { |
|
193 | + foreach ($rows as $row) { |
|
194 | + foreach ($this->tableCollection as $table) { |
|
195 | + if (!$table->issetDataInRow($row)) { |
|
196 | 196 | continue; |
197 | 197 | } |
198 | 198 | |
199 | 199 | [$item, $pkValue, $alias, $aliasTo, $fkValue, $containerFieldAlias, $type] |
200 | 200 | = $table->getDataFromRow($row, $this->joinConditionCollection); |
201 | 201 | |
202 | - if(!isset($map[$alias][$pkValue])) { |
|
202 | + if (!isset($map[$alias][$pkValue])) { |
|
203 | 203 | $map[$alias][$pkValue] = &$item; |
204 | 204 | } |
205 | 205 | |
206 | - if($aliasTo !== null) { |
|
206 | + if ($aliasTo !== null) { |
|
207 | 207 | $bufMapKey = implode('-', [$aliasTo, $fkValue, $containerFieldAlias, $pkValue]); |
208 | 208 | /** @var string $type */ |
209 | - switch($type) { |
|
209 | + switch ($type) { |
|
210 | 210 | case JoinCondition::TYPE_SINGLE: |
211 | - if(!isset($bufMap[$bufMapKey])) { |
|
211 | + if (!isset($bufMap[$bufMapKey])) { |
|
212 | 212 | /** @var mixed[][][] $map */ |
213 | 213 | $map[$aliasTo][$fkValue][$containerFieldAlias] = &$item; |
214 | 214 | $bufMap[$bufMapKey] = 1; |
215 | 215 | } |
216 | 216 | break; |
217 | 217 | case JoinCondition::TYPE_MULTIPLE: |
218 | - if(!isset($bufMap[$bufMapKey])) { |
|
218 | + if (!isset($bufMap[$bufMapKey])) { |
|
219 | 219 | /** @var mixed[][][][] $map */ |
220 | 220 | $map[$aliasTo][$fkValue][$containerFieldAlias][] = &$item; |
221 | 221 | $bufMap[$bufMapKey] = 1; |
@@ -229,8 +229,8 @@ discard block |
||
229 | 229 | } |
230 | 230 | } |
231 | 231 | |
232 | - foreach($this->modifierMap as $alias => $modifier) { |
|
233 | - foreach($map[$alias] as $pk => &$item) { |
|
232 | + foreach ($this->modifierMap as $alias => $modifier) { |
|
233 | + foreach ($map[$alias] as $pk => &$item) { |
|
234 | 234 | ($modifier)($item); |
235 | 235 | } |
236 | 236 | unset($item); |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | */ |
247 | 247 | public function prepare(): QueryWrapperInterface |
248 | 248 | { |
249 | - foreach($this->tableCollection as $table) { |
|
249 | + foreach ($this->tableCollection as $table) { |
|
250 | 250 | $table->setPkFieldChain( |
251 | 251 | $this->tableCollection->getPkFieldChain($table->alias, $this->joinConditionCollection) |
252 | 252 | ); |
@@ -255,8 +255,8 @@ discard block |
||
255 | 255 | $this->query = $this->createQuery(); |
256 | 256 | |
257 | 257 | $arSelect = []; |
258 | - foreach($this->tableCollection as $table) { |
|
259 | - foreach($table->getFieldMap() as $fieldName => $fieldNamePrefixed) { |
|
258 | + foreach ($this->tableCollection as $table) { |
|
259 | + foreach ($table->getFieldMap() as $fieldName => $fieldNamePrefixed) { |
|
260 | 260 | $arSelect[$fieldNamePrefixed] = $fieldName; |
261 | 261 | } |
262 | 262 | } |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | ->select($arSelect) |
268 | 268 | ->from([$mainTable->alias => $mainTable->name]); |
269 | 269 | |
270 | - foreach($this->joinConditionCollection as $cond) { |
|
270 | + foreach ($this->joinConditionCollection as $cond) { |
|
271 | 271 | $this->query->join( |
272 | 272 | $cond->joinType, |
273 | 273 | [$cond->table->alias => $cond->table->name], |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | ); |
277 | 277 | } |
278 | 278 | |
279 | - foreach($this->filters as $modifier) { |
|
279 | + foreach ($this->filters as $modifier) { |
|
280 | 280 | $modifier($this->query->getQuery()); |
281 | 281 | } |
282 | 282 |