mirror of
https://github.com/danog/psalm.git
synced 2025-01-21 21:31:13 +01:00
Don’t get statements from cache if file hasn’t changed
This commit is contained in:
parent
58be09d36b
commit
724e72af58
@ -14,11 +14,21 @@ class TemplateScanner extends Psalm\Scanner\FileScanner
|
||||
/**
|
||||
* @param array<mixed, PhpParser\Node> $stmts
|
||||
* @param bool $storage_from_cache
|
||||
* @param bool $debug_output
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function scan(Codebase $codebase, array $stmts, FileStorage $file_storage, $storage_from_cache = false)
|
||||
{
|
||||
public function scan(
|
||||
Codebase $codebase,
|
||||
FileStorage $file_storage,
|
||||
$storage_from_cache = false,
|
||||
$debug_output = false
|
||||
) {
|
||||
$stmts = $codebase->statements_provider->getStatementsForFile(
|
||||
$file_storage->file_path,
|
||||
$debug_output
|
||||
);
|
||||
|
||||
if (empty($stmts)) {
|
||||
return;
|
||||
}
|
||||
@ -52,6 +62,6 @@ class TemplateScanner extends Psalm\Scanner\FileScanner
|
||||
|
||||
$codebase->scanner->queueClassLikeForScanning(self::VIEW_CLASS, $this->file_path);
|
||||
|
||||
parent::scan($codebase, $stmts, $file_storage);
|
||||
parent::scan($codebase, $file_storage, $storage_from_cache, $debug_output);
|
||||
}
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ class Codebase
|
||||
/**
|
||||
* @var StatementsProvider
|
||||
*/
|
||||
private $statements_provider;
|
||||
public $statements_provider;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
@ -148,7 +148,6 @@ class Codebase
|
||||
$config,
|
||||
$file_storage_provider,
|
||||
$file_provider,
|
||||
$statements_provider,
|
||||
$this->reflection,
|
||||
$debug_output
|
||||
);
|
||||
|
@ -6,7 +6,6 @@ use Psalm\Config;
|
||||
use Psalm\Provider\FileProvider;
|
||||
use Psalm\Provider\FileReferenceProvider;
|
||||
use Psalm\Provider\FileStorageProvider;
|
||||
use Psalm\Provider\StatementsProvider;
|
||||
use Psalm\Scanner\FileScanner;
|
||||
|
||||
/**
|
||||
@ -91,11 +90,6 @@ class Scanner
|
||||
*/
|
||||
private $file_provider;
|
||||
|
||||
/**
|
||||
* @var StatementsProvider
|
||||
*/
|
||||
private $statements_provider;
|
||||
|
||||
/**
|
||||
* @param bool $debug_output
|
||||
*/
|
||||
@ -104,7 +98,6 @@ class Scanner
|
||||
Config $config,
|
||||
FileStorageProvider $file_storage_provider,
|
||||
FileProvider $file_provider,
|
||||
StatementsProvider $statements_provider,
|
||||
Reflection $reflection,
|
||||
$debug_output
|
||||
) {
|
||||
@ -113,7 +106,6 @@ class Scanner
|
||||
$this->file_provider = $file_provider;
|
||||
$this->debug_output = $debug_output;
|
||||
$this->file_storage_provider = $file_storage_provider;
|
||||
$this->statements_provider = $statements_provider;
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
@ -283,26 +275,15 @@ class Scanner
|
||||
$this->file_storage_provider->create($file_path);
|
||||
}
|
||||
|
||||
if ($this->debug_output) {
|
||||
if (isset($this->files_to_deep_scan[$file_path])) {
|
||||
echo 'Deep scanning ' . $file_path . PHP_EOL;
|
||||
} else {
|
||||
echo 'Scanning ' . $file_path . PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
$this->scanned_files[$file_path] = true;
|
||||
|
||||
$file_storage = $this->file_storage_provider->get($file_path);
|
||||
|
||||
$file_scanner->scan(
|
||||
$this->codebase,
|
||||
$this->statements_provider->getStatementsForFile(
|
||||
$file_path,
|
||||
$this->debug_output
|
||||
),
|
||||
$file_storage,
|
||||
$from_cache
|
||||
$from_cache,
|
||||
$this->debug_output
|
||||
);
|
||||
|
||||
$file_storage->deep_scan = $will_analyze;
|
||||
|
@ -645,7 +645,6 @@ class Config
|
||||
$file_to_scan = new FileScanner($path, $this->shortenFileName($path), false);
|
||||
$file_to_scan->scan(
|
||||
$codebase,
|
||||
$codebase->getStatementsForFile($path),
|
||||
$file_storage
|
||||
);
|
||||
|
||||
@ -805,7 +804,6 @@ class Config
|
||||
$file_to_scan = new FileScanner($stub_file_path, $this->shortenFileName($stub_file_path), false);
|
||||
$file_to_scan->scan(
|
||||
$codebase,
|
||||
$codebase->getStatementsForFile($stub_file_path),
|
||||
$file_storage
|
||||
);
|
||||
}
|
||||
@ -906,7 +904,6 @@ class Config
|
||||
$file_to_scan = new \Psalm\Scanner\FileScanner($file_path, $this->shortenFileName($file_path), false);
|
||||
$file_to_scan->scan(
|
||||
$codebase,
|
||||
$codebase->getStatementsForFile($file_path),
|
||||
$file_storage
|
||||
);
|
||||
}
|
||||
|
@ -108,10 +108,9 @@ class ClassLikeStorageCacheProvider
|
||||
if ($this->config->use_igbinary) {
|
||||
/** @var ClassLikeStorage */
|
||||
return igbinary_unserialize((string)file_get_contents($cache_location)) ?: null;
|
||||
} else {
|
||||
/** @var ClassLikeStorage */
|
||||
return unserialize((string)file_get_contents($cache_location)) ?: null;
|
||||
}
|
||||
/** @var ClassLikeStorage */
|
||||
return unserialize((string)file_get_contents($cache_location)) ?: null;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
@ -62,7 +62,7 @@ class ClassLikeStorageProvider
|
||||
$fq_classlike_name_lc = strtolower($fq_classlike_name);
|
||||
|
||||
if (isset(self::$storage[$fq_classlike_name_lc])) {
|
||||
throw new \UnexpectedValueException('Already exists');
|
||||
return self::$storage[$fq_classlike_name_lc];
|
||||
}
|
||||
|
||||
self::$storage[$fq_classlike_name_lc]
|
||||
|
@ -106,10 +106,9 @@ class FileStorageCacheProvider
|
||||
if ($this->config->use_igbinary) {
|
||||
/** @var FileStorage */
|
||||
return igbinary_unserialize((string)file_get_contents($cache_location)) ?: null;
|
||||
} else {
|
||||
/** @var FileStorage */
|
||||
return unserialize((string)file_get_contents($cache_location)) ?: null;
|
||||
}
|
||||
/** @var FileStorage */
|
||||
return unserialize((string)file_get_contents($cache_location)) ?: null;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
@ -79,9 +79,9 @@ class FileStorageProvider
|
||||
*/
|
||||
public function create($file_path)
|
||||
{
|
||||
$file_path = strtolower($file_path);
|
||||
$file_path_lc = strtolower($file_path);
|
||||
|
||||
self::$storage[$file_path] = $storage = new FileStorage();
|
||||
self::$storage[$file_path_lc] = $storage = new FileStorage();
|
||||
|
||||
$storage->file_path = $file_path;
|
||||
|
||||
|
@ -40,15 +40,33 @@ class FileScanner implements FileSource
|
||||
/**
|
||||
* @param array<mixed, PhpParser\Node> $stmts
|
||||
* @param bool $storage_from_cache
|
||||
* @param bool $debug_output
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function scan(Codebase $codebase, array $stmts, FileStorage $file_storage, $storage_from_cache = false)
|
||||
{
|
||||
public function scan(
|
||||
Codebase $codebase,
|
||||
FileStorage $file_storage,
|
||||
$storage_from_cache = false,
|
||||
$debug_output = false
|
||||
) {
|
||||
if ((!$this->will_analyze || $file_storage->deep_scan) && $storage_from_cache) {
|
||||
return;
|
||||
}
|
||||
|
||||
$stmts = $codebase->statements_provider->getStatementsForFile(
|
||||
$file_storage->file_path,
|
||||
$debug_output
|
||||
);
|
||||
|
||||
if ($debug_output) {
|
||||
if ($this->will_analyze) {
|
||||
echo 'Deep scanning ' . $file_storage->file_path . PHP_EOL;
|
||||
} else {
|
||||
echo 'Scanning ' . $file_storage->file_path . PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
$traverser = new NodeTraverser();
|
||||
$traverser->addVisitor(new DependencyFinderVisitor($codebase, $file_storage, $this));
|
||||
$traverser->traverse($stmts);
|
||||
|
Loading…
x
Reference in New Issue
Block a user