1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 21:31:13 +01:00

Accept space-separated arguments

This commit is contained in:
Matthew Brown 2016-10-05 17:08:20 -04:00
parent 3f742ee954
commit ed2c157762
4 changed files with 73 additions and 14 deletions

View File

@ -29,7 +29,7 @@ $use_color = !array_key_exists('monochrome', $options);
$show_info = isset($options['show-info'])
? $options['show-info'] !== 'false' && $options['show-info'] !== '0'
: true;
$diff_files = isset($options['diff']) ? explode(',', $options['diff']) : [];
$diff_files = isset($options['diff']) ? explode(' ', $options['diff']) : [];
// set the cache directory for the file checker
FileChecker::setCacheDir('/var/tmp/php-parser');

View File

@ -241,6 +241,8 @@ abstract class ClassLikeChecker implements StatementsSource
$this->registerInheritedMethods($this->parent_class);
FileChecker::addFileInheritanceToClass(Config::getInstance()->getBaseDir() . $this->file_name, $this->parent_class);
self::$class_implements[$this->absolute_class] += self::$class_implements[$this->parent_class];
self::$public_class_properties[$this->absolute_class] = self::$public_class_properties[$this->parent_class];
@ -267,6 +269,8 @@ abstract class ClassLikeChecker implements StatementsSource
}
self::registerClass($interface_name);
FileChecker::addFileInheritanceToClass(Config::getInstance()->getBaseDir() . $this->file_name, $interface_name);
}
foreach (ClassChecker::getInterfacesForClass($this->absolute_class) as $interface_id => $interface_name) {
@ -341,6 +345,8 @@ abstract class ClassLikeChecker implements StatementsSource
$trait_checker->check(false, $class_context);
FileChecker::addFileInheritanceToClass(Config::getInstance()->getBaseDir() . $this->file_name, $this->parent_class);
$trait_checkers[] = $trait_checker;
}
}

View File

@ -52,7 +52,7 @@ class FileChecker implements StatementsSource
/**
* A lookup table used for getting all the files referenced by a file
*
* @var array<string,array<string,bool>>
* @var array<string,object-like{a:array<int,string>,i:array<int,string>}>
*/
protected static $file_references = [];
@ -63,6 +63,9 @@ class FileChecker implements StatementsSource
*/
protected static $referencing_files = [];
/** @var array<string,array<int,string>> */
protected static $files_inheriting_classes = [];
public function __construct($file_name, array $preloaded_statements = [])
{
$this->real_file_name = $file_name;
@ -290,8 +293,11 @@ class FileChecker implements StatementsSource
if (is_readable($cache_location)) {
self::$file_references = unserialize((string) file_get_contents($cache_location));
return true;
}
}
return false;
}
public static function updateReferenceCache()
@ -300,8 +306,24 @@ class FileChecker implements StatementsSource
$cache_location = self::$cache_dir . '/' . self::REFERENCE_CACHE_NAME;
foreach (self::$files_checked as $file => $_) {
$existing_references_to_file = isset(self::$file_references[$file]) ? self::$file_references[$file] : [];
self::$file_references[$file] = array_unique(array_merge($existing_references_to_file, self::calculateFilesReferencingFile($file)));
$all_file_references = array_unique(
array_merge(
isset(self::$file_references[$file]['a']) ? self::$file_references[$file]['a'] : [],
self::calculateFilesReferencingFile($file)
)
);
$inheritance_references = array_unique(
array_merge(
isset(self::$file_references[$file]['i']) ? self::$file_references[$file]['i'] : [],
self::calculateFilesInheritingFile($file)
)
);
self::$file_references[$file] = [
'a' => $all_file_references,
'i' => $inheritance_references
];
}
file_put_contents($cache_location, serialize(self::$file_references));
@ -429,6 +451,11 @@ class FileChecker implements StatementsSource
self::$file_references_to_class[$absolute_class][$source_file] = true;
}
public static function addFileInheritanceToClass($source_file, $absolute_class)
{
self::$files_inheriting_classes[$absolute_class][$source_file] = true;
}
public static function calculateFilesReferencingFile($file)
{
$referenced_files = [];
@ -444,9 +471,29 @@ class FileChecker implements StatementsSource
return array_unique($referenced_files);
}
public static function calculateFilesInheritingFile($file)
{
$referenced_files = [];
$file_classes = ClassLikeChecker::getClassesForFile($file);
foreach ($file_classes as $file_class) {
if (isset(self::$files_inheriting_classes[$file_class])) {
$referenced_files = array_merge($referenced_files, array_keys(self::$files_inheriting_classes[$file_class]));
}
}
return array_unique($referenced_files);
}
public static function getFilesReferencingFile($file)
{
return isset(self::$file_references[$file]) ? self::$file_references[$file] : [];
return isset(self::$file_references[$file]['a']) ? self::$file_references[$file]['a'] : [];
}
public static function getFilesInheritingFromFile($file)
{
return isset(self::$file_references[$file]['i']) ? self::$file_references[$file]['i'] : [];
}
public static function clearCache()

View File

@ -37,8 +37,7 @@ class ProjectChecker
$file_list = [];
if ($diff_files) {
FileChecker::loadReferenceCache();
if ($diff_files && FileChecker::loadReferenceCache()) {
$file_list = self::getReferencedFilesFromDiff($diff_files);
self::checkDiffFilesWithConfig($file_list, self::$config, $debug);
}
@ -226,18 +225,25 @@ class ProjectChecker
public static function getReferencedFilesFromDiff(array $diff_files)
{
$all_files_to_check = $diff_files;
$all_inherited_files_to_check = $diff_files;
while ($diff_files) {
$diff_file = array_shift($diff_files);
$dependent_files = FileChecker::getFilesReferencingFile($diff_file);
//var_dump($dependent_files);
$new_files = array_diff($dependent_files, $all_files_to_check);
$all_files_to_check += $new_files;
$diff_files += $new_files;
$dependent_files = FileChecker::getFilesInheritingFromFile($diff_file);
$new_dependent_files = array_diff($dependent_files, $all_inherited_files_to_check);
$all_inherited_files_to_check += $new_dependent_files;
$diff_files += $new_dependent_files;
}
return $all_files_to_check;
$all_files_to_check = $all_inherited_files_to_check;
foreach ($all_inherited_files_to_check as $file_name) {
$dependent_files = FileChecker::getFilesReferencingFile($file_name);
$all_files_to_check = array_merge($dependent_files, $all_files_to_check);
}
return array_unique($all_files_to_check);
}
}