Skip to content

Commit e17c5f1

Browse files
committed
MC-38348: Make SVC and Infra changes
- Codefixes for DbSchemaWhitelistAnalyzer
1 parent 7693e6f commit e17c5f1

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

src/Analyzer/DBSchema/DbSchemaWhitelistAnalyzer.php

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
use PHPSemVerChecker\Report\Report;
1515

1616
/**
17-
* Class DbSchemaAnalyzer
18-
* @package Magento\SemanticVersionChecker\Analyzer
17+
* Implements an analyzer for the database schema whitelist files
1918
*/
2019
class DbSchemaWhitelistAnalyzer implements AnalyzerInterface
2120
{
@@ -25,6 +24,18 @@ class DbSchemaWhitelistAnalyzer implements AnalyzerInterface
2524
* @var string
2625
*/
2726
protected $context = 'db_schema';
27+
/**
28+
* @var Report
29+
*/
30+
private $report;
31+
32+
/**
33+
* DbSchemaWhitelistAnalyzer constructor.
34+
* @param Report $report
35+
*/
36+
public function __construct(Report $report) {
37+
$this->report = $report;
38+
}
2839

2940
/**
3041
* Class analyzer.
@@ -35,29 +46,25 @@ class DbSchemaWhitelistAnalyzer implements AnalyzerInterface
3546
*/
3647
public function analyze($registryBefore, $registryAfter)
3748
{
38-
$report = new Report();
3949
$registryTablesAfter = $registryAfter->data['table'] ?? [];
4050
$registryTablesBefore = $registryBefore->data['table'] ?? [];
4151

52+
//Take file like an example
53+
//We will replace module_name in file_path in order to get
54+
//correct module
55+
$dbFile = $registryAfter->getCurrentFile();
4256
foreach ($registryTablesAfter as $moduleName => $tablesData) {
4357
if (count($tablesData)) {
44-
//Take file like an example
45-
//We will replace module_name in file_path in order to get
46-
//correct module
47-
$dbFile = $registryAfter->getCurrentFile();
58+
$dbWhiteListFile =
4859
$dbWhiteListFile = preg_replace(
49-
'/(.*Magento\/)\w+(\/.*)/',
50-
'$1' . explode("_", $moduleName)[1] . '$2',
60+
'/(.*Magento\/)\w+(\/.*)(db_schema\.xml)/',
61+
'$1' . explode("_", $moduleName)[1] . '$2'
62+
. 'db_schema_whitelist.json',
5163
$dbFile
5264
);
53-
$dbWhiteListFile = str_replace(
54-
'db_schema.xml',
55-
'db_schema_whitelist.json',
56-
$dbWhiteListFile
57-
);
5865
if (!file_exists($dbWhiteListFile)) {
5966
$operation = new WhiteListWasRemoved($dbWhiteListFile, $moduleName);
60-
$report->add('database', $operation);
67+
$this->report->add('database', $operation);
6168
continue;
6269
} else {
6370
$dbWhiteListContent = json_decode(
@@ -70,13 +77,11 @@ public function analyze($registryBefore, $registryAfter)
7077
foreach (array_keys($tables) as $table) {
7178
if (!isset($dbWhiteListContent[$table])) {
7279
$operation = new InvalidWhitelist($dbWhiteListFile, $table);
73-
$report->add('database', $operation);
80+
$this->report->add('database', $operation);
7481
}
7582
}
7683
}
7784
}
78-
79-
80-
return $report;
85+
return $this->report;
8186
}
8287
}

0 commit comments

Comments
 (0)