7
7
*/
8
8
namespace Magento \TestFramework \Dependency ;
9
9
10
- use DOMDocument ;
11
- use DOMXPath ;
10
+ use Magento \Framework \App \Utility \Classes ;
12
11
use Magento \Framework \App \Utility \Files ;
13
12
use Magento \TestFramework \Dependency \VirtualType \VirtualTypeMapper ;
14
13
14
+ /**
15
+ * Class provide dependency rule for di.xml config files.
16
+ */
15
17
class DiRule implements RuleInterface
16
18
{
17
19
/**
@@ -33,6 +35,8 @@ public function __construct(VirtualTypeMapper $mapper)
33
35
}
34
36
35
37
/**
38
+ * Get class name pattern.
39
+ *
36
40
* @return string
37
41
* @throws \Exception
38
42
*/
@@ -73,6 +77,7 @@ private function getPattern()
73
77
*/
74
78
public function getDependencyInfo ($ currentModule , $ fileType , $ file , &$ contents )
75
79
{
80
+ //phpcs:ignore Magento2.Functions.DiscouragedFunction
76
81
if (pathinfo ($ file , PATHINFO_BASENAME ) !== 'di.xml ' ) {
77
82
return [];
78
83
}
@@ -99,12 +104,14 @@ public function getDependencyInfo($currentModule, $fileType, $file, &$contents)
99
104
}
100
105
101
106
/**
107
+ * Fetch all possible dependencies.
108
+ *
102
109
* @param string $contents
103
110
* @return array
104
111
*/
105
112
private function fetchPossibleDependencies ($ contents )
106
113
{
107
- $ doc = new DOMDocument ();
114
+ $ doc = new \ DOMDocument ();
108
115
$ doc ->loadXML ($ contents );
109
116
return [
110
117
RuleInterface::TYPE_SOFT => $ this ->getSoftDependencies ($ doc ),
@@ -113,16 +120,22 @@ private function fetchPossibleDependencies($contents)
113
120
}
114
121
115
122
/**
116
- * @param DOMDocument $doc
123
+ * Collect soft dependencies.
124
+ *
125
+ * @param \DOMDocument $doc
117
126
* @return array
118
127
*/
119
- private function getSoftDependencies (DOMDocument $ doc )
128
+ private function getSoftDependencies (\ DOMDocument $ doc )
120
129
{
121
130
$ result = [];
122
131
foreach (self ::$ tagNameMap as $ tagName => $ attributeNames ) {
123
132
$ nodes = $ doc ->getElementsByTagName ($ tagName );
124
133
/** @var \DOMElement $node */
125
134
foreach ($ nodes as $ node ) {
135
+ if ($ tagName === 'virtualType ' && !$ node ->getAttribute ('type ' )) {
136
+ $ result [] = Classes::resolveVirtualType ($ node ->getAttribute ('name ' ));
137
+ continue ;
138
+ }
126
139
foreach ($ attributeNames as $ attributeName ) {
127
140
$ result [] = $ node ->getAttribute ($ attributeName );
128
141
}
@@ -133,13 +146,15 @@ private function getSoftDependencies(DOMDocument $doc)
133
146
}
134
147
135
148
/**
136
- * @param DOMDocument $doc
149
+ * Collect hard dependencies.
150
+ *
151
+ * @param \DOMDocument $doc
137
152
* @return array
138
153
*/
139
- private function getHardDependencies (DOMDocument $ doc )
154
+ private function getHardDependencies (\ DOMDocument $ doc )
140
155
{
141
156
$ result = [];
142
- $ xpath = new DOMXPath ($ doc );
157
+ $ xpath = new \ DOMXPath ($ doc );
143
158
$ textNodes = $ xpath ->query ('//*[@xsi:type="object"] ' );
144
159
/** @var \DOMElement $node */
145
160
foreach ($ textNodes as $ node ) {
0 commit comments