diff --git a/src/Psalm/Config.php b/src/Psalm/Config.php index 908e85ce8..911ab332c 100644 --- a/src/Psalm/Config.php +++ b/src/Psalm/Config.php @@ -1111,7 +1111,8 @@ class Config $any_file_path_matched = false; foreach ($dependent_files as $dependent_file_path) { - if (($project_analyzer->full_run || $codebase->analyzer->canReportIssues($dependent_file_path)) + if (($codebase->analyzer->canReportIssues($dependent_file_path) + || $project_analyzer->canReportIssues($dependent_file_path)) && !$this->mustBeIgnored($dependent_file_path) ) { $any_file_path_matched = true; diff --git a/src/Psalm/FileBasedPluginAdapter.php b/src/Psalm/FileBasedPluginAdapter.php index b33b068e3..8cb67637d 100644 --- a/src/Psalm/FileBasedPluginAdapter.php +++ b/src/Psalm/FileBasedPluginAdapter.php @@ -18,6 +18,10 @@ class FileBasedPluginAdapter implements Plugin\PluginEntryPointInterface public function __construct(string $path, Config $config, Codebase $codebase) { + if (!$path) { + throw new \UnexpectedValueException('$path cannot be empty'); + } + $this->path = $path; $this->config = $config; $this->codebase = $codebase; diff --git a/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php b/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php index aa987ef82..ecdbadfb7 100644 --- a/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php @@ -122,6 +122,11 @@ class ProjectAnalyzer */ public $onchange_line_limit; + /** + * @var array + */ + private $project_files; + const TYPE_COMPACT = 'compact'; const TYPE_CONSOLE = 'console'; const TYPE_PYLINT = 'pylint'; @@ -204,6 +209,26 @@ class ProjectAnalyzer } } + $project_files = []; + + foreach ($this->config->getProjectDirectories() as $dir_name) { + $file_extensions = $this->config->getFileExtensions(); + + $file_paths = $this->file_provider->getFilesInDir($dir_name, $file_extensions); + + foreach ($file_paths as $file_path) { + if ($this->config->isInProjectDirs($file_path)) { + $project_files[$file_path] = $file_path; + } + } + } + + foreach ($this->config->getProjectFiles() as $file_path) { + $project_files[$file_path] = $file_path; + } + + $this->project_files = $project_files; + $this->output_format = $output_format; self::$instance = $this; } @@ -323,6 +348,16 @@ class ProjectAnalyzer return self::$instance; } + /** + * @param string $file_path + * + * @return bool + */ + public function canReportIssues($file_path) + { + return isset($this->project_files[$file_path]); + } + /** * @param string $base_dir * @param bool $is_diff @@ -361,36 +396,18 @@ class ProjectAnalyzer echo 'Scanning files...' . "\n"; } - $all_files_to_scan = []; - - foreach ($this->config->getProjectDirectories() as $dir_name) { - $file_extensions = $this->config->getFileExtensions(); - - $file_paths = $this->file_provider->getFilesInDir($dir_name, $file_extensions); - - foreach ($file_paths as $file_path) { - if ($this->config->isInProjectDirs($file_path)) { - $all_files_to_scan[$file_path] = $file_path; - } - } - } - - foreach ($this->config->getProjectFiles() as $file_path) { - $all_files_to_scan[$file_path] = $file_path; - } - if ($diff_files === null || $deleted_files === null || count($diff_files) > 200 || $this->codebase->find_unused_code) { - $this->codebase->scanner->addFilesToDeepScan($all_files_to_scan); + $this->codebase->scanner->addFilesToDeepScan($this->project_files); } if ($diff_files === null || $deleted_files === null || count($diff_files) > 200 ) { - $this->codebase->analyzer->addFiles($all_files_to_scan); + $this->codebase->analyzer->addFiles($this->project_files); $this->config->initializePlugins($this); diff --git a/tests/TestConfig.php b/tests/TestConfig.php index d3e7e29e8..74e430d91 100644 --- a/tests/TestConfig.php +++ b/tests/TestConfig.php @@ -19,8 +19,19 @@ class TestConfig extends Config $this->base_dir = getcwd() . DIRECTORY_SEPARATOR; - $this->project_files = new Config\ProjectFileFilter(true); - $this->project_files->addDirectory($this->base_dir . 'src'); + $this->project_files = Config\ProjectFileFilter::loadFromXMLElement( + new \SimpleXMLElement( + ' + + + + + + ' + ), + $this->base_dir, + true + ); $this->collectPredefinedConstants(); $this->collectPredefinedFunctions();