From d457f7c93c4c049cf880040334c535388281de9c Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Wed, 7 Oct 2026 10:37:28 +0200 Subject: [PATCH] Fold Fnmatcher and RealpathMatcher into FileInfoMatcher --- src/Skipper/Fnmatcher.php | 26 ------------ src/Skipper/Matcher/FileInfoMatcher.php | 55 ++++++++++++++++++++++--- src/Skipper/RealpathMatcher.php | 42 ------------------- 3 files changed, 49 insertions(+), 74 deletions(-) delete mode 100644 src/Skipper/Fnmatcher.php delete mode 100644 src/Skipper/RealpathMatcher.php diff --git a/src/Skipper/Fnmatcher.php b/src/Skipper/Fnmatcher.php deleted file mode 100644 index a6e7cf08c79..00000000000 --- a/src/Skipper/Fnmatcher.php +++ /dev/null @@ -1,26 +0,0 @@ -normalizePath($matchingPath); - $normalizedFilePath = $this->normalizePath($filePath); - - if (fnmatch($normalizedMatchingPath, $normalizedFilePath)) { - return true; - } - - // in case of relative compare - return fnmatch('*/' . $normalizedMatchingPath, $normalizedFilePath); - } - - private function normalizePath(string $path): string - { - return str_replace('\\', '/', $path); - } -} diff --git a/src/Skipper/Matcher/FileInfoMatcher.php b/src/Skipper/Matcher/FileInfoMatcher.php index 58f13454cda..f561b8798b7 100644 --- a/src/Skipper/Matcher/FileInfoMatcher.php +++ b/src/Skipper/Matcher/FileInfoMatcher.php @@ -6,15 +6,11 @@ use SplFileInfo; use Symplify\EasyCodingStandard\Skipper\FileSystem\FnMatchPathNormalizer; -use Symplify\EasyCodingStandard\Skipper\Fnmatcher; -use Symplify\EasyCodingStandard\Skipper\RealpathMatcher; final readonly class FileInfoMatcher { public function __construct( private FnMatchPathNormalizer $fnMatchPathNormalizer, - private Fnmatcher $fnmatcher, - private RealpathMatcher $realpathMatcher, ) { } @@ -54,10 +50,57 @@ private function doesFileInfoMatchPattern(SplFileInfo|string $file, string $igno return true; } - if ($this->fnmatcher->match($ignoredPath, $filePath)) { + if ($this->matchesFnmatch($ignoredPath, $filePath)) { return true; } - return $this->realpathMatcher->match($ignoredPath, $filePath); + return $this->matchesRealpath($ignoredPath, $filePath); + } + + private function matchesFnmatch(string $matchingPath, string $filePath): bool + { + $normalizedMatchingPath = $this->normalizePath($matchingPath); + $normalizedFilePath = $this->normalizePath($filePath); + + if (fnmatch($normalizedMatchingPath, $normalizedFilePath)) { + return true; + } + + // in case of relative compare + return fnmatch('*/' . $normalizedMatchingPath, $normalizedFilePath); + } + + private function matchesRealpath(string $matchingPath, string $filePath): bool + { + /** @var non-empty-string|false $realPathMatchingPath */ + $realPathMatchingPath = realpath($matchingPath); + if ($realPathMatchingPath === false) { + return false; + } + + $realpathFilePath = realpath($filePath); + if ($realpathFilePath === false) { + return false; + } + + $normalizedMatchingPath = $this->normalizePath($realPathMatchingPath); + $normalizedFilePath = $this->normalizePath($realpathFilePath); + + // skip define direct path + if (is_file($normalizedMatchingPath)) { + return $normalizedMatchingPath === $normalizedFilePath; + } + + // ensure add / suffix to ensure no same prefix directory + if (is_dir($normalizedMatchingPath)) { + $normalizedMatchingPath = rtrim($normalizedMatchingPath, '/') . '/'; + } + + return str_starts_with($normalizedFilePath, $normalizedMatchingPath); + } + + private function normalizePath(string $path): string + { + return str_replace('\\', '/', $path); } } diff --git a/src/Skipper/RealpathMatcher.php b/src/Skipper/RealpathMatcher.php deleted file mode 100644 index d99d1ebc5c4..00000000000 --- a/src/Skipper/RealpathMatcher.php +++ /dev/null @@ -1,42 +0,0 @@ -normalizePath($realPathMatchingPath); - $normalizedFilePath = $this->normalizePath($realpathFilePath); - - // skip define direct path - if (is_file($normalizedMatchingPath)) { - return $normalizedMatchingPath === $normalizedFilePath; - } - - // ensure add / suffix to ensure no same prefix directory - if (is_dir($normalizedMatchingPath)) { - $normalizedMatchingPath = rtrim($normalizedMatchingPath, '/') . '/'; - } - - return str_starts_with($normalizedFilePath, $normalizedMatchingPath); - } - - private function normalizePath(string $path): string - { - return str_replace('\\', '/', $path); - } -}