Skip to content

Commit 4e92155

Browse files
committed
Runner: bug fix - disable cache when running Diff report
This fixes the following fatal error which would occur if the `Diff` report is used in combination with caching: ``` Fatal error: Uncaught Error: Call to a member function getFixableCount() on null in path/to/PHP_CodeSniffer/src/Fixer.php:144 Stack trace: #0 path/to/PHP_CodeSniffer/src/Reports/Diff.php(73): PHP_CodeSniffer\Fixer->fixFile() #1 path/to/PHP_CodeSniffer/src/Reporter.php(285): PHP_CodeSniffer\Reports\Diff->generateFileReport(Array, Object(PHP_CodeSniffer\Files\LocalFile), true, 150) #2 path/to/PHP_CodeSniffer/src/Runner.php(659): PHP_CodeSniffer\Reporter->cacheFileReport(Object(PHP_CodeSniffer\Files\LocalFile)) #3 path/to/PHP_CodeSniffer/src/Runner.php(400): PHP_CodeSniffer\Runner->processFile(Object(PHP_CodeSniffer\Files\LocalFile)) #4 path/to/PHP_CodeSniffer/src/Runner.php(119): PHP_CodeSniffer\Runner->run() #5 path/to/PHP_CodeSniffer/bin/phpcs(30): PHP_CodeSniffer\Runner->runPHPCS() #6 {main} thrown in path/to/PHP_CodeSniffer/src/Fixer.php on line 144 ```
1 parent 50f03b3 commit 4e92155

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/Runner.php

+7
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,13 @@ public function runPHPCS()
117117
$this->config->cache = false;
118118
}
119119

120+
// Disable caching if the Diff report has been requested as it will run
121+
// the fixer and the fixer doesn't use/support the cache functionality.
122+
$requestedReports = array_change_key_case($this->config->reports, CASE_LOWER);
123+
if (array_key_exists('diff', $requestedReports) === true) {
124+
$this->config->cache = false;
125+
}
126+
120127
$numErrors = $this->run();
121128

122129
// Print all the reports for this run.

0 commit comments

Comments
 (0)