1313use Magento \SemanticVersionChecker \Node \VirtualType ;
1414use Magento \SemanticVersionChecker \Operation \DiXml \VirtualTypeChanged ;
1515use Magento \SemanticVersionChecker \Operation \DiXml \VirtualTypeRemoved ;
16+ use Magento \SemanticVersionChecker \Operation \DiXml \VirtualTypeToTypeChanged ;
1617use Magento \SemanticVersionChecker \Registry \XmlRegistry ;
1718use PHPSemVerChecker \Registry \Registry ;
1819use PHPSemVerChecker \Report \Report ;
@@ -57,10 +58,15 @@ public function analyze($registryBefore, $registryAfter)
5758 foreach ($ nodesBefore as $ moduleName => $ moduleNodes ) {
5859 /* @var VirtualType $nodeBefore */
5960 $ fileBefore = $ registryBefore ->mapping [XmlRegistry::NODES_KEY ][$ moduleName ];
61+
62+ // Check if $moduleName exists in $registryAfter->mapping[XmlRegistry::NODES_KEY]
63+ if (!isset ($ registryAfter ->mapping [XmlRegistry::NODES_KEY ][$ moduleName ])) {
64+ continue ;
65+ }
6066 foreach ($ moduleNodes as $ name => $ nodeBefore ) {
6167 // search nodesAfter the by name
6268 $ nodeAfter = $ nodesAfter [$ moduleName ][$ name ] ?? false ;
63-
69+ $ fileAfter = $ registryAfter -> mapping [XmlRegistry:: NODES_KEY ][ $ moduleName ];
6470 if ($ nodeAfter !== false && $ nodeBefore !== $ nodeAfter ) {
6571 /* @var VirtualType $nodeAfter */
6672 $ this ->triggerNodeChange ($ nodeBefore , $ nodeAfter , $ fileBefore );
@@ -78,14 +84,68 @@ public function analyze($registryBefore, $registryAfter)
7884 }
7985 }
8086
81- $ operation = new VirtualTypeRemoved ($ fileBefore , $ name );
87+ $ finalPath = $ this ->convertClassNameToFilePath ($ fileAfter , $ name , '.php ' );
88+
89+ if (file_exists ($ finalPath )) {
90+ $ operation = new VirtualTypeToTypeChanged ($ fileBefore , $ name );
91+ } else {
92+ $ operation = new VirtualTypeRemoved ($ fileBefore , $ name );
93+ }
8294 $ this ->report ->add ('di ' , $ operation );
8395 }
8496 }
8597
8698 return $ this ->report ;
8799 }
88100
101+ /**
102+ * Method to convert class name to file path
103+ *
104+ * @param string $filePath
105+ * @param string $className
106+ * @param string $extraString
107+ * @return string
108+ */
109+ private function convertClassNameToFilePath ($ filePath , $ className , $ extraString = '' ): string
110+ {
111+ // Split the initial file path to get the base directory.
112+ $ parts = explode ('/ ' , $ filePath );
113+ $ classParts = explode ('\\' , $ className );
114+
115+ // Find the common part between the file path and class name.
116+ $ baseDirParts = [];
117+ foreach ($ parts as $ part ) {
118+ $ baseDirParts [] = $ part ;
119+
120+ if (in_array ($ part , $ classParts )) {
121+ break ;
122+ }
123+ }
124+
125+ // Reconstruct the base directory path.
126+ $ baseDir = implode ('/ ' , $ baseDirParts );
127+
128+ // Replace namespace separators with directory separators in the class name.
129+ $ classFilePath = str_replace ('\\' , '/ ' , $ className );
130+
131+ $ position = strpos ($ classFilePath , "/ " );
132+
133+ if ($ position !== false ) {
134+ $ classFilePath = substr ($ classFilePath , $ position );
135+ }
136+
137+ // Combine the base directory and class file path.
138+ $ fullPath = rtrim ($ baseDir , '/ ' ) . $ classFilePath ;
139+
140+
141+ // Append the extra string if provided.
142+ if ($ extraString ) {
143+ $ fullPath .= $ extraString ;
144+ }
145+ return $ fullPath ;
146+ }
147+
148+
89149 /**
90150 * Return a filtered node list from type {@link VirtualType}
91151 *
0 commit comments