Skip to content

Commit 1ae6f63

Browse files
committed
MC-38348: Make SVC and Infra changes
- Fixes for Layout and DatabaseWhitelist Analyzer
1 parent 6f8ab4d commit 1ae6f63

File tree

4 files changed

+25
-37
lines changed

4 files changed

+25
-37
lines changed

src/Analyzer/DBSchema/DbSchemaWhitelistAnalyzer.php

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
* See COPYING.txt for license details.
66
*/
77

8+
declare(strict_types=1);
9+
810
namespace Magento\SemanticVersionChecker\Analyzer\DBSchema;
911

1012
use Magento\SemanticVersionChecker\Analyzer\AnalyzerInterface;
@@ -14,7 +16,8 @@
1416
use PHPSemVerChecker\Report\Report;
1517

1618
/**
17-
* Implements an analyzer for the database schema whitelist files
19+
* Implements an analyzer fdr the database schema whitelist files.
20+
* @noinspection PhpUnused
1821
*/
1922
class DbSchemaWhitelistAnalyzer implements AnalyzerInterface
2023
{
@@ -30,10 +33,11 @@ class DbSchemaWhitelistAnalyzer implements AnalyzerInterface
3033
private $report;
3134

3235
/**
33-
* DbSchemaWhitelistAnalyzer constructor.
3436
* @param Report $report
3537
*/
36-
public function __construct(Report $report) {
38+
public function __construct(
39+
Report $report
40+
) {
3741
$this->report = $report;
3842
}
3943

@@ -42,41 +46,25 @@ public function __construct(Report $report) {
4246
*
4347
* @param Registry $registryBefore
4448
* @param Registry $registryAfter
49+
*
4550
* @return Report
4651
*/
4752
public function analyze($registryBefore, $registryAfter)
4853
{
4954
$registryTablesAfter = $registryAfter->data['table'] ?? [];
50-
$registryTablesBefore = $registryBefore->data['table'] ?? [];
55+
$dbWhiteListContent = $registryAfter->data['whitelist_json'] ?? [];
5156

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();
5657
foreach ($registryTablesAfter as $moduleName => $tablesData) {
58+
$whiteListFileAfter = $registryAfter->mapping['whitelist_json'][$moduleName] ?? '';
59+
if (!file_exists($whiteListFileAfter)) {
60+
$operation = new WhiteListWasRemoved($whiteListFileAfter, $moduleName);
61+
$this->report->add('database', $operation);
62+
continue;
63+
}
5764
if (count($tablesData)) {
58-
$dbWhiteListFile =
59-
$dbWhiteListFile = preg_replace(
60-
'/(.*Magento\/)\w+(\/.*)(db_schema\.xml)/',
61-
'$1' . explode("_", $moduleName)[1] . '$2'
62-
. 'db_schema_whitelist.json',
63-
$dbFile
64-
);
65-
if (!file_exists($dbWhiteListFile)) {
66-
$operation = new WhiteListWasRemoved($dbWhiteListFile, $moduleName);
67-
$this->report->add('database', $operation);
68-
continue;
69-
} else {
70-
$dbWhiteListContent = json_decode(
71-
file_get_contents($dbWhiteListFile),
72-
true
73-
);
74-
}
75-
76-
$tables = array_replace($tablesData, $registryTablesBefore[$moduleName] ?? []);
77-
foreach (array_keys($tables) as $table) {
78-
if (!isset($dbWhiteListContent[$table])) {
79-
$operation = new InvalidWhitelist($dbWhiteListFile, $table);
65+
foreach (array_keys($tablesData) as $table) {
66+
if (!isset($dbWhiteListContent[$moduleName][$table])) {
67+
$operation = new InvalidWhitelist($whiteListFileAfter, $table);
8068
$this->report->add('database', $operation);
8169
}
8270
}

src/Analyzer/Layout/Analyzer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,15 @@ public function analyze($registryBefore, $registryAfter)
6060

6161
foreach (array_keys($nodesBefore) as $moduleName) {
6262
$moduleNodesBefore = $nodesBefore[$moduleName] ?? [];
63-
$moduleNodesAfter = [];
63+
$moduleNodesAfter = $nodesAfter[$moduleName] ?? [];
6464

6565
/**
6666
* @var string $nodeName
6767
* @var LayoutNodeInterface $node
6868
*/
6969
foreach ($moduleNodesBefore as $nodeName => $node) {
7070
$uniqueKey = $node->getUniqueKey();
71-
$nodeAfter = $moduleNodesAfter[$moduleName][$uniqueKey] ?? false;
71+
$nodeAfter = $moduleNodesAfter[$uniqueKey] ?? false;
7272
if ($nodeAfter === false) {
7373
$beforeFilePath = $registryBefore->getLayoutFile($moduleName, $uniqueKey);
7474
$this->triggerNodeRemoved($moduleName, $node, $beforeFilePath);

src/Operation/WhiteListWasRemoved.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ class WhiteListWasRemoved extends Operation
4848
private $location;
4949

5050
/**
51+
* @param string $location
5152
* @param string $target
52-
* @param string $module
5353
*/
54-
public function __construct($target, $module)
54+
public function __construct($location, $target)
5555
{
56-
$this->location = $target;
57-
$this->target = $module;
56+
$this->location = $location;
57+
$this->target = $target;
5858
}
5959

6060
/**

src/Reporter/HtmlPackageLevelChangesRenderer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function outputPackageChanges()
8383
$this->output->writeln('<tr class="text"><td class="test-name">Package Level Changes</td>');
8484
//Skip writing table if no severe changes are detected
8585
if (!$pkgChangesJson) {
86-
$this->output->writeln('<td>No severe changes found to packages.</td></tr>');
86+
$this->output->writeln('<td>No BIC changes found to packages</td></tr>');
8787
return;
8888
}
8989
$this->output->writeln('<td><button class="btn-danger collapsible">Details</button><div class="content">');

0 commit comments

Comments
 (0)