@@ -151,16 +151,18 @@ protected function execute(InputInterface $input, OutputInterface $cliOutput)
151
151
$ versionReport = $ semanticVersionChecker ->loadVersionReport ();
152
152
$ changedFiles = $ semanticVersionChecker ->loadChangedFiles ();
153
153
154
- if ($ this ->areFilesPresentLocally ($ changedFiles , $ sourceAfterDir )) {
155
- $ versionIncrease =Level::PATCH ; // Set to "Patch"
156
- $ versionIncWord = strtoupper ($ this ->changeLevels [$ versionIncrease ]);
157
- }
158
- foreach ($ changedFiles as &$ file ) {
154
+ foreach ($ changedFiles as $ file ) {
155
+
159
156
if (substr ($ file , 0 , strlen ($ sourceBeforeDir )) == $ sourceBeforeDir ) {
160
157
$ file = substr ($ file , strlen ($ sourceBeforeDir ));
161
158
} elseif (substr ($ file , 0 , strlen ($ sourceAfterDir )) == $ sourceAfterDir ) {
162
159
$ file = substr ($ file , strlen ($ sourceAfterDir ));
163
160
}
161
+
162
+ if ($ this ->isVirtualTypeReplacedByType ($ sourceBeforeDir .$ file , $ sourceAfterDir .$ file )) {
163
+ $ versionIncrease =Level::PATCH ; // Set to "Patch"
164
+ $ versionIncWord = strtoupper ($ this ->changeLevels [$ versionIncrease ]);
165
+ }
164
166
}
165
167
$ changedFiles = array_unique ($ changedFiles );
166
168
@@ -242,18 +244,34 @@ protected function execute(InputInterface $input, OutputInterface $cliOutput)
242
244
}
243
245
244
246
/**
245
- * Method to check if file exist.
247
+ * Method to check if definition is changed from virtual to type
246
248
*
247
- * @param array $changedFiles
248
- * @param string $sourceAfterDir
249
+ * @param string $source
250
+ * @param string $target
249
251
* @return bool
250
252
*/
251
- private function areFilesPresentLocally ( array $ changedFiles , string $ sourceAfterDir ): bool
253
+ private function isVirtualTypeReplacedByType ( string $ source , string $ target ): bool
252
254
{
253
- foreach ($ changedFiles as $ file ) {
254
- $ localFilePath = $ sourceAfterDir ;
255
- if (file_exists ($ localFilePath )) {
256
- return true ;
255
+ $ beforeContent = file_exists ($ source ) ?file_get_contents ($ source ):'' ;
256
+ $ afterContent = file_exists ($ target ) ? file_get_contents ($ target ) : '' ;
257
+
258
+ if (strpos ($ target , 'di.xml ' ) !== false ) {
259
+ $ virtualTypePattern = '/<virtualType\s+name="([^"]+)"\s+type="[^"]+">.*?<\/virtualType>/s ' ;
260
+ $ typePattern = '/<type\s+name="([^"]+)"\s*>.*?<\/type>/s ' ;
261
+
262
+ preg_match_all ($ virtualTypePattern , $ beforeContent , $ beforeVirtualTypes );
263
+ preg_match_all ($ typePattern , $ afterContent , $ afterTypes );
264
+
265
+ // Extract the names of the virtualTypes and types
266
+ $ beforeVirtualTypeNames = $ beforeVirtualTypes [1 ] ?? [];
267
+ $ afterTypeNames = $ afterTypes [1 ] ?? [];
268
+
269
+ if (!empty ($ beforeVirtualTypeNames )) {
270
+ foreach ($ beforeVirtualTypeNames as $ virtualTypeName ) {
271
+ if (in_array ($ virtualTypeName , $ afterTypeNames )) {
272
+ return true ;
273
+ }
274
+ }
257
275
}
258
276
}
259
277
return false ;
0 commit comments