From d52c4b1de105ada5d4f33b23314da07b1f41e173 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Tue, 16 Jun 2026 15:04:20 +0200 Subject: [PATCH 1/2] Remove unnecessary loop in FileExcluder->isExcludedFromAnalysing() --- src/File/FileExcluder.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/File/FileExcluder.php b/src/File/FileExcluder.php index e9df089e50..84810107a2 100644 --- a/src/File/FileExcluder.php +++ b/src/File/FileExcluder.php @@ -29,7 +29,7 @@ final class FileExcluder /** * Files to exclude from analysing * - * @var string[] + * @var array */ private array $literalAnalyseFilesExcludes = []; @@ -63,7 +63,7 @@ public function __construct( $this->fnmatchAnalyseExcludes[] = $normalized; } else { if (is_file($normalized)) { - $this->literalAnalyseFilesExcludes[] = $normalized; + $this->literalAnalyseFilesExcludes[$normalized] = true; } elseif (is_dir($normalized)) { if (!$trailingDirSeparator) { $normalized .= DIRECTORY_SEPARATOR; @@ -91,10 +91,8 @@ public function isExcludedFromAnalysing(string $file): bool return true; } } - foreach ($this->literalAnalyseFilesExcludes as $exclude) { - if ($file === $exclude) { - return true; - } + if (isset($this->literalAnalyseFilesExcludes[$file])) { + return true; } foreach ($this->fnmatchAnalyseExcludes as $exclude) { if (fnmatch($exclude, $file, $this->fnmatchFlags)) { From 8223c0655420d519910723dc0063cd97c16082b4 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Tue, 16 Jun 2026 15:06:44 +0200 Subject: [PATCH 2/2] cheap check first --- src/File/FileExcluder.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/File/FileExcluder.php b/src/File/FileExcluder.php index 84810107a2..9e6266fc29 100644 --- a/src/File/FileExcluder.php +++ b/src/File/FileExcluder.php @@ -86,14 +86,14 @@ public function isExcludedFromAnalysing(string $file): bool { $file = $this->fileHelper->normalizePath($file); + if (isset($this->literalAnalyseFilesExcludes[$file])) { + return true; + } foreach ($this->literalAnalyseDirectoryExcludes as $exclude) { if (str_starts_with($file, $exclude)) { return true; } } - if (isset($this->literalAnalyseFilesExcludes[$file])) { - return true; - } foreach ($this->fnmatchAnalyseExcludes as $exclude) { if (fnmatch($exclude, $file, $this->fnmatchFlags)) { return true;