check(); $paths_to_check = getPathsToCheck(isset($options['f']) ? $options['f'] : null); if ($paths_to_check && count($paths_to_check) > 1) { die('Psalter can currently only be run on one path at a time' . PHP_EOL); } $path_to_config = isset($options['c']) && is_string($options['c']) ? realpath($options['c']) : null; if ($path_to_config === false) { /** @psalm-suppress InvalidCast */ die('Could not resolve path to config ' . (string)$options['c'] . PHP_EOL); } // initialise custom config, if passed if ($path_to_config) { $config = Config::loadFromXMLFile($path_to_config, $current_dir); } else { $config = Config::getConfigForPath($current_dir, $current_dir, ProjectAnalyzer::TYPE_CONSOLE); } $config->setComposerClassLoader($first_autoloader); $threads = isset($options['threads']) ? (int)$options['threads'] : 1; $project_analyzer = new ProjectAnalyzer( $config, new Psalm\Internal\Provider\Providers( new Psalm\Internal\Provider\FileProvider(), new Psalm\Internal\Provider\ParserCacheProvider($config), new Psalm\Internal\Provider\FileStorageCacheProvider($config), new Psalm\Internal\Provider\ClassLikeStorageCacheProvider($config) ), !array_key_exists('m', $options), false, ProjectAnalyzer::TYPE_CONSOLE, $threads, array_key_exists('debug', $options) ); if (array_key_exists('debug-by-line', $options)) { $project_analyzer->debug_lines = true; } $config->visitComposerAutoloadFiles($project_analyzer); if (array_key_exists('issues', $options)) { if (!is_string($options['issues']) || !$options['issues']) { die('Expecting a comma-separated list of issues' . PHP_EOL); } $issues = explode(',', $options['issues']); $keyed_issues = []; foreach ($issues as $issue) { $keyed_issues[$issue] = true; } } else { $keyed_issues = []; } if (isset($options['php-version'])) { if (!is_string($options['php-version'])) { die('Expecting a version number in the format x.y' . PHP_EOL); } $project_analyzer->setPhpVersion($options['php-version']); } $plugins = []; if (isset($options['plugin'])) { $plugins = $options['plugin']; if (!is_array($plugins)) { $plugins = [$plugins]; } } /** @var string $plugin_path */ foreach ($plugins as $plugin_path) { Config::getInstance()->addPluginPath($current_dir . $plugin_path); } $find_unused_code = array_key_exists('find-unused-code', $options); if ($config->find_unused_code) { $find_unused_code = true; } if ($find_unused_code) { $project_analyzer->getCodebase()->reportUnusedCode(); } $project_analyzer->alterCodeAfterCompletion( array_key_exists('dry-run', $options), array_key_exists('safe-types', $options) ); $project_analyzer->setIssuesToFix($keyed_issues); $start_time = microtime(true); if ($paths_to_check === null) { $project_analyzer->check($current_dir); } elseif ($paths_to_check) { foreach ($paths_to_check as $path_to_check) { if (is_dir($path_to_check)) { $project_analyzer->checkDir($path_to_check); } else { $project_analyzer->checkFile($path_to_check); } } } IssueBuffer::finish($project_analyzer, false, $start_time);