17
17
*
18
18
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
19
19
*/
20
- class DeclarativeSchemaDependencyProvider extends DependencyProvider
20
+ class DeclarativeSchemaDependencyProvider
21
21
{
22
22
/**
23
23
* Declarative name for table entity of the declarative schema.
@@ -49,6 +49,16 @@ class DeclarativeSchemaDependencyProvider extends DependencyProvider
49
49
*/
50
50
private $ moduleSchemaFileMapping = [];
51
51
52
+ /**
53
+ * @var DependencyProvider
54
+ */
55
+ private $ dependencyProvider ;
56
+
57
+ public function __construct (DependencyProvider $ dependencyProvider )
58
+ {
59
+ $ this ->dependencyProvider = $ dependencyProvider ;
60
+ }
61
+
52
62
/**
53
63
* Provide declared dependencies between modules based on the declarative schema configuration.
54
64
*
@@ -58,10 +68,14 @@ class DeclarativeSchemaDependencyProvider extends DependencyProvider
58
68
*/
59
69
public function getDeclaredExistingModuleDependencies (string $ moduleName ): array
60
70
{
61
- $ this ->initDeclaredDependencies ();
71
+ $ this ->dependencyProvider -> initDeclaredDependencies ();
62
72
$ dependencies = $ this ->getDependenciesFromFiles ($ this ->getSchemaFileNameByModuleName ($ moduleName ));
63
73
$ dependencies = $ this ->filterSelfDependency ($ moduleName , $ dependencies );
64
- $ declared = $ this ->getDeclaredDependencies ($ moduleName , self ::TYPE_HARD , self ::MAP_TYPE_DECLARED );
74
+ $ declared = $ this ->dependencyProvider ->getDeclaredDependencies (
75
+ $ moduleName ,
76
+ DependencyProvider::TYPE_HARD ,
77
+ DependencyProvider::MAP_TYPE_DECLARED
78
+ );
65
79
66
80
$ existingDeclared = [];
67
81
foreach ($ dependencies as $ dependency ) {
@@ -89,7 +103,7 @@ public function getDeclaredExistingModuleDependencies(string $moduleName): array
89
103
*/
90
104
public function getUndeclaredModuleDependencies (string $ moduleName ): array
91
105
{
92
- $ this ->initDeclaredDependencies ();
106
+ $ this ->dependencyProvider -> initDeclaredDependencies ();
93
107
$ dependencies = $ this ->getDependenciesFromFiles ($ this ->getSchemaFileNameByModuleName ($ moduleName ));
94
108
$ dependencies = $ this ->filterSelfDependency ($ moduleName , $ dependencies );
95
109
return $ this ->collectDependencies ($ moduleName , $ dependencies );
@@ -100,7 +114,7 @@ public function getUndeclaredModuleDependencies(string $moduleName): array
100
114
*
101
115
* @param string $module
102
116
* @return string
103
- * @throws \Exception
117
+ * @throws \Magento\Framework\ Exception\LocalizedException
104
118
*/
105
119
private function getSchemaFileNameByModuleName (string $ module ): string
106
120
{
@@ -128,10 +142,10 @@ private function getSchemaFileNameByModuleName(string $module): string
128
142
* @param array $dependencies
129
143
* @return array
130
144
*/
131
- private function filterSelfDependency (string $ moduleName , array $ dependencies ):array
145
+ private function filterSelfDependency (string $ moduleName , array $ dependencies ): array
132
146
{
133
147
foreach ($ dependencies as $ id => $ modules ) {
134
- $ decodedId = $ this -> decodeDependencyId ($ id );
148
+ $ decodedId = self :: decodeDependencyId ($ id );
135
149
$ entityType = $ decodedId ['entityType ' ];
136
150
if ($ entityType === self ::SCHEMA_ENTITY_TABLE || $ entityType === "column " ) {
137
151
if (array_search ($ moduleName , $ modules ) !== false ) {
@@ -178,7 +192,7 @@ private function filterComplexDependency(string $moduleName, array $modules): ar
178
192
* Retrieve declarative schema declaration.
179
193
*
180
194
* @return array
181
- * @throws \Exception
195
+ * @throws \Magento\Framework\ Exception\LocalizedException
182
196
*/
183
197
private function getDeclarativeSchema (): array
184
198
{
@@ -201,10 +215,9 @@ private function getDeclarativeSchema(): array
201
215
array_push ($ tableDeclaration ['modules ' ], $ moduleName );
202
216
$ moduleDeclaration = array_replace_recursive (
203
217
$ moduleDeclaration ,
204
- [self ::SCHEMA_ENTITY_TABLE =>
205
- [
206
- $ tableName => $ tableDeclaration ,
207
- ]
218
+ [self ::SCHEMA_ENTITY_TABLE => [
219
+ $ tableName => $ tableDeclaration ,
220
+ ]
208
221
]
209
222
);
210
223
foreach ($ entityTypes as $ entityType ) {
@@ -213,11 +226,9 @@ private function getDeclarativeSchema(): array
213
226
}
214
227
$ moduleDeclaration = array_replace_recursive (
215
228
$ moduleDeclaration ,
216
- [self ::SCHEMA_ENTITY_TABLE =>
217
- [
218
- $ tableName =>
219
- $ this ->addModuleAssigment ($ tableDeclaration , $ entityType , $ moduleName )
220
- ]
229
+ [self ::SCHEMA_ENTITY_TABLE => [
230
+ $ tableName => $ this ->addModuleAssigment ($ tableDeclaration , $ entityType , $ moduleName )
231
+ ]
221
232
]
222
233
);
223
234
}
@@ -236,7 +247,7 @@ private function getDeclarativeSchema(): array
236
247
* @param string $entityType
237
248
* @param null|string $entityName
238
249
* @return array
239
- * @throws \Exception
250
+ * @throws \Magento\Framework\ Exception\LocalizedException
240
251
*/
241
252
private function resolveEntityDependencies (string $ tableName , string $ entityType , ?string $ entityName = null ): array
242
253
{
@@ -319,7 +330,7 @@ private function getDependenciesFromFiles($file)
319
330
*
320
331
* @param array $moduleDeclaration
321
332
* @return array
322
- * @throws \Exception
333
+ * @throws \Magento\Framework\ Exception\LocalizedException
323
334
*/
324
335
private function getDisabledDependencies (array $ moduleDeclaration ): array
325
336
{
@@ -532,7 +543,7 @@ public static function decodeDependencyId(string $id): array
532
543
* @param array $dependencies
533
544
* @return array
534
545
*/
535
- private function collectDependencies ($ currentModuleName , $ dependencies = [])
546
+ private function collectDependencies ($ currentModuleName , $ dependencies = []): array
536
547
{
537
548
if (empty ($ dependencies )) {
538
549
return [];
@@ -541,7 +552,11 @@ private function collectDependencies($currentModuleName, $dependencies = [])
541
552
$ this ->collectDependency ($ dependencyName , $ dependency , $ currentModuleName );
542
553
}
543
554
544
- return $ this ->getDeclaredDependencies ($ currentModuleName , self ::TYPE_HARD , self ::MAP_TYPE_FOUND );
555
+ return $ this ->dependencyProvider ->getDeclaredDependencies (
556
+ $ currentModuleName ,
557
+ DependencyProvider::TYPE_HARD ,
558
+ DependencyProvider::MAP_TYPE_FOUND
559
+ );
545
560
}
546
561
547
562
/**
@@ -556,31 +571,22 @@ private function collectDependency(
556
571
array $ dependency ,
557
572
string $ currentModule
558
573
) {
559
- $ declared = $ this ->getDeclaredDependencies ($ currentModule , self ::TYPE_HARD , self ::MAP_TYPE_DECLARED );
574
+ $ declared = $ this ->dependencyProvider ->getDeclaredDependencies (
575
+ $ currentModule ,
576
+ DependencyProvider::TYPE_HARD ,
577
+ DependencyProvider::MAP_TYPE_DECLARED
578
+ );
560
579
$ checkResult = array_intersect ($ declared , $ dependency );
561
580
562
581
if (empty ($ checkResult )) {
563
- $ this ->addDependencies (
582
+ $ this ->dependencyProvider -> addDependencies (
564
583
$ currentModule ,
565
- self ::TYPE_HARD ,
566
- self ::MAP_TYPE_FOUND ,
584
+ DependencyProvider ::TYPE_HARD ,
585
+ DependencyProvider ::MAP_TYPE_FOUND ,
567
586
[
568
587
$ dependencyName => $ dependency ,
569
588
]
570
589
);
571
590
}
572
591
}
573
-
574
- /**
575
- * Retrieve array of dependency items.
576
- *
577
- * @param $module
578
- * @param $type
579
- * @param $mapType
580
- * @return array
581
- */
582
- protected function getDeclaredDependencies (string $ module , string $ type , string $ mapType )
583
- {
584
- return $ this ->mapDependencies [$ module ][$ type ][$ mapType ] ?? [];
585
- }
586
592
}
0 commit comments