5
5
* See COPYING.txt for license details.
6
6
*/
7
7
8
+ declare (strict_types=1 );
9
+
8
10
namespace Magento \SemanticVersionChecker \Analyzer \DBSchema ;
9
11
10
12
use Magento \SemanticVersionChecker \Analyzer \AnalyzerInterface ;
14
16
use PHPSemVerChecker \Report \Report ;
15
17
16
18
/**
17
- * Implements an analyzer for the database schema whitelist files
19
+ * Implements an analyzer fdr the database schema whitelist files.
20
+ * @noinspection PhpUnused
18
21
*/
19
22
class DbSchemaWhitelistAnalyzer implements AnalyzerInterface
20
23
{
@@ -30,10 +33,11 @@ class DbSchemaWhitelistAnalyzer implements AnalyzerInterface
30
33
private $ report ;
31
34
32
35
/**
33
- * DbSchemaWhitelistAnalyzer constructor.
34
36
* @param Report $report
35
37
*/
36
- public function __construct (Report $ report ) {
38
+ public function __construct (
39
+ Report $ report
40
+ ) {
37
41
$ this ->report = $ report ;
38
42
}
39
43
@@ -42,41 +46,25 @@ public function __construct(Report $report) {
42
46
*
43
47
* @param Registry $registryBefore
44
48
* @param Registry $registryAfter
49
+ *
45
50
* @return Report
46
51
*/
47
52
public function analyze ($ registryBefore , $ registryAfter )
48
53
{
49
54
$ registryTablesAfter = $ registryAfter ->data ['table ' ] ?? [];
50
- $ registryTablesBefore = $ registryBefore ->data ['table ' ] ?? [];
55
+ $ dbWhiteListContent = $ registryAfter ->data ['whitelist_json ' ] ?? [];
51
56
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 ();
56
57
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
+ }
57
64
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 );
80
68
$ this ->report ->add ('database ' , $ operation );
81
69
}
82
70
}
0 commit comments