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

Breadcrumb

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

function ValidateCommand::outputResult

Parameters

string[] $errors:

string[] $warnings:

string[] $publishErrors:

string[] $lockErrors:

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

File

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

Class

ValidateCommand
ValidateCommand

Namespace

Composer\Command

Code

private function outputResult(IOInterface $io, string $name, array &$errors, array &$warnings, bool $checkPublish = false, array $publishErrors = [], bool $checkLock = false, array $lockErrors = [], bool $printSchemaUrl = false) : void {
    $doPrintSchemaUrl = false;
    if ($errors) {
        $io->writeError('<error>' . $name . ' is invalid, the following errors/warnings were found:</error>');
    }
    elseif ($publishErrors) {
        $io->writeError('<info>' . $name . ' is valid for simple usage with Composer but has</info>');
        $io->writeError('<info>strict errors that make it unable to be published as a package</info>');
        $doPrintSchemaUrl = $printSchemaUrl;
    }
    elseif ($warnings) {
        $io->writeError('<info>' . $name . ' is valid, but with a few warnings</info>');
        $doPrintSchemaUrl = $printSchemaUrl;
    }
    elseif ($lockErrors) {
        $io->write('<info>' . $name . ' is valid but your composer.lock has some ' . ($checkLock ? 'errors' : 'warnings') . '</info>');
    }
    else {
        $io->write('<info>' . $name . ' is valid</info>');
    }
    if ($doPrintSchemaUrl) {
        $io->writeError('<warning>See https://getcomposer.org/doc/04-schema.md for details on the schema</warning>');
    }
    if ($errors) {
        $errors = array_map(static function ($err) : string {
            return '- ' . $err;
        }, $errors);
        array_unshift($errors, '# General errors');
    }
    if ($warnings) {
        $warnings = array_map(static function ($err) : string {
            return '- ' . $err;
        }, $warnings);
        array_unshift($warnings, '# General warnings');
    }
    // Avoid setting the exit code to 1 in case --strict and --no-check-publish/--no-check-lock are combined
    $extraWarnings = [];
    // If checking publish errors, display them as errors, otherwise just show them as warnings
    if ($publishErrors) {
        $publishErrors = array_map(static function ($err) : string {
            return '- ' . $err;
        }, $publishErrors);
        if ($checkPublish) {
            array_unshift($publishErrors, '# Publish errors');
            $errors = array_merge($errors, $publishErrors);
        }
        else {
            array_unshift($publishErrors, '# Publish warnings');
            $extraWarnings = array_merge($extraWarnings, $publishErrors);
        }
    }
    // If checking lock errors, display them as errors, otherwise just show them as warnings
    if ($lockErrors) {
        if ($checkLock) {
            array_unshift($lockErrors, '# Lock file errors');
            $errors = array_merge($errors, $lockErrors);
        }
        else {
            array_unshift($lockErrors, '# Lock file warnings');
            $extraWarnings = array_merge($extraWarnings, $lockErrors);
        }
    }
    $messages = [
        'error' => $errors,
        'warning' => array_merge($warnings, $extraWarnings),
    ];
    foreach ($messages as $style => $msgs) {
        foreach ($msgs as $msg) {
            if (strpos($msg, '#') === 0) {
                $io->writeError('<' . $style . '>' . $msg . '</' . $style . '>');
            }
            else {
                $io->writeError($msg);
            }
        }
    }
}

API Navigation

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