Skip to content

Commit

Permalink
Merge 0a4212c into 4fd52f7
Browse files Browse the repository at this point in the history
  • Loading branch information
fredden committed May 8, 2024
2 parents 4fd52f7 + 0a4212c commit 51feab3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 23 deletions.
35 changes: 19 additions & 16 deletions src/Files/LocalFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ public function process()
$hash = md5_file($this->path);
$hash .= fileperms($this->path);
$cache = Cache::get($this->path);
if ($cache !== false && $cache['hash'] === $hash) {

if ($cache !== false && $cache['hash'] === $hash && (PHP_CODESNIFFER_CBF === false || (PHP_CODESNIFFER_CBF === true && $cache['fixableCount'] === 0))) {
// We can't filter metrics, so just load all of them.
$this->metrics = $cache['metrics'];

Expand All @@ -112,9 +113,7 @@ public function process()
$this->fixableCount = $cache['fixableCount'];
}

if (PHP_CODESNIFFER_VERBOSITY > 0
|| (PHP_CODESNIFFER_CBF === true && empty($this->config->files) === false)
) {
if (PHP_CODESNIFFER_VERBOSITY > 0) {
echo "[loaded from cache]... ";
}

Expand All @@ -129,18 +128,22 @@ public function process()

parent::process();

$cache = [
'hash' => $hash,
'errors' => $this->errors,
'warnings' => $this->warnings,
'metrics' => $this->metrics,
'errorCount' => $this->errorCount,
'warningCount' => $this->warningCount,
'fixableCount' => $this->fixableCount,
'numTokens' => $this->numTokens,
];

Cache::set($this->path, $cache);
if (PHP_CODESNIFFER_CBF === false || $this->fixedCount === 0) {
$cache = [
'hash' => $hash,
'errors' => $this->errors,
'warnings' => $this->warnings,
'metrics' => $this->metrics,
'errorCount' => $this->errorCount,
'warningCount' => $this->warningCount,
'fixableCount' => $this->fixableCount,
'numTokens' => $this->numTokens,
];

Cache::set($this->path, $cache);
} else {
Cache::set($this->path, false);
}

// During caching, we don't filter out errors in any way, so
// we need to do that manually now by replaying them.
Expand Down
2 changes: 2 additions & 0 deletions src/Fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ public function fixFile()
return false;
}

$this->currentFile->disableCaching();

$this->enabled = true;

$this->loops = 0;
Expand Down
12 changes: 5 additions & 7 deletions src/Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,11 @@ public function runPHPCBF()
}

// Override some of the command line settings that might break the fixes.
$this->config->generator = null;
$this->config->explain = false;
$this->config->interactive = false;
$this->config->cache = false;
$this->config->showSources = false;
$this->config->recordErrors = false;
$this->config->reportFile = null;
$this->config->generator = null;
$this->config->explain = false;
$this->config->interactive = false;
$this->config->showSources = false;
$this->config->reportFile = null;

// Only use the "Cbf" report, but allow for the Performance report as well.
$originalReports = array_change_key_case($this->config->reports, CASE_LOWER);
Expand Down

0 comments on commit 51feab3

Please sign in to comment.