From 09be5b23df30cefce3f5840231750f41af1c0f3e Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sat, 15 Mar 2025 11:26:57 +0000 Subject: [PATCH] Updated Rector to commit b96adc590b9939e14a2abfdda3dd05f5bb1824e1 https://github.com/rectorphp/rector-src/commit/b96adc590b9939e14a2abfdda3dd05f5bb1824e1 [Performance] Move realpath() collection early on FilesystemTweaker (part 1) (#6783) --- src/Application/VersionResolver.php | 4 ++-- src/FileSystem/FileAndDirectoryFilter.php | 4 ++-- src/FileSystem/FilesFinder.php | 1 - src/FileSystem/FilesystemTweaker.php | 20 ++++++++++++++++++-- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index e9138c6daf9..b73472792c8 100644 --- a/src/Application/VersionResolver.php +++ b/src/Application/VersionResolver.php @@ -19,12 +19,12 @@ final class VersionResolver * @api * @var string */ - public const PACKAGE_VERSION = '217026caf877c60eb7a7fd61b5b16d9a642f1662'; + public const PACKAGE_VERSION = 'b96adc590b9939e14a2abfdda3dd05f5bb1824e1'; /** * @api * @var string */ - public const RELEASE_DATE = '2025-03-14 23:18:19'; + public const RELEASE_DATE = '2025-03-15 12:24:23'; /** * @var int */ diff --git a/src/FileSystem/FileAndDirectoryFilter.php b/src/FileSystem/FileAndDirectoryFilter.php index a7c017ea74b..caccb21d05b 100644 --- a/src/FileSystem/FileAndDirectoryFilter.php +++ b/src/FileSystem/FileAndDirectoryFilter.php @@ -14,7 +14,7 @@ final class FileAndDirectoryFilter */ public function filterDirectories(array $filesAndDirectories) : array { - $directories = \array_filter($filesAndDirectories, static fn(string $path): bool => \is_dir($path) && \realpath($path) !== \false); + $directories = \array_filter($filesAndDirectories, static fn(string $path): bool => \is_dir($path)); return \array_values($directories); } /** @@ -23,7 +23,7 @@ final class FileAndDirectoryFilter */ public function filterFiles(array $filesAndDirectories) : array { - $files = \array_filter($filesAndDirectories, static fn(string $path): bool => \is_file($path) && \realpath($path) !== \false); + $files = \array_filter($filesAndDirectories, static fn(string $path): bool => \is_file($path)); return \array_values($files); } } diff --git a/src/FileSystem/FilesFinder.php b/src/FileSystem/FilesFinder.php index 47eb9140b32..057d283a77b 100644 --- a/src/FileSystem/FilesFinder.php +++ b/src/FileSystem/FilesFinder.php @@ -59,7 +59,6 @@ final class FilesFinder $filesAndDirectories = $this->filesystemTweaker->resolveWithFnmatch($source); // filtering files in files collection $filteredFilePaths = $this->fileAndDirectoryFilter->filterFiles($filesAndDirectories); - $filteredFilePaths = \array_map(fn(string $filePath): string => \realpath($filePath), $filteredFilePaths); $filteredFilePaths = \array_filter($filteredFilePaths, fn(string $filePath): bool => !$this->pathSkipper->shouldSkip($filePath)); // fallback append `.php` to be used for both $filteredFilePaths and $filteredFilePathsInDirectories $hasOnlySuffix = $onlySuffix !== null && $onlySuffix !== ''; diff --git a/src/FileSystem/FilesystemTweaker.php b/src/FileSystem/FilesystemTweaker.php index d351599c44e..473a2dea06e 100644 --- a/src/FileSystem/FilesystemTweaker.php +++ b/src/FileSystem/FilesystemTweaker.php @@ -18,13 +18,29 @@ final class FilesystemTweaker foreach ($paths as $path) { if (\strpos($path, '*') !== \false) { $foundPaths = $this->foundInGlob($path); - $absolutePathsFound = \array_merge($absolutePathsFound, $foundPaths); + $absolutePathsFound = $this->appendPaths($foundPaths, $absolutePathsFound); } else { - $absolutePathsFound[] = $path; + $absolutePathsFound = $this->appendPaths([$path], $absolutePathsFound); } } return $absolutePathsFound; } + /** + * @param string[] $foundPaths + * @param string[] $absolutePathsFound + * @return string[] + */ + private function appendPaths(array $foundPaths, array $absolutePathsFound) : array + { + foreach ($foundPaths as $foundPath) { + $foundPath = \realpath($foundPath); + if ($foundPath === \false) { + continue; + } + $absolutePathsFound[] = $foundPath; + } + return $absolutePathsFound; + } /** * @return string[] */