Skip to content

Commit 9ef11a4

Browse files
authored
Merge pull request #21 from magento-trigger/MC-38148-develop
Add a new section to HTML SVC report
2 parents 6b1f28f + 50a807f commit 9ef11a4

File tree

89 files changed

+1589
-240
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+1589
-240
lines changed

.github/workflows/php.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name: CI
22

33
on:
44
push:
5-
branches: [ master ]
5+
branches: [ master, develop ]
66
pull_request:
7-
branches: [ master ]
7+
branches: [ master, develop ]
88

99
jobs:
1010
build:

composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "magento/magento-semver",
33
"description": "Magento Semantic Version Checker",
4-
"version": "9.0.0",
4+
"version": "10.0.0",
55
"license": [
66
"OSL-3.0",
77
"AFL-3.0"
@@ -20,6 +20,7 @@
2020
},
2121
"require-dev": {
2222
"phpunit/phpunit": "^6.5.0",
23+
"ext-dom": "*",
2324
"squizlabs/php_codesniffer": "^3.5"
2425
},
2526
"autoload": {

composer.lock

+4-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Analyzer/DBSchema/DbSchemaColumnAnalyzer.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -58,27 +58,29 @@ public function analyze($registryBefore, $registryAfter)
5858

5959
foreach ($registryTablesBefore as $moduleName => $moduleTables) {
6060
foreach ($moduleTables as $tableName => $tableData) {
61+
$fileBefore = $registryBefore->mapping['table'][$moduleName];
6162
$columns = $tableData['column'] ?? [];
6263
foreach ($columns as $column) {
6364
if (
6465
isset($registryTablesAfter[$moduleName][$tableName])
6566
&& !isset($registryTablesAfter[$moduleName][$tableName]['column'][$column])
6667
) {
67-
$operation = new ColumnRemove($moduleName, $tableName . '/' . $column);
68+
$operation = new ColumnRemove($fileBefore, $tableName . '/' . $column);
6869
$this->getReport()->add($this->context, $operation);
6970
}
7071
}
7172
}
7273
}
7374
foreach ($registryTablesAfter as $moduleName => $moduleTables) {
75+
$fileAfter = $registryAfter->mapping['table'][$moduleName];
7476
foreach ($moduleTables as $tableName => $tableData) {
7577
$columns = $tableData['column'] ?? [];
7678
foreach ($columns as $column) {
7779
if (
7880
isset($registryTablesBefore[$moduleName][$tableName])
7981
&& !isset($registryTablesBefore[$moduleName][$tableName]['column'][$column])
8082
) {
81-
$operation = new ColumnAdd($moduleName, $tableName . '/' . $column);
83+
$operation = new ColumnAdd($fileAfter, $tableName . '/' . $column);
8284
$this->getReport()->add($this->context, $operation);
8385
}
8486
}

src/Analyzer/DBSchema/DbSchemaForeignKeyAnalyzer.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,21 @@ public function analyze($registryBefore, $registryAfter)
5656
$registryTablesAfter = $registryAfter->data['table'] ?? [];
5757

5858
foreach ($registryTablesBefore as $moduleName => $moduleTables) {
59+
$fileBefore = $registryBefore->mapping['table'][$moduleName];
5960
foreach ($moduleTables as $tableName => $tableData) {
6061
$keys = $tableData['foreign'] ?? [];
6162
foreach ($keys as $name => $key) {
6263
if (!isset($registryTablesAfter[$moduleName][$tableName])) {
6364
continue;
6465
}
6566
if ($key !== null && !isset($registryTablesAfter[$moduleName][$tableName]['foreign'][$name])) {
66-
$operation = new ForeignKeyDrop($moduleName, $tableName . '/' . $name);
67+
$operation = new ForeignKeyDrop($fileBefore, $tableName . '/' . $name);
6768
$this->getReport()->add($this->context, $operation);
6869
continue;
6970
}
7071
foreach ($key as $item => $value) {
7172
if ($value !== $registryTablesAfter[$moduleName][$tableName]['foreign'][$name][$item]) {
72-
$operation = new ForeignKeyChange($moduleName, $tableName . '/' . $name . '/' . $item);
73+
$operation = new ForeignKeyChange($fileBefore, $tableName . '/' . $name . '/' . $item);
7374
$this->getReport()->add($this->context, $operation);
7475
}
7576
}
@@ -78,14 +79,15 @@ public function analyze($registryBefore, $registryAfter)
7879
}
7980

8081
foreach ($registryTablesAfter as $moduleName => $moduleTables) {
82+
$fileAfter = $registryAfter->mapping['table'][$moduleName];
8183
foreach ($moduleTables as $tableName => $tableData) {
8284
$keys = $tableData['foreign'] ?? [];
8385
foreach ($keys as $name => $key) {
8486
if (!isset($registryTablesBefore[$moduleName][$tableName])) {
8587
continue;
8688
}
8789
if ($key !== null && !isset($registryTablesBefore[$moduleName][$tableName]['foreign'][$name])) {
88-
$operation = new ForeignKeyAdd($moduleName, $tableName . '/' . $name);
90+
$operation = new ForeignKeyAdd($fileAfter, $tableName . '/' . $name);
8991
$this->getReport()->add($this->context, $operation);
9092
}
9193
}

src/Analyzer/DBSchema/DbSchemaPrimaryKeyAnalyzer.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,15 @@ public function analyze($registryBefore, $registryAfter)
5555
$registryTablesAfter = $registryAfter->data['table'] ?? [];
5656

5757
foreach ($registryTablesBefore as $moduleName => $moduleTables) {
58+
$fileBefore = $registryBefore->mapping['table'][$moduleName];
5859
foreach ($moduleTables as $tableName => $tableData) {
5960
$keys = $tableData['primary'] ?? [];
6061
foreach ($keys as $name => $key) {
6162
if (!isset($registryTablesAfter[$moduleName][$tableName])) {
6263
continue;
6364
}
6465
if ($key !== null && !isset($registryTablesAfter[$moduleName][$tableName]['primary'][$name])) {
65-
$operation = new PrimaryKeyDrop($moduleName, $tableName . '/' . $name);
66+
$operation = new PrimaryKeyDrop($fileBefore, $tableName . '/' . $name);
6667
$this->getReport()->add($this->context, $operation);
6768
continue;
6869
}
@@ -76,7 +77,7 @@ public function analyze($registryBefore, $registryAfter)
7677
}
7778
}
7879
if (!$matchedColumnFlag) {
79-
$operation = new PrimaryKeyChange($moduleName, $tableName . '/' . $name);
80+
$operation = new PrimaryKeyChange($fileBefore, $tableName . '/' . $name);
8081
$this->getReport()->add($this->context, $operation);
8182
break;
8283
}
@@ -86,14 +87,15 @@ public function analyze($registryBefore, $registryAfter)
8687
}
8788

8889
foreach ($registryTablesAfter as $moduleName => $moduleTables) {
90+
$fileAfter = $registryAfter->mapping['table'][$moduleName];
8991
foreach ($moduleTables as $tableName => $tableData) {
9092
$keys = $tableData['primary'] ?? [];
9193
foreach ($keys as $name => $key) {
9294
if (!isset($registryTablesBefore[$moduleName][$tableName])) {
9395
continue;
9496
}
9597
if ($key !== null && !isset($registryTablesBefore[$moduleName][$tableName]['primary'][$name])) {
96-
$operation = new PrimaryKeyAdd($moduleName, $tableName . '/' . $name);
98+
$operation = new PrimaryKeyAdd($fileAfter, $tableName . '/' . $name);
9799
$this->getReport()->add($this->context, $operation);
98100
continue;
99101
}
@@ -108,7 +110,7 @@ public function analyze($registryBefore, $registryAfter)
108110
}
109111
}
110112
if (!$matchedColumnFlag) {
111-
$operation = new PrimaryKeyChange($moduleName, $tableName . '/' . $name);
113+
$operation = new PrimaryKeyChange($fileAfter, $tableName . '/' . $name);
112114
$this->getReport()->add($this->context, $operation);
113115
break;
114116
}

src/Analyzer/DBSchema/DbSchemaTableAnalyzer.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,16 @@ public function analyze($registryBefore, $registryAfter)
5555
$registryTablesAfter = $registryAfter->data['table'] ?? [];
5656

5757
foreach ($registryTablesBefore as $moduleName => $moduleTables) {
58+
$fileBefore = $registryBefore->mapping['table'][$moduleName];
5859
foreach ($moduleTables as $tableName => $tableData) {
5960
if (!isset($registryTablesAfter[$moduleName][$tableName])) {
60-
$operation = new TableDropped($moduleName, $tableName);
61+
$operation = new TableDropped($fileBefore, $tableName);
6162
$this->getReport()->add($this->context, $operation);
6263
continue;
6364
}
6465
if ($tableData['resource'] !== $registryTablesAfter[$moduleName][$tableName]['resource']) {
6566
$operation = new TableChangeResource(
66-
$moduleName,
67+
$fileBefore,
6768
$tableName,
6869
$tableData['resource'],
6970
$registryTablesAfter[$moduleName][$tableName]['resource']
@@ -73,12 +74,13 @@ public function analyze($registryBefore, $registryAfter)
7374
}
7475
}
7576
foreach ($registryTablesAfter as $moduleName => $moduleTables) {
77+
$fileAfter = $registryAfter->mapping['table'][$moduleName];
7678
foreach ($moduleTables as $tableName => $tableData) {
7779
if (
7880
!isset($registryTablesBefore[$moduleName][$tableName])
7981
&& !$this->isModificationTableDeclaration($registryTablesAfter, $moduleName, $tableName)
8082
) {
81-
$operation = new TableAdded($moduleName, $tableName);
83+
$operation = new TableAdded($fileAfter, $tableName);
8284
$this->getReport()->add($this->context, $operation);
8385
}
8486
}

src/Analyzer/DBSchema/DbSchemaUniqueKeyAnalyzer.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,15 @@ public function analyze($registryBefore, $registryAfter)
5656
$registryTablesAfter = $registryAfter->data['table'] ?? [];
5757

5858
foreach ($registryTablesBefore as $moduleName => $moduleTables) {
59+
$fileBefore = $registryBefore->mapping['table'][$moduleName];
5960
foreach ($moduleTables as $tableName => $tableData) {
6061
$keys = $tableData['unique'] ?? [];
6162
foreach ($keys as $name => $key) {
6263
if (!isset($registryTablesAfter[$moduleName][$tableName])) {
6364
continue;
6465
}
6566
if ($key !== null && !isset($registryTablesAfter[$moduleName][$tableName]['unique'][$name])) {
66-
$operation = new UniqueKeyDrop($moduleName, $tableName . '/' . $name);
67+
$operation = new UniqueKeyDrop($fileBefore, $tableName . '/' . $name);
6768
$this->getReport()->add($this->context, $operation);
6869
continue;
6970
}
@@ -77,7 +78,7 @@ public function analyze($registryBefore, $registryAfter)
7778
}
7879
}
7980
if (!$matchedColumnFlag) {
80-
$operation = new UniqueKeyChange($moduleName, $tableName . '/' . $name);
81+
$operation = new UniqueKeyChange($fileBefore, $tableName . '/' . $name);
8182
$this->getReport()->add($this->context, $operation);
8283
break;
8384
}
@@ -87,14 +88,15 @@ public function analyze($registryBefore, $registryAfter)
8788
}
8889

8990
foreach ($registryTablesAfter as $moduleName => $moduleTables) {
91+
$fileAfter = $registryAfter->mapping['table'][$moduleName];
9092
foreach ($moduleTables as $tableName => $tableData) {
9193
$keys = $tableData['unique'] ?? [];
9294
foreach ($keys as $name => $key) {
9395
if (!isset($registryTablesBefore[$moduleName][$tableName])) {
9496
continue;
9597
}
9698
if ($key !== null && !isset($registryTablesBefore[$moduleName][$tableName]['unique'][$name])) {
97-
$operation = new UniqueKeyAdd($moduleName, $tableName . '/' . $name);
99+
$operation = new UniqueKeyAdd($fileAfter, $tableName . '/' . $name);
98100
$this->getReport()->add($this->context, $operation);
99101
continue;
100102
}
@@ -109,7 +111,7 @@ public function analyze($registryBefore, $registryAfter)
109111
}
110112
}
111113
if (!$matchedColumnFlag) {
112-
$operation = new UniqueKeyChange($moduleName, $tableName . '/' . $name);
114+
$operation = new UniqueKeyChange($fileAfter, $tableName . '/' . $name);
113115
$this->getReport()->add($this->context, $operation);
114116
break;
115117
}

src/Analyzer/DBSchema/DbSchemaWhitelistAnalyzer.php

+11-4
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@
1111

1212
use Magento\SemanticVersionChecker\Analyzer\AnalyzerInterface;
1313
use Magento\SemanticVersionChecker\Operation\InvalidWhitelist;
14+
use Magento\SemanticVersionChecker\Operation\WhiteListWasRemoved;
1415
use PHPSemVerChecker\Registry\Registry;
1516
use PHPSemVerChecker\Report\Report;
1617

1718
/**
18-
* Implements an analyzer fdr the database schema whitelist files.
19+
* Implements an analyzer for the database schema whitelist files.
1920
* @noinspection PhpUnused
2021
*/
2122
class DbSchemaWhitelistAnalyzer implements AnalyzerInterface
@@ -54,17 +55,23 @@ public function analyze($registryBefore, $registryAfter)
5455
$dbWhiteListContent = $registryAfter->data['whitelist_json'] ?? [];
5556

5657
foreach ($registryTablesAfter as $moduleName => $tablesData) {
58+
$whiteListFileAfter = $registryAfter->mapping['whitelist_json'][$moduleName] ?? '';
59+
if (!file_exists($whiteListFileAfter)) {
60+
$tableFileAfter = $registryAfter->mapping['table'][$moduleName];
61+
$whiteListFileAfter = dirname($tableFileAfter) . '/db_schema_whitelist.json';
62+
$operation = new WhiteListWasRemoved($whiteListFileAfter, $moduleName);
63+
$this->report->add('database', $operation);
64+
continue;
65+
}
5766
if (count($tablesData)) {
5867
foreach (array_keys($tablesData) as $table) {
5968
if (!isset($dbWhiteListContent[$moduleName][$table])) {
60-
$operation = new InvalidWhitelist($moduleName, $table);
69+
$operation = new InvalidWhitelist($whiteListFileAfter, $table);
6170
$this->report->add('database', $operation);
6271
}
6372
}
6473
}
6574
}
66-
67-
6875
return $this->report;
6976
}
7077
}

src/Analyzer/DBSchema/DbSchemaWhitelistReductionOrRemovalAnalyzer.php

+8-7
Original file line numberDiff line numberDiff line change
@@ -49,31 +49,32 @@ public function analyze($registryBefore, $registryAfter)
4949

5050
/** @var array $tablesData */
5151
foreach ($whiteListBefore as $moduleName => $beforeModuleTablesData) {
52+
$fileBefore = $registryBefore->mapping['whitelist_json'][$moduleName];
5253
if (!isset($whiteListAfter[$moduleName])) {
53-
$operation = new WhiteListWasRemoved($moduleName);
54+
$operation = new WhiteListWasRemoved($fileBefore, $moduleName);
5455
$this->report->add('database', $operation);
5556
continue;
5657
}
5758
$afterModuleTablesData = $whiteListAfter[$moduleName];
5859
/** @var array $beforeTableData */
5960
foreach ($beforeModuleTablesData as $tableName => $beforeTableData) {
6061
if (!$this->isArrayExistsAndHasSameSize($afterModuleTablesData, $beforeTableData, $tableName)) {
61-
$this->addReport($moduleName, $tableName);
62+
$this->addReport($fileBefore, $tableName);
6263
continue;
6364
}
6465
$afterTableData = $afterModuleTablesData[$tableName];
6566
/** @var array $beforeTablePartData */
6667
foreach ($beforeTableData as $tablePartName => $beforeTablePartData) {
6768
if (!$this->isArrayExistsAndHasSameSize($afterTableData, $beforeTablePartData, $tablePartName)) {
68-
$this->addReport($moduleName, $tableName . '/' . $tablePartName);
69+
$this->addReport($fileBefore, $tableName . '/' . $tablePartName);
6970
continue;
7071
}
7172
$afterTablePartData = $afterTableData[$tablePartName];
7273
/** @var bool $beforeStatus */
7374
foreach ($beforeTablePartData as $name => $beforeStatus) {
7475
//checks if array exists in new whitelist.json and if it has different amount of items inside
7576
if (!isset($afterTablePartData[$name])) {
76-
$this->addReport($moduleName, $tableName . '/' . $tablePartName . '/' . $name);
77+
$this->addReport($fileBefore, $tableName . '/' . $tablePartName . '/' . $name);
7778
}
7879
}
7980
}
@@ -102,14 +103,14 @@ public function isArrayExistsAndHasSameSize(array $after, array $beforeArray, st
102103
}
103104

104105
/**
105-
* @param string $moduleName
106+
* @param string $location
106107
* @param string $target
107108
*
108109
* @return void
109110
*/
110-
public function addReport(string $moduleName, string $target): void
111+
public function addReport(string $location, string $target): void
111112
{
112-
$operation = new WhiteListReduced($moduleName, $target);
113+
$operation = new WhiteListReduced($location, $target);
113114
$this->report->add('database', $operation);
114115
}
115116
}

0 commit comments

Comments
 (0)