77 */
88namespace Magento \TestFramework \Dependency ;
99
10- use DOMDocument ;
11- use DOMXPath ;
10+ use Magento \Framework \App \Utility \Classes ;
1211use Magento \Framework \App \Utility \Files ;
1312use Magento \TestFramework \Dependency \VirtualType \VirtualTypeMapper ;
1413
14+ /**
15+ * Class provide dependency rule for di.xml config files.
16+ */
1517class DiRule implements RuleInterface
1618{
1719 /**
@@ -33,6 +35,8 @@ public function __construct(VirtualTypeMapper $mapper)
3335 }
3436
3537 /**
38+ * Get class name pattern.
39+ *
3640 * @return string
3741 * @throws \Exception
3842 */
@@ -73,6 +77,7 @@ private function getPattern()
7377 */
7478 public function getDependencyInfo ($ currentModule , $ fileType , $ file , &$ contents )
7579 {
80+ //phpcs:ignore Magento2.Functions.DiscouragedFunction
7681 if (pathinfo ($ file , PATHINFO_BASENAME ) !== 'di.xml ' ) {
7782 return [];
7883 }
@@ -99,12 +104,14 @@ public function getDependencyInfo($currentModule, $fileType, $file, &$contents)
99104 }
100105
101106 /**
107+ * Fetch all possible dependencies.
108+ *
102109 * @param string $contents
103110 * @return array
104111 */
105112 private function fetchPossibleDependencies ($ contents )
106113 {
107- $ doc = new DOMDocument ();
114+ $ doc = new \ DOMDocument ();
108115 $ doc ->loadXML ($ contents );
109116 return [
110117 RuleInterface::TYPE_SOFT => $ this ->getSoftDependencies ($ doc ),
@@ -113,16 +120,22 @@ private function fetchPossibleDependencies($contents)
113120 }
114121
115122 /**
116- * @param DOMDocument $doc
123+ * Collect soft dependencies.
124+ *
125+ * @param \DOMDocument $doc
117126 * @return array
118127 */
119- private function getSoftDependencies (DOMDocument $ doc )
128+ private function getSoftDependencies (\ DOMDocument $ doc )
120129 {
121130 $ result = [];
122131 foreach (self ::$ tagNameMap as $ tagName => $ attributeNames ) {
123132 $ nodes = $ doc ->getElementsByTagName ($ tagName );
124133 /** @var \DOMElement $node */
125134 foreach ($ nodes as $ node ) {
135+ if ($ tagName === 'virtualType ' && !$ node ->getAttribute ('type ' )) {
136+ $ result [] = Classes::resolveVirtualType ($ node ->getAttribute ('name ' ));
137+ continue ;
138+ }
126139 foreach ($ attributeNames as $ attributeName ) {
127140 $ result [] = $ node ->getAttribute ($ attributeName );
128141 }
@@ -133,13 +146,15 @@ private function getSoftDependencies(DOMDocument $doc)
133146 }
134147
135148 /**
136- * @param DOMDocument $doc
149+ * Collect hard dependencies.
150+ *
151+ * @param \DOMDocument $doc
137152 * @return array
138153 */
139- private function getHardDependencies (DOMDocument $ doc )
154+ private function getHardDependencies (\ DOMDocument $ doc )
140155 {
141156 $ result = [];
142- $ xpath = new DOMXPath ($ doc );
157+ $ xpath = new \ DOMXPath ($ doc );
143158 $ textNodes = $ xpath ->query ('//*[@xsi:type="object"] ' );
144159 /** @var \DOMElement $node */
145160 foreach ($ textNodes as $ node ) {
0 commit comments