Skip to content

Commit 7d7a760

Browse files
committed
fixed report merging
1 parent e3ae55e commit 7d7a760

File tree

1 file changed

+80
-12
lines changed

1 file changed

+80
-12
lines changed

src/Analyzer/EtSchemaAnalyzer.php

Lines changed: 80 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,38 @@ public function __construct(Report $report)
6666
$this->report = $report;
6767
}
6868

69-
private function reportAddedModuleConfig(array $moduleConfig): array
69+
/**
70+
* Process a new configuration file
71+
*
72+
* @param array $moduleConfig
73+
* @return array
74+
*/
75+
private function addedModuleConfig(array $moduleConfig): array
7076
{
71-
return [];
77+
$changes = [];
78+
foreach ($moduleConfig as $moduleName => $records) {
79+
foreach ($records as $record) {
80+
$changes[] = $this->addedRecord($moduleName, $record['name']);
81+
}
82+
}
83+
return $changes;
7284
}
7385

86+
/**
87+
* Process removed configuration file
88+
*
89+
* @param array $moduleConfig
90+
* @return array
91+
*/
7492
private function removedModuleConfig(array $moduleConfig): array
7593
{
76-
return [];
94+
$changes = [];
95+
foreach ($moduleConfig as $moduleName => $records) {
96+
foreach ($records as $record) {
97+
$changes[] = $this->removedRecord($moduleName, $record['name']);
98+
}
99+
}
100+
return $changes;
77101
}
78102

79103
/**
@@ -113,6 +137,8 @@ private function removedRecord(string $moduleName, string $recordName): array
113137
}
114138

115139
/**
140+
* Register removed field
141+
*
116142
* @param string $moduleName
117143
* @param string $recordName
118144
* @param string $fieldName
@@ -135,6 +161,8 @@ private function removedField(string $moduleName, string $recordName, string $fi
135161
}
136162

137163
/**
164+
* Register a new field
165+
*
138166
* @param string $moduleName
139167
* @param string $recordName
140168
* @param string $fieldName
@@ -157,6 +185,8 @@ private function addedField(string $moduleName, string $recordName, string $fiel
157185
}
158186

159187
/**
188+
* Register field change
189+
*
160190
* @param string $moduleName
161191
* @param string $recordName
162192
* @param string $fieldName
@@ -197,7 +227,7 @@ private function analyzeRecord(string $moduleName, $beforeRecord, $afterRecord):
197227
if ($beforeRecord['field'][$fieldName]['type'] != $afterRecord['field'][$fieldName]['type']
198228
|| $beforeRecord['field'][$fieldName]['repeated'] != $afterRecord['field'][$fieldName]['repeated']
199229
) {
200-
$this->changedField($moduleName, $beforeRecord['name'], $fieldName);
230+
$changes[] = $this->changedField($moduleName, $beforeRecord['name'], $fieldName);
201231
}
202232
}
203233
$diff = array_merge(
@@ -236,10 +266,13 @@ private function analyzeModuleConfig(string $moduleName, array $beforeModuleConf
236266
array_keys($afterModuleConfig)
237267
);
238268
foreach ($commonRecords as $recordName) {
239-
$changes += $this->analyzeRecord(
240-
$moduleName,
241-
$beforeModuleConfig[$recordName],
242-
$afterModuleConfig[$recordName]
269+
$changes = array_merge(
270+
$changes,
271+
$this->analyzeRecord(
272+
$moduleName,
273+
$beforeModuleConfig[$recordName],
274+
$afterModuleConfig[$recordName]
275+
)
243276
);
244277
}
245278
$diff = array_merge(
@@ -298,12 +331,47 @@ public function analyze($registryBefore, $registryAfter)
298331
array_keys($registryAfter->data['etSchema'])
299332
);
300333
foreach ($commonModules as $moduleName) {
301-
$changes += $this->analyzeModuleConfig(
302-
$moduleName,
303-
$registryBefore->data['etSchema'][$moduleName],
304-
$registryAfter->data['etSchema'][$moduleName]
334+
$changes = array_merge(
335+
$changes,
336+
$this->analyzeModuleConfig(
337+
$moduleName,
338+
$registryBefore->data['etSchema'][$moduleName],
339+
$registryAfter->data['etSchema'][$moduleName]
340+
)
305341
);
306342
}
343+
344+
$changes = array_merge(
345+
$changes,
346+
$this->removedModuleConfig(
347+
array_intersect_key(
348+
$registryBefore->data['etSchema'],
349+
array_flip(
350+
array_diff(
351+
array_keys($registryBefore->data['etSchema']),
352+
array_keys($registryAfter->data['etSchema'])
353+
)
354+
)
355+
)
356+
)
357+
);
358+
359+
$changes = array_merge(
360+
$changes,
361+
$this->addedModuleConfig(
362+
array_intersect_key(
363+
$registryAfter->data['etSchema'],
364+
array_flip(
365+
array_diff(
366+
array_keys($registryAfter->data['etSchema']),
367+
array_keys($registryBefore->data['etSchema'])
368+
)
369+
)
370+
)
371+
)
372+
);
373+
374+
307375
$this->reportChanges($changes);
308376
return $this->report;
309377
}

0 commit comments

Comments
 (0)