Skip to content

Commit ef0dff1

Browse files
authored
Remove unnecessary loop in FileExcluder->isExcludedFromAnalysing() (#5886)
1 parent 618e671 commit ef0dff1

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

src/File/FileExcluder.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ final class FileExcluder
2929
/**
3030
* Files to exclude from analysing
3131
*
32-
* @var string[]
32+
* @var array<string, true>
3333
*/
3434
private array $literalAnalyseFilesExcludes = [];
3535

@@ -63,7 +63,7 @@ public function __construct(
6363
$this->fnmatchAnalyseExcludes[] = $normalized;
6464
} else {
6565
if (is_file($normalized)) {
66-
$this->literalAnalyseFilesExcludes[] = $normalized;
66+
$this->literalAnalyseFilesExcludes[$normalized] = true;
6767
} elseif (is_dir($normalized)) {
6868
if (!$trailingDirSeparator) {
6969
$normalized .= DIRECTORY_SEPARATOR;
@@ -86,16 +86,14 @@ public function isExcludedFromAnalysing(string $file): bool
8686
{
8787
$file = $this->fileHelper->normalizePath($file);
8888

89+
if (isset($this->literalAnalyseFilesExcludes[$file])) {
90+
return true;
91+
}
8992
foreach ($this->literalAnalyseDirectoryExcludes as $exclude) {
9093
if (str_starts_with($file, $exclude)) {
9194
return true;
9295
}
9396
}
94-
foreach ($this->literalAnalyseFilesExcludes as $exclude) {
95-
if ($file === $exclude) {
96-
return true;
97-
}
98-
}
9997
foreach ($this->fnmatchAnalyseExcludes as $exclude) {
10098
if (fnmatch($exclude, $file, $this->fnmatchFlags)) {
10199
return true;

0 commit comments

Comments
 (0)