Skip to content

Commit bcb11a7

Browse files
committed
Updated Rector to commit a77b00d92bb3e62063ba56c63f42502e6fe6f316
rectorphp/rector-src@a77b00d Skip files with short <?= PHP tag as leads to invalid changes (#6068)
1 parent c09e34b commit bcb11a7

4 files changed

Lines changed: 20 additions & 11 deletions

File tree

src/Application/VersionResolver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ final class VersionResolver
1919
* @api
2020
* @var string
2121
*/
22-
public const PACKAGE_VERSION = '1865d51f2f5e5045ac3b5e52fc45d79d8f36636b';
22+
public const PACKAGE_VERSION = 'a77b00d92bb3e62063ba56c63f42502e6fe6f316';
2323
/**
2424
* @api
2525
* @var string
2626
*/
27-
public const RELEASE_DATE = '2024-06-28 16:03:51';
27+
public const RELEASE_DATE = '2024-06-28 17:11:57';
2828
/**
2929
* @var int
3030
*/

src/Caching/UnchangedFilesFilter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function __construct(ChangedFilesDetector $changedFilesDetector)
1919
* @param string[] $filePaths
2020
* @return string[]
2121
*/
22-
public function filterFileInfos(array $filePaths) : array
22+
public function filterFilePaths(array $filePaths) : array
2323
{
2424
$changedFileInfos = [];
2525
foreach ($filePaths as $filePath) {

src/FileSystem/FilesFinder.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

src/PostRector/Rector/NameImportingPostRector.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,7 @@ private function shouldSkipFileWithoutNamespace(File $file) : bool
119119
return \false;
120120
}
121121
$currentStmt = \current($firstStmt->stmts);
122-
if ($currentStmt instanceof InlineHTML || $currentStmt === \false) {
123-
return \true;
124-
}
125-
$oldTokens = $file->getOldTokens();
126-
$tokenStartPos = $currentStmt->getStartTokenPos();
127-
return isset($oldTokens[$tokenStartPos][1]) && $oldTokens[$tokenStartPos][1] === '<?=';
122+
return $currentStmt instanceof InlineHTML || $currentStmt === \false;
128123
}
129124
private function processNodeName(FullyQualified $fullyQualified, File $file) : ?Node
130125
{

0 commit comments

Comments
 (0)