1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00

Merge branch 'master' into psr2-fixes

This commit is contained in:
Jon Ursenbach 2016-11-04 20:07:21 -04:00
commit 653f509e80
5 changed files with 50 additions and 36 deletions

View File

@ -51,9 +51,6 @@ $show_info = isset($options['show-info'])
: true;
$is_diff = isset($options['diff']);
// set the cache directory for the file checker
FileChecker::setCacheDir('/var/tmp/php-parser');
// initialise custom config, if passed
if ($path_to_config) {
ProjectChecker::setConfigXML($path_to_config);

View File

@ -1,5 +1,5 @@
<?xml version="1.0"?>
<codeinspector
<psalm
name="Example Psalm config with recommended defaults"
stopOnFirstError="false"
useDocblockTypes="true"
@ -19,4 +19,4 @@
<PossiblyUndefinedVariable errorLevel="info">
</issueHandler>
</codeinspector>
</psalm>

View File

@ -1,5 +1,5 @@
<?xml version="1.0"?>
<codeinspector
<psalm
name="Psalm for Psalm"
stopOnFirstError="false"
useDocblockTypes="true"
@ -16,4 +16,4 @@
</ForbiddenCode>
</issueHandler>
</codeinspector>
</psalm>

View File

@ -52,11 +52,6 @@ class FileChecker implements StatementsSource
*/
protected $suppressed_issues = [];
/**
* @var string|null
*/
protected static $cache_dir = null;
/**
* @var array<string, static>
*/
@ -329,10 +324,12 @@ class FileChecker implements StatementsSource
$cache_location = null;
if (self::$cache_dir) {
$cache_directory = Config::getInstance()->getCacheDirectory();
if ($cache_directory) {
$key = md5($contents);
$cache_location = self::$cache_dir . '/' . $key;
$cache_location = $cache_directory . '/' . $key;
if (is_readable($cache_location)) {
$stmts = unserialize((string) file_get_contents($cache_location));
@ -346,12 +343,12 @@ class FileChecker implements StatementsSource
$stmts = $parser->parse($contents);
}
if (self::$cache_dir && $cache_location) {
if ($cache_directory && $cache_location) {
if ($from_cache) {
touch($cache_location);
} else {
if (!file_exists(self::$cache_dir)) {
mkdir(self::$cache_dir);
if (!file_exists($cache_directory)) {
mkdir($cache_directory);
}
file_put_contents($cache_location, serialize($stmts));
@ -370,8 +367,10 @@ class FileChecker implements StatementsSource
*/
public static function loadReferenceCache()
{
if (self::$cache_dir) {
$cache_location = self::$cache_dir . '/' . self::REFERENCE_CACHE_NAME;
$cache_directory = Config::getInstance()->getCacheDirectory();
if ($cache_directory) {
$cache_location = $cache_directory . '/' . self::REFERENCE_CACHE_NAME;
if (is_readable($cache_location)) {
self::$file_references = unserialize((string) file_get_contents($cache_location));
@ -387,8 +386,10 @@ class FileChecker implements StatementsSource
*/
public static function updateReferenceCache()
{
if (self::$cache_dir) {
$cache_location = self::$cache_dir . '/' . self::REFERENCE_CACHE_NAME;
$cache_directory = Config::getInstance()->getCacheDirectory();
if ($cache_directory) {
$cache_location = $cache_directory . '/' . self::REFERENCE_CACHE_NAME;
foreach (self::$files_checked as $file => $_) {
$all_file_references = array_unique(
@ -415,15 +416,6 @@ class FileChecker implements StatementsSource
}
}
/**
* @param string $cache_dir
* @return void
*/
public static function setCacheDir($cache_dir)
{
self::$cache_dir = $cache_dir;
}
/**
* @return null
*/
@ -676,7 +668,9 @@ class FileChecker implements StatementsSource
*/
public static function canDiffFiles()
{
return self::$cache_dir && file_exists(self::$cache_dir . '/' . self::GOOD_RUN_NAME);
$cache_directory = Config::getInstance()->getCacheDirectory();
return $cache_directory && file_exists($cache_directory . '/' . self::GOOD_RUN_NAME);
}
/**
@ -686,7 +680,9 @@ class FileChecker implements StatementsSource
public static function hasFileChanged($file)
{
if (self::$last_good_run === null) {
self::$last_good_run = filemtime(self::$cache_dir . '/' . self::GOOD_RUN_NAME) ?: 0;
$cache_directory = Config::getInstance()->getCacheDirectory();
self::$last_good_run = filemtime($cache_directory . '/' . self::GOOD_RUN_NAME) ?: 0;
}
return filemtime($file) > self::$last_good_run;
@ -714,8 +710,10 @@ class FileChecker implements StatementsSource
*/
public static function goodRun()
{
if (self::$cache_dir) {
$run_cache_location = self::$cache_dir . '/' . self::GOOD_RUN_NAME;
$cache_directory = Config::getInstance()->getCacheDirectory();
if ($cache_directory) {
$run_cache_location = $cache_directory . '/' . self::GOOD_RUN_NAME;
touch($run_cache_location);
@ -727,7 +725,7 @@ class FileChecker implements StatementsSource
}
file_put_contents(
self::$cache_dir . '/' . self::REFERENCE_CACHE_NAME,
$cache_directory . '/' . self::REFERENCE_CACHE_NAME,
serialize(self::$file_references)
);
}

View File

@ -49,7 +49,14 @@ class Config
public $throw_exception = false;
/**
* Path to the autoloader
* The directory to store PHP Parser (and other) caches
*
* @var string
*/
public $cache_directory = '/var/tmp/psalm';
/**
* Path to the autoader
*
* @var string|null
*/
@ -149,6 +156,10 @@ class Config
$config->autoloader = (string) $config_xml['autoloader'];
}
if (isset($config_xml['cacheDirectory'])) {
$config->cacheDirectory = (string) $config_xml['cacheDirectory'];
}
if (isset($config_xml->inspectFiles)) {
$config->inspect_files = FileFilter::loadFromXML($config_xml->inspectFiles, true);
}
@ -375,6 +386,14 @@ class Config
return $this->mock_classes;
}
/**
* @return string|null
*/
public function getCacheDirectory()
{
return $this->cache_directory;
}
/**
* @return array<Plugin>
*/