13
13
use Magento \SemanticVersionChecker \Node \VirtualType ;
14
14
use Magento \SemanticVersionChecker \Operation \DiXml \VirtualTypeChanged ;
15
15
use Magento \SemanticVersionChecker \Operation \DiXml \VirtualTypeRemoved ;
16
+ use Magento \SemanticVersionChecker \Operation \DiXml \VirtualTypeToTypeChanged ;
16
17
use Magento \SemanticVersionChecker \Registry \XmlRegistry ;
17
18
use PHPSemVerChecker \Registry \Registry ;
18
19
use PHPSemVerChecker \Report \Report ;
@@ -60,7 +61,7 @@ public function analyze($registryBefore, $registryAfter)
60
61
foreach ($ moduleNodes as $ name => $ nodeBefore ) {
61
62
// search nodesAfter the by name
62
63
$ nodeAfter = $ nodesAfter [$ moduleName ][$ name ] ?? false ;
63
-
64
+ $ fileAfter = $ registryAfter -> mapping [XmlRegistry:: NODES_KEY ][ $ moduleName ];
64
65
if ($ nodeAfter !== false && $ nodeBefore !== $ nodeAfter ) {
65
66
/* @var VirtualType $nodeAfter */
66
67
$ this ->triggerNodeChange ($ nodeBefore , $ nodeAfter , $ fileBefore );
@@ -78,14 +79,68 @@ public function analyze($registryBefore, $registryAfter)
78
79
}
79
80
}
80
81
81
- $ operation = new VirtualTypeRemoved ($ fileBefore , $ name );
82
+ $ finalPath = $ this ->convertClassNameToFilePath ($ fileAfter , $ name , '.php ' );
83
+
84
+ if (file_exists ($ finalPath )) {
85
+ $ operation = new VirtualTypeToTypeChanged ($ fileBefore , $ name );
86
+ } else {
87
+ $ operation = new VirtualTypeRemoved ($ fileBefore , $ name );
88
+ }
82
89
$ this ->report ->add ('di ' , $ operation );
83
90
}
84
91
}
85
92
86
93
return $ this ->report ;
87
94
}
88
95
96
+ /**
97
+ * Method to convert class name to file path
98
+ *
99
+ * @param string $filePath
100
+ * @param string $className
101
+ * @param string $extraString
102
+ * @return string
103
+ */
104
+ private function convertClassNameToFilePath ($ filePath , $ className , $ extraString = '' ): string
105
+ {
106
+ // Split the initial file path to get the base directory.
107
+ $ parts = explode ('/ ' , $ filePath );
108
+ $ classParts = explode ('\\' , $ className );
109
+
110
+ // Find the common part between the file path and class name.
111
+ $ baseDirParts = [];
112
+ foreach ($ parts as $ part ) {
113
+ $ baseDirParts [] = $ part ;
114
+
115
+ if (in_array ($ part , $ classParts )) {
116
+ break ;
117
+ }
118
+ }
119
+
120
+ // Reconstruct the base directory path.
121
+ $ baseDir = implode ('/ ' , $ baseDirParts );
122
+
123
+ // Replace namespace separators with directory separators in the class name.
124
+ $ classFilePath = str_replace ('\\' , '/ ' , $ className );
125
+
126
+ $ position = strpos ($ classFilePath , "/ " );
127
+
128
+ if ($ position !== false ) {
129
+ $ classFilePath = substr ($ classFilePath , $ position );
130
+ }
131
+
132
+ // Combine the base directory and class file path.
133
+ $ fullPath = rtrim ($ baseDir , '/ ' ) . $ classFilePath ;
134
+
135
+
136
+ // Append the extra string if provided.
137
+ if ($ extraString ) {
138
+ $ fullPath .= $ extraString ;
139
+ }
140
+ return $ fullPath ;
141
+ }
142
+
143
+
89
144
/**
90
145
* Return a filtered node list from type {@link VirtualType}
91
146
*
0 commit comments