From 5cae93b05938aa5041af9955c3788685ddfa859d Mon Sep 17 00:00:00 2001 From: nuno maduro Date: Sat, 2 May 2026 17:37:56 +0100 Subject: [PATCH] wip --- src/Plugins/Tia/SourceScope.php | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/Plugins/Tia/SourceScope.php b/src/Plugins/Tia/SourceScope.php index 4025f487..68e060d0 100644 --- a/src/Plugins/Tia/SourceScope.php +++ b/src/Plugins/Tia/SourceScope.php @@ -10,8 +10,12 @@ use Throwable; /** * @internal */ -final readonly class SourceScope +final class SourceScope { + /** @var array */ + private array $containsCache = []; + + private const array TOP_LEVEL_NOISE = [ 'vendor', 'node_modules', @@ -35,8 +39,8 @@ final readonly class SourceScope * @param list $excludes Absolute, normalised directory paths. */ public function __construct( - private array $includes, - private array $excludes, + private readonly array $includes, + private readonly array $excludes, ) {} public static function fromProjectRoot(string $projectRoot): self @@ -99,23 +103,27 @@ final readonly class SourceScope public function contains(string $absoluteFile): bool { + if (isset($this->containsCache[$absoluteFile])) { + return $this->containsCache[$absoluteFile]; + } + $real = @realpath($absoluteFile); $candidate = $real === false ? $absoluteFile : $real; $candidate = self::normalise($candidate); foreach ($this->excludes as $excluded) { if ($this->startsWithDir($candidate, $excluded)) { - return false; + return $this->containsCache[$absoluteFile] = false; } } foreach ($this->includes as $included) { if ($this->startsWithDir($candidate, $included)) { - return true; + return $this->containsCache[$absoluteFile] = true; } } - return false; + return $this->containsCache[$absoluteFile] = false; } /**