Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow phpcbf to use the cache #481

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 21 additions & 16 deletions src/Files/LocalFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ 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 || $cache['fixableCount'] === 0)
) {
// We can't filter metrics, so just load all of them.
$this->metrics = $cache['metrics'];

Expand All @@ -112,9 +115,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 +130,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