@@ -151,16 +151,18 @@ protected function execute(InputInterface $input, OutputInterface $cliOutput)
151151 $ versionReport = $ semanticVersionChecker ->loadVersionReport ();
152152 $ changedFiles = $ semanticVersionChecker ->loadChangedFiles ();
153153
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+
159156 if (substr ($ file , 0 , strlen ($ sourceBeforeDir )) == $ sourceBeforeDir ) {
160157 $ file = substr ($ file , strlen ($ sourceBeforeDir ));
161158 } elseif (substr ($ file , 0 , strlen ($ sourceAfterDir )) == $ sourceAfterDir ) {
162159 $ file = substr ($ file , strlen ($ sourceAfterDir ));
163160 }
161+
162+ if ($ this ->isVirtualTypeReplacedByType ($ sourceBeforeDir .$ file , $ sourceAfterDir .$ file )) {
163+ $ versionIncrease =Level::PATCH ; // Set to "Patch"
164+ $ versionIncWord = strtoupper ($ this ->changeLevels [$ versionIncrease ]);
165+ }
164166 }
165167 $ changedFiles = array_unique ($ changedFiles );
166168
@@ -242,18 +244,34 @@ protected function execute(InputInterface $input, OutputInterface $cliOutput)
242244 }
243245
244246 /**
245- * Method to check if file exist.
247+ * Method to check if definition is changed from virtual to type
246248 *
247- * @param array $changedFiles
248- * @param string $sourceAfterDir
249+ * @param string $source
250+ * @param string $target
249251 * @return bool
250252 */
251- private function areFilesPresentLocally ( array $ changedFiles , string $ sourceAfterDir ): bool
253+ private function isVirtualTypeReplacedByType ( string $ source , string $ target ): bool
252254 {
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+ }
257275 }
258276 }
259277 return false ;
0 commit comments