diff --git a/src/Analyser.php b/src/Analyser.php index c262b21..ac18470 100644 --- a/src/Analyser.php +++ b/src/Analyser.php @@ -20,7 +20,7 @@ final class Analyser * @param array $files * @param Closure(Result): void $callback */ - public static function analyse(array $files, Closure $postProcessedFile, Closure $onProcessedFile, Cache $cache): void + public static function analyse(array $files, Closure $postProcessedFile, Closure $onProcessedFile, ?Cache $cache): void { $testCase = new TestCaseForTypeCoverage('dummy'); @@ -31,7 +31,7 @@ public static function analyse(array $files, Closure $postProcessedFile, Closure $filesTouched = []; foreach ($files as $file) { - if ($cache->has($file)) { + if ($cache !== null && $cache->has($file)) { [$file, $errors, $ignored] = $cache->get($file); $result = Result::fromPHPStanErrors($file, $errors, $ignored); @@ -95,7 +95,7 @@ private static function analyseChunks( TestCaseForTypeCoverage $testCase, Closure $postProcessedFile, Closure $onProcessedFile, - Cache $cache, + ?Cache $cache, bool $useAsync = true, ): void { $promises = []; @@ -123,7 +123,7 @@ private static function analyseChunks( $errors = array_values($errors); $ignored = array_values($ignored); - $cache->persist($file, [$file, $errors, $ignored]); + $cache?->persist($file, [$file, $errors, $ignored]); $result = Result::fromPHPStanErrors($file, $errors, $ignored); diff --git a/src/Plugin.php b/src/Plugin.php index ac95c34..6b7bd81 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -65,7 +65,9 @@ public function handleOriginalArguments(array $arguments): void return; } - if ($this->hasArgument('--no-cache', $arguments)) { + $noCache = $this->hasArgument('--no-cache', $arguments); + + if ($noCache) { $this->cache->flush(); } @@ -234,7 +236,7 @@ function (Result $result) use ($terminalWidth): void { HTML); }, - $this->cache, + $noCache ? null : $this->cache, ); $coverage = array_sum($totals) / count($totals);