@@ -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); |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | */ |
30 | 30 | public function add(Table $table): self |
31 | 31 | { |
32 | - if($this->mainTable === null) { |
|
32 | + if ($this->mainTable === null) { |
|
33 | 33 | $this->mainTable = $table; |
34 | 34 | } |
35 | 35 | |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | */ |
46 | 46 | public function getMainTable(): Table |
47 | 47 | { |
48 | - if($this->mainTable === null) { |
|
48 | + if ($this->mainTable === null) { |
|
49 | 49 | throw new QueryRelationManagerException('no main table found in TableManager'); |
50 | 50 | } |
51 | 51 | |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | */ |
72 | 72 | public function each(callable $callback): self |
73 | 73 | { |
74 | - foreach($this->mapByAlias as $table) { |
|
74 | + foreach ($this->mapByAlias as $table) { |
|
75 | 75 | $callback($table); |
76 | 76 | } |
77 | 77 | return $this; |
@@ -89,10 +89,10 @@ discard block |
||
89 | 89 | $tableAliasChain = $this->getTableAliasChain($tableAlias, $joinConditions); |
90 | 90 | $result = []; |
91 | 91 | |
92 | - foreach($tableAliasChain as $alias) { |
|
92 | + foreach ($tableAliasChain as $alias) { |
|
93 | 93 | $table = $this->byAlias($alias); |
94 | 94 | |
95 | - foreach($table->primaryKey as $field) { |
|
95 | + foreach ($table->primaryKey as $field) { |
|
96 | 96 | $result[] = "{$alias}_{$field}"; |
97 | 97 | } |
98 | 98 | } |
@@ -110,10 +110,10 @@ discard block |
||
110 | 110 | { |
111 | 111 | $result = []; |
112 | 112 | |
113 | - while(true) { |
|
113 | + while (true) { |
|
114 | 114 | $result[] = $tableAlias; |
115 | 115 | |
116 | - if(!$joinConditions->issetByJoinAs($tableAlias)) { |
|
116 | + if (!$joinConditions->issetByJoinAs($tableAlias)) { |
|
117 | 117 | break; |
118 | 118 | } |
119 | 119 | |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | */ |
134 | 134 | protected function addToMap(string $mapName, string $key, Table $table): self |
135 | 135 | { |
136 | - if(isset($this->{$mapName}[$table->{$key}])) { |
|
136 | + if (isset($this->{$mapName}[$table->{$key}])) { |
|
137 | 137 | throw new QueryRelationManagerException("duplicate key '{$key}' in map '{$mapName}' of TableManager"); |
138 | 138 | } |
139 | 139 | $this->{$mapName}[$table->{$key}] = $table; |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | */ |
151 | 151 | protected function getFromMap(string $mapName, string $key): Table |
152 | 152 | { |
153 | - if(!isset($this->{$mapName}[$key])) { |
|
153 | + if (!isset($this->{$mapName}[$key])) { |
|
154 | 154 | throw new QueryRelationManagerException("key '{$key}' not found in map '{$mapName}' of TableManager"); |
155 | 155 | } |
156 | 156 |
@@ -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 |
@@ -30,15 +30,15 @@ discard block |
||
30 | 30 | */ |
31 | 31 | public function add(JoinCondition $condition): self |
32 | 32 | { |
33 | - if(isset($this->mapByJoinAs[$condition->table->alias])) { |
|
33 | + if (isset($this->mapByJoinAs[$condition->table->alias])) { |
|
34 | 34 | throw new QueryRelationManagerException("duplicate table alias '{$condition->table->alias}'"); |
35 | 35 | } |
36 | 36 | $this->mapByJoinAs[$condition->table->alias] = $condition; |
37 | 37 | |
38 | - if(!isset($this->matrixByJoinTo[$condition->joinTo->alias])) { |
|
38 | + if (!isset($this->matrixByJoinTo[$condition->joinTo->alias])) { |
|
39 | 39 | $this->matrixByJoinTo[$condition->joinTo->alias] = []; |
40 | 40 | } |
41 | - if(isset($this->matrixByJoinTo[$condition->joinTo->alias][$condition->table->alias])) { |
|
41 | + if (isset($this->matrixByJoinTo[$condition->joinTo->alias][$condition->table->alias])) { |
|
42 | 42 | throw new QueryRelationManagerException("duplicate table alias '{$condition->table->alias}'"); |
43 | 43 | } |
44 | 44 | $this->matrixByJoinTo[$condition->joinTo->alias][$condition->table->alias] = $condition; |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | */ |
54 | 54 | public function issetByJoinAs(string $joinAs): bool |
55 | 55 | { |
56 | - if(!isset($this->mapByJoinAs[$joinAs])) { |
|
56 | + if (!isset($this->mapByJoinAs[$joinAs])) { |
|
57 | 57 | return false; |
58 | 58 | } |
59 | 59 | |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | */ |
79 | 79 | public function byJoinTo(string $joinTo): array |
80 | 80 | { |
81 | - if(!isset($this->matrixByJoinTo[$joinTo])) { |
|
81 | + if (!isset($this->matrixByJoinTo[$joinTo])) { |
|
82 | 82 | return []; |
83 | 83 | } |
84 | 84 | return $this->matrixByJoinTo[$joinTo]; |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | */ |
93 | 93 | public function each(callable $callback): self |
94 | 94 | { |
95 | - foreach($this->mapByJoinAs as $condition) { |
|
95 | + foreach ($this->mapByJoinAs as $condition) { |
|
96 | 96 | $callback($condition); |
97 | 97 | } |
98 | 98 | return $this; |
@@ -190,32 +190,32 @@ discard block |
||
190 | 190 | |
191 | 191 | $bufMap = []; |
192 | 192 | |
193 | - foreach($rows as $row) { |
|
193 | + foreach ($rows as $row) { |
|
194 | 194 | $this->tableCollection->each(function(Table $table) use (&$map, &$row, &$bufMap) { |
195 | - if(!$table->issetDataInRow($row)) { |
|
195 | + if (!$table->issetDataInRow($row)) { |
|
196 | 196 | return; |
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; |
@@ -228,8 +228,8 @@ discard block |
||
228 | 228 | }); |
229 | 229 | } |
230 | 230 | |
231 | - foreach($this->modifierMap as $alias => $modifier) { |
|
232 | - foreach($map[$alias] as $pk => &$item) { |
|
231 | + foreach ($this->modifierMap as $alias => $modifier) { |
|
232 | + foreach ($map[$alias] as $pk => &$item) { |
|
233 | 233 | ($modifier)($item); |
234 | 234 | } |
235 | 235 | unset($item); |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | |
256 | 256 | $arSelect = []; |
257 | 257 | $this->tableCollection->each(function(Table $table) use (&$arSelect) { |
258 | - foreach($table->getFieldMap() as $fieldName => $fieldNamePrefixed) { |
|
258 | + foreach ($table->getFieldMap() as $fieldName => $fieldNamePrefixed) { |
|
259 | 259 | $arSelect[$fieldNamePrefixed] = $fieldName; |
260 | 260 | } |
261 | 261 | }); |
@@ -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 |