Skip to content

Commit

Permalink
Merge pull request #21 from magento-trigger/MC-38148-develop
Browse files Browse the repository at this point in the history
Add a new section to HTML SVC report
  • Loading branch information
fascinosum committed Feb 1, 2021
2 parents 6b1f28f + 50a807f commit 9ef11a4
Show file tree
Hide file tree
Showing 89 changed files with 1,589 additions and 240 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: CI

on:
push:
branches: [ master ]
branches: [ master, develop ]
pull_request:
branches: [ master ]
branches: [ master, develop ]

jobs:
build:
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "magento/magento-semver",
"description": "Magento Semantic Version Checker",
"version": "9.0.0",
"version": "10.0.0",
"license": [
"OSL-3.0",
"AFL-3.0"
Expand All @@ -20,6 +20,7 @@
},
"require-dev": {
"phpunit/phpunit": "^6.5.0",
"ext-dom": "*",
"squizlabs/php_codesniffer": "^3.5"
},
"autoload": {
Expand Down
6 changes: 4 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions src/Analyzer/DBSchema/DbSchemaColumnAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,27 +58,29 @@ public function analyze($registryBefore, $registryAfter)

foreach ($registryTablesBefore as $moduleName => $moduleTables) {
foreach ($moduleTables as $tableName => $tableData) {
$fileBefore = $registryBefore->mapping['table'][$moduleName];
$columns = $tableData['column'] ?? [];
foreach ($columns as $column) {
if (
isset($registryTablesAfter[$moduleName][$tableName])
&& !isset($registryTablesAfter[$moduleName][$tableName]['column'][$column])
) {
$operation = new ColumnRemove($moduleName, $tableName . '/' . $column);
$operation = new ColumnRemove($fileBefore, $tableName . '/' . $column);
$this->getReport()->add($this->context, $operation);
}
}
}
}
foreach ($registryTablesAfter as $moduleName => $moduleTables) {
$fileAfter = $registryAfter->mapping['table'][$moduleName];
foreach ($moduleTables as $tableName => $tableData) {
$columns = $tableData['column'] ?? [];
foreach ($columns as $column) {
if (
isset($registryTablesBefore[$moduleName][$tableName])
&& !isset($registryTablesBefore[$moduleName][$tableName]['column'][$column])
) {
$operation = new ColumnAdd($moduleName, $tableName . '/' . $column);
$operation = new ColumnAdd($fileAfter, $tableName . '/' . $column);
$this->getReport()->add($this->context, $operation);
}
}
Expand Down
8 changes: 5 additions & 3 deletions src/Analyzer/DBSchema/DbSchemaForeignKeyAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,21 @@ public function analyze($registryBefore, $registryAfter)
$registryTablesAfter = $registryAfter->data['table'] ?? [];

foreach ($registryTablesBefore as $moduleName => $moduleTables) {
$fileBefore = $registryBefore->mapping['table'][$moduleName];
foreach ($moduleTables as $tableName => $tableData) {
$keys = $tableData['foreign'] ?? [];
foreach ($keys as $name => $key) {
if (!isset($registryTablesAfter[$moduleName][$tableName])) {
continue;
}
if ($key !== null && !isset($registryTablesAfter[$moduleName][$tableName]['foreign'][$name])) {
$operation = new ForeignKeyDrop($moduleName, $tableName . '/' . $name);
$operation = new ForeignKeyDrop($fileBefore, $tableName . '/' . $name);
$this->getReport()->add($this->context, $operation);
continue;
}
foreach ($key as $item => $value) {
if ($value !== $registryTablesAfter[$moduleName][$tableName]['foreign'][$name][$item]) {
$operation = new ForeignKeyChange($moduleName, $tableName . '/' . $name . '/' . $item);
$operation = new ForeignKeyChange($fileBefore, $tableName . '/' . $name . '/' . $item);
$this->getReport()->add($this->context, $operation);
}
}
Expand All @@ -78,14 +79,15 @@ public function analyze($registryBefore, $registryAfter)
}

foreach ($registryTablesAfter as $moduleName => $moduleTables) {
$fileAfter = $registryAfter->mapping['table'][$moduleName];
foreach ($moduleTables as $tableName => $tableData) {
$keys = $tableData['foreign'] ?? [];
foreach ($keys as $name => $key) {
if (!isset($registryTablesBefore[$moduleName][$tableName])) {
continue;
}
if ($key !== null && !isset($registryTablesBefore[$moduleName][$tableName]['foreign'][$name])) {
$operation = new ForeignKeyAdd($moduleName, $tableName . '/' . $name);
$operation = new ForeignKeyAdd($fileAfter, $tableName . '/' . $name);
$this->getReport()->add($this->context, $operation);
}
}
Expand Down
10 changes: 6 additions & 4 deletions src/Analyzer/DBSchema/DbSchemaPrimaryKeyAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,15 @@ public function analyze($registryBefore, $registryAfter)
$registryTablesAfter = $registryAfter->data['table'] ?? [];

foreach ($registryTablesBefore as $moduleName => $moduleTables) {
$fileBefore = $registryBefore->mapping['table'][$moduleName];
foreach ($moduleTables as $tableName => $tableData) {
$keys = $tableData['primary'] ?? [];
foreach ($keys as $name => $key) {
if (!isset($registryTablesAfter[$moduleName][$tableName])) {
continue;
}
if ($key !== null && !isset($registryTablesAfter[$moduleName][$tableName]['primary'][$name])) {
$operation = new PrimaryKeyDrop($moduleName, $tableName . '/' . $name);
$operation = new PrimaryKeyDrop($fileBefore, $tableName . '/' . $name);
$this->getReport()->add($this->context, $operation);
continue;
}
Expand All @@ -76,7 +77,7 @@ public function analyze($registryBefore, $registryAfter)
}
}
if (!$matchedColumnFlag) {
$operation = new PrimaryKeyChange($moduleName, $tableName . '/' . $name);
$operation = new PrimaryKeyChange($fileBefore, $tableName . '/' . $name);
$this->getReport()->add($this->context, $operation);
break;
}
Expand All @@ -86,14 +87,15 @@ public function analyze($registryBefore, $registryAfter)
}

foreach ($registryTablesAfter as $moduleName => $moduleTables) {
$fileAfter = $registryAfter->mapping['table'][$moduleName];
foreach ($moduleTables as $tableName => $tableData) {
$keys = $tableData['primary'] ?? [];
foreach ($keys as $name => $key) {
if (!isset($registryTablesBefore[$moduleName][$tableName])) {
continue;
}
if ($key !== null && !isset($registryTablesBefore[$moduleName][$tableName]['primary'][$name])) {
$operation = new PrimaryKeyAdd($moduleName, $tableName . '/' . $name);
$operation = new PrimaryKeyAdd($fileAfter, $tableName . '/' . $name);
$this->getReport()->add($this->context, $operation);
continue;
}
Expand All @@ -108,7 +110,7 @@ public function analyze($registryBefore, $registryAfter)
}
}
if (!$matchedColumnFlag) {
$operation = new PrimaryKeyChange($moduleName, $tableName . '/' . $name);
$operation = new PrimaryKeyChange($fileAfter, $tableName . '/' . $name);
$this->getReport()->add($this->context, $operation);
break;
}
Expand Down
8 changes: 5 additions & 3 deletions src/Analyzer/DBSchema/DbSchemaTableAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,16 @@ public function analyze($registryBefore, $registryAfter)
$registryTablesAfter = $registryAfter->data['table'] ?? [];

foreach ($registryTablesBefore as $moduleName => $moduleTables) {
$fileBefore = $registryBefore->mapping['table'][$moduleName];
foreach ($moduleTables as $tableName => $tableData) {
if (!isset($registryTablesAfter[$moduleName][$tableName])) {
$operation = new TableDropped($moduleName, $tableName);
$operation = new TableDropped($fileBefore, $tableName);
$this->getReport()->add($this->context, $operation);
continue;
}
if ($tableData['resource'] !== $registryTablesAfter[$moduleName][$tableName]['resource']) {
$operation = new TableChangeResource(
$moduleName,
$fileBefore,
$tableName,
$tableData['resource'],
$registryTablesAfter[$moduleName][$tableName]['resource']
Expand All @@ -73,12 +74,13 @@ public function analyze($registryBefore, $registryAfter)
}
}
foreach ($registryTablesAfter as $moduleName => $moduleTables) {
$fileAfter = $registryAfter->mapping['table'][$moduleName];
foreach ($moduleTables as $tableName => $tableData) {
if (
!isset($registryTablesBefore[$moduleName][$tableName])
&& !$this->isModificationTableDeclaration($registryTablesAfter, $moduleName, $tableName)
) {
$operation = new TableAdded($moduleName, $tableName);
$operation = new TableAdded($fileAfter, $tableName);
$this->getReport()->add($this->context, $operation);
}
}
Expand Down
10 changes: 6 additions & 4 deletions src/Analyzer/DBSchema/DbSchemaUniqueKeyAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,15 @@ public function analyze($registryBefore, $registryAfter)
$registryTablesAfter = $registryAfter->data['table'] ?? [];

foreach ($registryTablesBefore as $moduleName => $moduleTables) {
$fileBefore = $registryBefore->mapping['table'][$moduleName];
foreach ($moduleTables as $tableName => $tableData) {
$keys = $tableData['unique'] ?? [];
foreach ($keys as $name => $key) {
if (!isset($registryTablesAfter[$moduleName][$tableName])) {
continue;
}
if ($key !== null && !isset($registryTablesAfter[$moduleName][$tableName]['unique'][$name])) {
$operation = new UniqueKeyDrop($moduleName, $tableName . '/' . $name);
$operation = new UniqueKeyDrop($fileBefore, $tableName . '/' . $name);
$this->getReport()->add($this->context, $operation);
continue;
}
Expand All @@ -77,7 +78,7 @@ public function analyze($registryBefore, $registryAfter)
}
}
if (!$matchedColumnFlag) {
$operation = new UniqueKeyChange($moduleName, $tableName . '/' . $name);
$operation = new UniqueKeyChange($fileBefore, $tableName . '/' . $name);
$this->getReport()->add($this->context, $operation);
break;
}
Expand All @@ -87,14 +88,15 @@ public function analyze($registryBefore, $registryAfter)
}

foreach ($registryTablesAfter as $moduleName => $moduleTables) {
$fileAfter = $registryAfter->mapping['table'][$moduleName];
foreach ($moduleTables as $tableName => $tableData) {
$keys = $tableData['unique'] ?? [];
foreach ($keys as $name => $key) {
if (!isset($registryTablesBefore[$moduleName][$tableName])) {
continue;
}
if ($key !== null && !isset($registryTablesBefore[$moduleName][$tableName]['unique'][$name])) {
$operation = new UniqueKeyAdd($moduleName, $tableName . '/' . $name);
$operation = new UniqueKeyAdd($fileAfter, $tableName . '/' . $name);
$this->getReport()->add($this->context, $operation);
continue;
}
Expand All @@ -109,7 +111,7 @@ public function analyze($registryBefore, $registryAfter)
}
}
if (!$matchedColumnFlag) {
$operation = new UniqueKeyChange($moduleName, $tableName . '/' . $name);
$operation = new UniqueKeyChange($fileAfter, $tableName . '/' . $name);
$this->getReport()->add($this->context, $operation);
break;
}
Expand Down
15 changes: 11 additions & 4 deletions src/Analyzer/DBSchema/DbSchemaWhitelistAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@

use Magento\SemanticVersionChecker\Analyzer\AnalyzerInterface;
use Magento\SemanticVersionChecker\Operation\InvalidWhitelist;
use Magento\SemanticVersionChecker\Operation\WhiteListWasRemoved;
use PHPSemVerChecker\Registry\Registry;
use PHPSemVerChecker\Report\Report;

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

foreach ($registryTablesAfter as $moduleName => $tablesData) {
$whiteListFileAfter = $registryAfter->mapping['whitelist_json'][$moduleName] ?? '';
if (!file_exists($whiteListFileAfter)) {
$tableFileAfter = $registryAfter->mapping['table'][$moduleName];
$whiteListFileAfter = dirname($tableFileAfter) . '/db_schema_whitelist.json';
$operation = new WhiteListWasRemoved($whiteListFileAfter, $moduleName);
$this->report->add('database', $operation);
continue;
}
if (count($tablesData)) {
foreach (array_keys($tablesData) as $table) {
if (!isset($dbWhiteListContent[$moduleName][$table])) {
$operation = new InvalidWhitelist($moduleName, $table);
$operation = new InvalidWhitelist($whiteListFileAfter, $table);
$this->report->add('database', $operation);
}
}
}
}


return $this->report;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,31 +49,32 @@ public function analyze($registryBefore, $registryAfter)

/** @var array $tablesData */
foreach ($whiteListBefore as $moduleName => $beforeModuleTablesData) {
$fileBefore = $registryBefore->mapping['whitelist_json'][$moduleName];
if (!isset($whiteListAfter[$moduleName])) {
$operation = new WhiteListWasRemoved($moduleName);
$operation = new WhiteListWasRemoved($fileBefore, $moduleName);
$this->report->add('database', $operation);
continue;
}
$afterModuleTablesData = $whiteListAfter[$moduleName];
/** @var array $beforeTableData */
foreach ($beforeModuleTablesData as $tableName => $beforeTableData) {
if (!$this->isArrayExistsAndHasSameSize($afterModuleTablesData, $beforeTableData, $tableName)) {
$this->addReport($moduleName, $tableName);
$this->addReport($fileBefore, $tableName);
continue;
}
$afterTableData = $afterModuleTablesData[$tableName];
/** @var array $beforeTablePartData */
foreach ($beforeTableData as $tablePartName => $beforeTablePartData) {
if (!$this->isArrayExistsAndHasSameSize($afterTableData, $beforeTablePartData, $tablePartName)) {
$this->addReport($moduleName, $tableName . '/' . $tablePartName);
$this->addReport($fileBefore, $tableName . '/' . $tablePartName);
continue;
}
$afterTablePartData = $afterTableData[$tablePartName];
/** @var bool $beforeStatus */
foreach ($beforeTablePartData as $name => $beforeStatus) {
//checks if array exists in new whitelist.json and if it has different amount of items inside
if (!isset($afterTablePartData[$name])) {
$this->addReport($moduleName, $tableName . '/' . $tablePartName . '/' . $name);
$this->addReport($fileBefore, $tableName . '/' . $tablePartName . '/' . $name);
}
}
}
Expand Down Expand Up @@ -102,14 +103,14 @@ public function isArrayExistsAndHasSameSize(array $after, array $beforeArray, st
}

/**
* @param string $moduleName
* @param string $location
* @param string $target
*
* @return void
*/
public function addReport(string $moduleName, string $target): void
public function addReport(string $location, string $target): void
{
$operation = new WhiteListReduced($moduleName, $target);
$operation = new WhiteListReduced($location, $target);
$this->report->add('database', $operation);
}
}

0 comments on commit 9ef11a4

Please sign in to comment.