diff --git a/package.xml b/package.xml
index 20bec01a09..72c6982cc7 100644
--- a/package.xml
+++ b/package.xml
@@ -26,6 +26,9 @@ http://pear.php.net/dtd/package-2.0.xsd">
BSD 3-Clause License
+ - Caching between runs (--cache, --no-cache and "cache" config var) (request #530)
+ - Automatic discovery of executable paths (request #571)
+ -- Thanks to Sergey Morozov for the patch
- Improved the performance of the CSS tokenizer, especially on very large CSS files (thousands of lines)
-- Thanks to Klaus Purer for the patch
- Defined tokens for lower PHP versions are now phpcs-specific string instead of ints
diff --git a/src/Config.php b/src/Config.php
index 7fd8978264..22fa1f677d 100644
--- a/src/Config.php
+++ b/src/Config.php
@@ -64,6 +64,13 @@ class Config
*/
public $interactive;
+ /**
+ * Enable the use of the file cache.
+ *
+ * @var bool
+ */
+ public $cache;
+
/**
* Display colous in output.
*
@@ -380,6 +387,7 @@ public function restoreDefaults()
$this->standards = array('PEAR');
$this->verbosity = 0;
$this->interactive = false;
+ $this->cache = false;
$this->colors = false;
$this->explain = false;
$this->local = false;
@@ -464,6 +472,11 @@ public function restoreDefaults()
$this->colors = (bool) $colors;
}
+ $cache = self::getConfigData('cache');
+ if ($cache !== null) {
+ $this->cache = (bool) $cache;
+ }
+
}//end restoreDefaults()
@@ -565,6 +578,14 @@ public function processLongArgument($arg, $pos)
$this->colors = false;
$this->overriddenDefaults['colors'] = true;
break;
+ case 'cache':
+ $this->cache = true;
+ $this->overriddenDefaults['cache'] = true;
+ break;
+ case 'no-cache':
+ $this->cache = false;
+ $this->overriddenDefaults['cache'] = true;
+ break;
case 'config-set':
if (isset($this->cliArgs[($pos + 1)]) === false
|| isset($this->cliArgs[($pos + 2)]) === false
@@ -883,7 +904,7 @@ public function printUsage()
*/
public function printPHPCSUsage()
{
- echo 'Usage: phpcs [-nwlsaepvi] [-d key[=value]] [--colors] [--no-colors]'.PHP_EOL;
+ echo 'Usage: phpcs [-nwlsaepvi] [-d key[=value]] [--cache] [--no-cache] [--colors] [--no-colors]'.PHP_EOL;
echo ' [--report=] [--report-file=] [--report-=] ...'.PHP_EOL;
echo ' [--report-width=] [--generator=] [--tab-width=]'.PHP_EOL;
echo ' [--severity=] [--error-severity=] [--warning-severity=]'.PHP_EOL;
@@ -905,6 +926,8 @@ public function printPHPCSUsage()
echo ' --version Print version information'.PHP_EOL;
echo ' --colors Use colors in output'.PHP_EOL;
echo ' --no-colors Do not use colors in output (this is the default)'.PHP_EOL;
+ echo ' --cache Cache results between runs'.PHP_EOL;
+ echo ' --no-cache Do not cache results between runs (this is the default)'.PHP_EOL;
echo ' One or more files and/or directories to check'.PHP_EOL;
echo ' The encoding of the files being checked (default is iso-8859-1)'.PHP_EOL;
echo ' A comma separated list of file extensions to check'.PHP_EOL;
diff --git a/src/Files/LocalFile.php b/src/Files/LocalFile.php
index f42558ec63..b39de23fca 100644
--- a/src/Files/LocalFile.php
+++ b/src/Files/LocalFile.php
@@ -11,6 +11,7 @@
use PHP_CodeSniffer\Ruleset;
use PHP_CodeSniffer\Config;
+use PHP_CodeSniffer\Util\Cache;
class LocalFile extends File
{
@@ -76,4 +77,46 @@ function reloadContent()
}//end reloadContent()
+ /**
+ *
+ *
+ * @return void
+ */
+ public function process()
+ {
+ $hash = $this->path.'.'.md5_file($this->path);
+ $cache = Cache::get($hash);
+ if ($cache !== false) {
+ $this->errors = $cache['errors'];
+ $this->warnings = $cache['warnings'];
+ $this->metrics = $cache['metrics'];
+ $this->errorCount = $cache['errorCount'];
+ $this->warningCount = $cache['warningCount'];
+ $this->fixableCount = $cache['fixableCount'];
+
+ if (PHP_CODESNIFFER_VERBOSITY > 0
+ || (PHP_CODESNIFFER_CBF === true && empty($this->config->files) === false)
+ ) {
+ echo "[loaded from cache]... ";
+ }
+
+ return;
+ }
+
+ parent::process();
+
+ $cache = array(
+ 'errors' => $this->errors,
+ 'warnings' => $this->warnings,
+ 'metrics' => $this->metrics,
+ 'errorCount' => $this->errorCount,
+ 'warningCount' => $this->warningCount,
+ 'fixableCount' => $this->fixableCount,
+ );
+
+ Cache::set($hash, $cache);
+
+ }//end process()
+
+
}//end class
diff --git a/src/Runner.php b/src/Runner.php
index 4107bacf6b..4891f00ad8 100644
--- a/src/Runner.php
+++ b/src/Runner.php
@@ -15,6 +15,7 @@
use PHP_CodeSniffer\Files\FileList;
use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Files\DummyFile;
+use PHP_CodeSniffer\Util\Cache;
class Runner
{
@@ -117,6 +118,7 @@ public function runPHPCBF()
$this->config->generator = null;
$this->config->explain = false;
$this->config->interactive = false;
+ $this->config->cache = false;
$this->config->showSources = false;
$this->config->reportFile = null;
$this->config->reports = array();
@@ -319,6 +321,10 @@ private function run()
$todo = new FileList($this->config, $ruleset);
$numFiles = count($todo);
+ if ($this->config->cache === true) {
+ Cache::load($this->config);
+ }
+
if (PHP_CODESNIFFER_VERBOSITY > 0) {
echo "DONE ($numFiles files in queue)".PHP_EOL;
}
@@ -492,6 +498,12 @@ private function run()
echo PHP_EOL.PHP_EOL;
}
+ if ($this->config->cache === true
+ && $this->config->stdin === false
+ ) {
+ Cache::save();
+ }
+
$ignoreWarnings = Config::getConfigData('ignore_warnings_on_exit');
$ignoreErrors = Config::getConfigData('ignore_errors_on_exit');
diff --git a/src/Standards/Squiz/Sniffs/Arrays/ArrayDeclarationSniff.php b/src/Standards/Squiz/Sniffs/Arrays/ArrayDeclarationSniff.php
index d57f15fab8..408e9ca6b3 100644
--- a/src/Standards/Squiz/Sniffs/Arrays/ArrayDeclarationSniff.php
+++ b/src/Standards/Squiz/Sniffs/Arrays/ArrayDeclarationSniff.php
@@ -827,7 +827,7 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array
}
// Skip to the end of multi-line strings.
- if (isset(PHP_CodeSniffer_Tokens::$stringTokens[$tokens[$i]['code']]) === true) {
+ if (isset(Tokens::$stringTokens[$tokens[$i]['code']]) === true) {
$i = $phpcsFile->findNext($tokens[$i]['code'], ($i + 1), null, true);
$i--;
$valueLine = $tokens[$i]['line'];