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

Breadcrumb

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

function StatusCommand::doExecute

1 call to StatusCommand::doExecute()
StatusCommand::execute in vendor/composer/composer/src/Composer/Command/StatusCommand.php
Executes the current command.

File

vendor/composer/composer/src/Composer/Command/StatusCommand.php, line 79

Class

StatusCommand
@author Tiago Ribeiro <tiago.ribeiro@seegno.com> @author Rui Marinho <rui.marinho@seegno.com>

Namespace

Composer\Command

Code

private function doExecute(InputInterface $input) : int {
    // init repos
    $composer = $this->requireComposer();
    $installedRepo = $composer->getRepositoryManager()
        ->getLocalRepository();
    $dm = $composer->getDownloadManager();
    $im = $composer->getInstallationManager();
    $errors = [];
    $io = $this->getIO();
    $unpushedChanges = [];
    $vcsVersionChanges = [];
    $parser = new VersionParser();
    $guesser = new VersionGuesser($composer->getConfig(), $composer->getLoop()
        ->getProcessExecutor() ?? new ProcessExecutor($io), $parser, $io);
    $dumper = new ArrayDumper();
    // list packages
    foreach ($installedRepo->getCanonicalPackages() as $package) {
        $downloader = $dm->getDownloaderForPackage($package);
        $targetDir = $im->getInstallPath($package);
        if ($targetDir === null) {
            continue;
        }
        if ($downloader instanceof ChangeReportInterface) {
            if (is_link($targetDir)) {
                $errors[$targetDir] = $targetDir . ' is a symbolic link.';
            }
            if (null !== ($changes = $downloader->getLocalChanges($package, $targetDir))) {
                $errors[$targetDir] = $changes;
            }
        }
        if ($downloader instanceof VcsCapableDownloaderInterface) {
            if ($downloader->getVcsReference($package, $targetDir)) {
                switch ($package->getInstallationSource()) {
                    case 'source':
                        $previousRef = $package->getSourceReference();
                        break;
                    case 'dist':
                        $previousRef = $package->getDistReference();
                        break;
                    default:
                        $previousRef = null;
                }
                $currentVersion = $guesser->guessVersion($dumper->dump($package), $targetDir);
                if ($previousRef && $currentVersion && $currentVersion['commit'] !== $previousRef && $currentVersion['pretty_version'] !== $previousRef) {
                    $vcsVersionChanges[$targetDir] = [
                        'previous' => [
                            'version' => $package->getPrettyVersion(),
                            'ref' => $previousRef,
                        ],
                        'current' => [
                            'version' => $currentVersion['pretty_version'],
                            'ref' => $currentVersion['commit'],
                        ],
                    ];
                }
            }
        }
        if ($downloader instanceof DvcsDownloaderInterface) {
            if ($unpushed = $downloader->getUnpushedChanges($package, $targetDir)) {
                $unpushedChanges[$targetDir] = $unpushed;
            }
        }
    }
    // output errors/warnings
    if (!$errors && !$unpushedChanges && !$vcsVersionChanges) {
        $io->writeError('<info>No local changes</info>');
        return 0;
    }
    if ($errors) {
        $io->writeError('<error>You have changes in the following dependencies:</error>');
        foreach ($errors as $path => $changes) {
            if ($input->getOption('verbose')) {
                $indentedChanges = implode("\n", array_map(static function ($line) : string {
                    return '    ' . ltrim($line);
                }, explode("\n", $changes)));
                $io->write('<info>' . $path . '</info>:');
                $io->write($indentedChanges);
            }
            else {
                $io->write($path);
            }
        }
    }
    if ($unpushedChanges) {
        $io->writeError('<warning>You have unpushed changes on the current branch in the following dependencies:</warning>');
        foreach ($unpushedChanges as $path => $changes) {
            if ($input->getOption('verbose')) {
                $indentedChanges = implode("\n", array_map(static function ($line) : string {
                    return '    ' . ltrim($line);
                }, explode("\n", $changes)));
                $io->write('<info>' . $path . '</info>:');
                $io->write($indentedChanges);
            }
            else {
                $io->write($path);
            }
        }
    }
    if ($vcsVersionChanges) {
        $io->writeError('<warning>You have version variations in the following dependencies:</warning>');
        foreach ($vcsVersionChanges as $path => $changes) {
            if ($input->getOption('verbose')) {
                // If we don't can't find a version, use the ref instead.
                $currentVersion = $changes['current']['version'] ?: $changes['current']['ref'];
                $previousVersion = $changes['previous']['version'] ?: $changes['previous']['ref'];
                if ($io->isVeryVerbose()) {
                    // Output the ref regardless of whether or not it's being used as the version
                    $currentVersion .= sprintf(' (%s)', $changes['current']['ref']);
                    $previousVersion .= sprintf(' (%s)', $changes['previous']['ref']);
                }
                $io->write('<info>' . $path . '</info>:');
                $io->write(sprintf('    From <comment>%s</comment> to <comment>%s</comment>', $previousVersion, $currentVersion));
            }
            else {
                $io->write($path);
            }
        }
    }
    if (($errors || $unpushedChanges || $vcsVersionChanges) && !$input->getOption('verbose')) {
        $io->writeError('Use --verbose (-v) to see a list of files');
    }
    return ($errors ? self::EXIT_CODE_ERRORS : 0) + ($unpushedChanges ? self::EXIT_CODE_UNPUSHED_CHANGES : 0) + ($vcsVersionChanges ? self::EXIT_CODE_VERSION_CHANGES : 0);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal