14
14
use PHPSemVerChecker \Report \Report ;
15
15
16
16
/**
17
- * Class DbSchemaAnalyzer
18
- * @package Magento\SemanticVersionChecker\Analyzer
17
+ * Implements an analyzer for the database schema whitelist files
19
18
*/
20
19
class DbSchemaWhitelistAnalyzer implements AnalyzerInterface
21
20
{
@@ -25,6 +24,18 @@ class DbSchemaWhitelistAnalyzer implements AnalyzerInterface
25
24
* @var string
26
25
*/
27
26
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
+ }
28
39
29
40
/**
30
41
* Class analyzer.
@@ -35,29 +46,25 @@ class DbSchemaWhitelistAnalyzer implements AnalyzerInterface
35
46
*/
36
47
public function analyze ($ registryBefore , $ registryAfter )
37
48
{
38
- $ report = new Report ();
39
49
$ registryTablesAfter = $ registryAfter ->data ['table ' ] ?? [];
40
50
$ registryTablesBefore = $ registryBefore ->data ['table ' ] ?? [];
41
51
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 ();
42
56
foreach ($ registryTablesAfter as $ moduleName => $ tablesData ) {
43
57
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 =
48
59
$ 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 ' ,
51
63
$ dbFile
52
64
);
53
- $ dbWhiteListFile = str_replace (
54
- 'db_schema.xml ' ,
55
- 'db_schema_whitelist.json ' ,
56
- $ dbWhiteListFile
57
- );
58
65
if (!file_exists ($ dbWhiteListFile )) {
59
66
$ operation = new WhiteListWasRemoved ($ dbWhiteListFile , $ moduleName );
60
- $ report ->add ('database ' , $ operation );
67
+ $ this -> report ->add ('database ' , $ operation );
61
68
continue ;
62
69
} else {
63
70
$ dbWhiteListContent = json_decode (
@@ -70,13 +77,11 @@ public function analyze($registryBefore, $registryAfter)
70
77
foreach (array_keys ($ tables ) as $ table ) {
71
78
if (!isset ($ dbWhiteListContent [$ table ])) {
72
79
$ operation = new InvalidWhitelist ($ dbWhiteListFile , $ table );
73
- $ report ->add ('database ' , $ operation );
80
+ $ this -> report ->add ('database ' , $ operation );
74
81
}
75
82
}
76
83
}
77
84
}
78
-
79
-
80
- return $ report ;
85
+ return $ this ->report ;
81
86
}
82
87
}
0 commit comments