55 * See COPYING.txt for license details.
66 */
77
8+ declare (strict_types=1 );
9+
810namespace Magento \SemanticVersionChecker \Analyzer \DBSchema ;
911
1012use Magento \SemanticVersionChecker \Analyzer \AnalyzerInterface ;
1416use 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 */
1922class 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 }
0 commit comments