function DiagnoseCommand::execute
Overrides Command::execute
File
-
vendor/
composer/ composer/ src/ Composer/ Command/ DiagnoseCommand.php, line 83
Class
- DiagnoseCommand
- @author Jordi Boggiano <j.boggiano@seld.be>
Namespace
Composer\CommandCode
protected function execute(InputInterface $input, OutputInterface $output) : int {
$composer = $this->tryComposer();
$io = $this->getIO();
if ($composer) {
$commandEvent = new CommandEvent(PluginEvents::COMMAND, 'diagnose', $input, $output);
$composer->getEventDispatcher()
->dispatch($commandEvent->getName(), $commandEvent);
$io->write('Checking composer.json: ', false);
$this->outputResult($this->checkComposerSchema());
if ($composer->getLocker()
->isLocked()) {
$io->write('Checking composer.lock: ', false);
$this->outputResult($this->checkComposerLockSchema($composer->getLocker()));
}
$this->process = $composer->getLoop()
->getProcessExecutor() ?? new ProcessExecutor($io);
}
else {
$this->process = new ProcessExecutor($io);
}
if ($composer) {
$config = $composer->getConfig();
}
else {
$config = Factory::createConfig();
}
$config->merge([
'config' => [
'secure-http' => false,
],
], Config::SOURCE_COMMAND);
$config->prohibitUrlByConfig('http://repo.packagist.org', new NullIO());
$this->httpDownloader = Factory::createHttpDownloader($io, $config);
$io->write('Checking platform settings: ', false);
$this->outputResult($this->checkPlatform());
$io->write('Checking git settings: ', false);
$this->outputResult($this->checkGit());
$io->write('Checking http connectivity to packagist: ', false);
$this->outputResult($this->checkHttp('http', $config));
$io->write('Checking https connectivity to packagist: ', false);
$this->outputResult($this->checkHttp('https', $config));
foreach ($config->getRepositories() as $repo) {
if (($repo['type'] ?? null) === 'composer' && isset($repo['url'])) {
$composerRepo = new ComposerRepository($repo, $this->getIO(), $config, $this->httpDownloader);
$reflMethod = new \ReflectionMethod($composerRepo, 'getPackagesJsonUrl');
if (PHP_VERSION_ID < 80100) {
$reflMethod->setAccessible(true);
}
$url = $reflMethod->invoke($composerRepo);
if (!str_starts_with($url, 'http')) {
continue;
}
if (str_starts_with($url, 'https://repo.packagist.org')) {
continue;
}
$io->write('Checking connectivity to ' . $repo['url'] . ': ', false);
$this->outputResult($this->checkComposerRepo($url, $config));
}
}
$proxyManager = ProxyManager::getInstance();
$protos = $config->get('disable-tls') === true ? [
'http',
] : [
'http',
'https',
];
try {
foreach ($protos as $proto) {
$proxy = $proxyManager->getProxyForRequest($proto . '://repo.packagist.org');
if ($proxy->getStatus() !== '') {
$type = $proxy->isSecure() ? 'HTTPS' : 'HTTP';
$io->write('Checking ' . $type . ' proxy with ' . $proto . ': ', false);
$this->outputResult($this->checkHttpProxy($proxy, $proto));
}
}
} catch (TransportException $e) {
$io->write('Checking HTTP proxy: ', false);
$status = $this->checkConnectivityAndComposerNetworkHttpEnablement();
$this->outputResult(is_string($status) ? $status : $e);
}
if (count($oauth = $config->get('github-oauth')) > 0) {
foreach ($oauth as $domain => $token) {
$io->write('Checking ' . $domain . ' oauth access: ', false);
$this->outputResult($this->checkGithubOauth($domain, $token));
}
}
else {
$io->write('Checking github.com rate limit: ', false);
try {
$rate = $this->getGithubRateLimit('github.com');
if (!is_array($rate)) {
$this->outputResult($rate);
}
elseif (10 > $rate['remaining']) {
$io->write('<warning>WARNING</warning>');
$io->write(sprintf('<comment>GitHub has a rate limit on their API. ' . 'You currently have <options=bold>%u</options=bold> ' . 'out of <options=bold>%u</options=bold> requests left.' . PHP_EOL . 'See https://developer.github.com/v3/#rate-limiting and also' . PHP_EOL . ' https://getcomposer.org/doc/articles/troubleshooting.md#api-rate-limit-and-oauth-tokens</comment>', $rate['remaining'], $rate['limit']));
}
else {
$this->outputResult(true);
}
} catch (\Exception $e) {
if ($e instanceof TransportException && $e->getCode() === 401) {
$this->outputResult('<comment>The oauth token for github.com seems invalid, run "composer config --global --unset github-oauth.github.com" to remove it</comment>');
}
else {
$this->outputResult($e);
}
}
}
$io->write('Checking disk free space: ', false);
$this->outputResult($this->checkDiskSpace($config));
if (strpos(__FILE__, 'phar:') === 0) {
$io->write('Checking pubkeys: ', false);
$this->outputResult($this->checkPubKeys($config));
$io->write('Checking Composer version: ', false);
$this->outputResult($this->checkVersion($config));
}
$io->write('Checking Composer and its dependencies for vulnerabilities: ', false);
$this->outputResult($this->checkComposerAudit($config));
$io->write(sprintf('Composer version: <comment>%s</comment>', Composer::getVersion()));
$platformOverrides = $config->get('platform') ?: [];
$platformRepo = new PlatformRepository([], $platformOverrides);
$phpPkg = $platformRepo->findPackage('php', '*');
$phpVersion = $phpPkg->getPrettyVersion();
if ($phpPkg instanceof CompletePackageInterface && str_contains((string) $phpPkg->getDescription(), 'overridden')) {
$phpVersion .= ' - ' . $phpPkg->getDescription();
}
$io->write(sprintf('PHP version: <comment>%s</comment>', $phpVersion));
if (defined('PHP_BINARY')) {
$io->write(sprintf('PHP binary path: <comment>%s</comment>', PHP_BINARY));
}
$io->write('OpenSSL version: ' . (defined('OPENSSL_VERSION_TEXT') ? '<comment>' . OPENSSL_VERSION_TEXT . '</comment>' : '<error>missing</error>'));
$io->write('curl version: ' . $this->getCurlVersion());
$finder = new ExecutableFinder();
$hasSystemUnzip = (bool) $finder->find('unzip');
$bin7zip = '';
if ($hasSystem7zip = (bool) $finder->find('7z', null, [
'C:\\Program Files\\7-Zip',
])) {
$bin7zip = '7z';
}
if (!Platform::isWindows() && !$hasSystem7zip && ($hasSystem7zip = (bool) $finder->find('7zz'))) {
$bin7zip = '7zz';
}
$io->write('zip: ' . (extension_loaded('zip') ? '<comment>extension present</comment>' : '<comment>extension not loaded</comment>') . ', ' . ($hasSystemUnzip ? '<comment>unzip present</comment>' : '<comment>unzip not available</comment>') . ', ' . ($hasSystem7zip ? '<comment>7-Zip present (' . $bin7zip . ')</comment>' : '<comment>7-Zip not available</comment>') . (($hasSystem7zip || $hasSystemUnzip) && !function_exists('proc_open') ? ', <warning>proc_open is disabled or not present, unzip/7-z will not be usable</warning>' : ''));
return $this->exitCode;
}