From 8ca81dca8cf5f34f1eb2c567ee145ea688507b9c Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 12 Mar 2026 10:35:38 +0100 Subject: [PATCH] fix: make --no-cache truly bypass caching instead of just flushing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously --no-cache only called Cache::flush() then continued to read from and write to the cache file. This is misleading — users expect --no-cache to mean no caching at all. Now --no-cache flushes the existing cache AND passes null instead of the Cache instance to the Analyser, so no cache reads or writes occur during the run. --- src/Analyser.php | 8 ++++---- src/Plugin.php | 6 ++++-- 2 files changed, 8 insertions(+), 6 deletions(-) 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);