check(); $path_to_config = get_path_to_config($options); $args = getArguments(); $operation = null; $last_arg = null; $to_refactor = []; foreach ($args as $arg) { if ($arg === '--move') { $operation = 'move'; continue; } if ($arg === '--into') { if ($operation !== 'move' || !$last_arg) { die('--into is not expected here' . PHP_EOL); } $operation = 'move_into'; continue; } if ($arg === '--rename') { $operation = 'rename'; continue; } if ($arg === '--to') { if ($operation !== 'rename' || !$last_arg) { die('--to is not expected here' . PHP_EOL); } $operation = 'rename_to'; continue; } if ($arg[0] === '-') { $operation = null; continue; } if ($operation === 'move_into' || $operation === 'rename_to') { if (!$last_arg) { die('Expecting a previous argument' . PHP_EOL); } if ($operation === 'move_into') { $last_arg_parts = preg_split('/, ?/', $last_arg); foreach ($last_arg_parts as $last_arg_part) { if (strpos($last_arg_part, '::')) { list(, $identifier_name) = explode('::', $last_arg_part); $to_refactor[$last_arg_part] = $arg . '::' . $identifier_name; } else { $namespace_parts = explode('\\', $last_arg_part); $class_name = end($namespace_parts); $to_refactor[$last_arg_part] = $arg . '\\' . $class_name; } } } else { $to_refactor[$last_arg] = $arg; } $last_arg = null; $operation = null; continue; } if ($operation === 'move' || $operation === 'rename') { $last_arg = $arg; continue; } die('Unexpected argument "' . $arg . '"' . PHP_EOL); } if (!$to_refactor) { die('No --move or --rename arguments supplied' . PHP_EOL); } $config = initialiseConfig($path_to_config, $current_dir, \Psalm\Report::TYPE_CONSOLE, $first_autoloader); if ($config->resolve_from_config_file) { $current_dir = $config->base_dir; chdir($current_dir); } $threads = isset($options['threads']) ? (int)$options['threads'] : max(1, ProjectAnalyzer::getCpuCount() - 2); $providers = new Psalm\Internal\Provider\Providers( new Psalm\Internal\Provider\FileProvider(), new Psalm\Internal\Provider\ParserCacheProvider($config, false), new Psalm\Internal\Provider\FileStorageCacheProvider($config), new Psalm\Internal\Provider\ClassLikeStorageCacheProvider($config), null, new Psalm\Internal\Provider\ProjectCacheProvider($current_dir . DIRECTORY_SEPARATOR . 'composer.lock') ); $debug = array_key_exists('debug', $options); $progress = $debug ? new DebugProgress() : new DefaultProgress(); $project_analyzer = new ProjectAnalyzer( $config, $providers, new \Psalm\Report\ReportOptions(), [], $threads, $progress ); $config->visitComposerAutoloadFiles($project_analyzer); $project_analyzer->refactorCodeAfterCompletion($to_refactor); $start_time = microtime(true); $project_analyzer->check($current_dir); IssueBuffer::finish($project_analyzer, false, $start_time);