check(); $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); } $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); } // initialise custom config, if passed // Initializing the config can be slow, so any UI logic should precede it, if possible 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'] : max(1, ProjectAnalyzer::getCpuCount() - 2); $providers = 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) ); $debug = array_key_exists('debug', $options); $progress = $debug ? new DebugProgress() : new DefaultProgress(); $project_analyzer = new ProjectAnalyzer( $config, $providers, !array_key_exists('m', $options), false, ProjectAnalyzer::TYPE_CONSOLE, $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);