Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ValidateCommand.php

function ValidateCommand::execute

Overrides Command::execute

File

vendor/composer/composer/src/Composer/Command/ValidateCommand.php, line 69

Class

ValidateCommand
ValidateCommand

Namespace

Composer\Command

Code

protected function execute(InputInterface $input, OutputInterface $output) : int {
    $file = $input->getArgument('file') ?: Factory::getComposerFile();
    $io = $this->getIO();
    if (!file_exists($file)) {
        $io->writeError('<error>' . $file . ' not found.</error>');
        return 3;
    }
    if (!Filesystem::isReadable($file)) {
        $io->writeError('<error>' . $file . ' is not readable.</error>');
        return 3;
    }
    $validator = new ConfigValidator($io);
    $checkAll = $input->getOption('no-check-all') ? 0 : ValidatingArrayLoader::CHECK_ALL;
    $checkPublish = !$input->getOption('no-check-publish');
    $checkLock = !$input->getOption('no-check-lock');
    $checkVersion = $input->getOption('no-check-version') ? 0 : ConfigValidator::CHECK_VERSION;
    $isStrict = $input->getOption('strict');
    [
        $errors,
        $publishErrors,
        $warnings,
    ] = $validator->validate($file, $checkAll, $checkVersion);
    $lockErrors = [];
    $composer = $this->createComposerInstance($input, $io, $file);
    // config.lock = false ~= implicit --no-check-lock; --check-lock overrides
    $checkLock = $checkLock && $composer->getConfig()
        ->get('lock') || $input->getOption('check-lock');
    $locker = $composer->getLocker();
    if ($locker->isLocked() && !$locker->isFresh()) {
        $lockErrors[] = '- The lock file is not up to date with the latest changes in composer.json, it is recommended that you run `composer update` or `composer update <package name>`.';
    }
    if ($locker->isLocked()) {
        $lockErrors = array_merge($lockErrors, $locker->getMissingRequirementInfo($composer->getPackage(), true));
    }
    $this->outputResult($io, $file, $errors, $warnings, $checkPublish, $publishErrors, $checkLock, $lockErrors, true);
    // $errors include publish and lock errors when exists
    $exitCode = count($errors) > 0 ? 2 : ($isStrict && count($warnings) > 0 ? 1 : 0);
    if ($input->getOption('with-dependencies')) {
        $localRepo = $composer->getRepositoryManager()
            ->getLocalRepository();
        foreach ($localRepo->getPackages() as $package) {
            $path = $composer->getInstallationManager()
                ->getInstallPath($package);
            if (null === $path) {
                continue;
            }
            $file = $path . '/composer.json';
            if (is_dir($path) && file_exists($file)) {
                [
                    $errors,
                    $publishErrors,
                    $warnings,
                ] = $validator->validate($file, $checkAll, $checkVersion);
                $this->outputResult($io, $package->getPrettyName(), $errors, $warnings, $checkPublish, $publishErrors);
                // $errors include publish errors when exists
                $depCode = count($errors) > 0 ? 2 : ($isStrict && count($warnings) > 0 ? 1 : 0);
                $exitCode = max($depCode, $exitCode);
            }
        }
    }
    $commandEvent = new CommandEvent(PluginEvents::COMMAND, 'validate', $input, $output);
    $eventCode = $composer->getEventDispatcher()
        ->dispatch($commandEvent->getName(), $commandEvent);
    return max($eventCode, $exitCode);
}
RSS feed
Powered by Drupal