@@ -31,6 +31,11 @@ final class FilesFinder
3131 * @var \Rector\Skipper\Skipper\PathSkipper
3232 */
3333 private $ pathSkipper ;
34+ /**
35+ * @var string
36+ * @see https://regex101.com/r/3NwDLo/1
37+ */
38+ private const OPEN_SHORTTAG_REGEX = '#^ \\< \\?=# ' ;
3439 public function __construct (\Rector \FileSystem \FilesystemTweaker $ filesystemTweaker , UnchangedFilesFilter $ unchangedFilesFilter , \Rector \FileSystem \FileAndDirectoryFilter $ fileAndDirectoryFilter , PathSkipper $ pathSkipper )
3540 {
3641 $ this ->filesystemTweaker = $ filesystemTweaker ;
@@ -47,6 +52,15 @@ public function findInDirectoriesAndFiles(array $source, array $suffixes = [], b
4752 {
4853 $ filesAndDirectories = $ this ->filesystemTweaker ->resolveWithFnmatch ($ source );
4954 $ files = $ this ->fileAndDirectoryFilter ->filterFiles ($ filesAndDirectories );
55+ // exclude short "<?=" tags as lead to invalid changes
56+ $ files = \array_filter ($ files , static function (string $ file ) : bool {
57+ // @ on purpose to deal with broken symlinks
58+ $ fileContents = @\file_get_contents ($ file );
59+ if (!\is_string ($ fileContents )) {
60+ return \true;
61+ }
62+ return \strncmp ($ fileContents , '<?= ' , \strlen ('<?= ' )) !== 0 ;
63+ });
5064 $ filteredFilePaths = \array_filter ($ files , function (string $ filePath ) : bool {
5165 return !$ this ->pathSkipper ->shouldSkip ($ filePath );
5266 });
@@ -60,7 +74,7 @@ public function findInDirectoriesAndFiles(array $source, array $suffixes = [], b
6074 $ directories = $ this ->fileAndDirectoryFilter ->filterDirectories ($ filesAndDirectories );
6175 $ filteredFilePathsInDirectories = $ this ->findInDirectories ($ directories , $ suffixes , $ sortByName );
6276 $ filePaths = \array_merge ($ filteredFilePaths , $ filteredFilePathsInDirectories );
63- return $ this ->unchangedFilesFilter ->filterFileInfos ($ filePaths );
77+ return $ this ->unchangedFilesFilter ->filterFilePaths ($ filePaths );
6478 }
6579 /**
6680 * @param string[] $directories
@@ -72,7 +86,7 @@ private function findInDirectories(array $directories, array $suffixes, bool $so
7286 if ($ directories === []) {
7387 return [];
7488 }
75- $ finder = Finder::create ()->files ()->size ('> 0 ' )->in ($ directories );
89+ $ finder = Finder::create ()->files ()->size ('> 0 ' )->notContains ( self :: OPEN_SHORTTAG_REGEX )-> in ($ directories );
7690 if ($ sortByName ) {
7791 $ finder ->sortByName ();
7892 }
0 commit comments