From 7e2679ffc1034c480b4c22a886709d27b859d410 Mon Sep 17 00:00:00 2001 From: Guilliam Xavier Date: Thu, 13 Feb 2020 14:37:08 +0100 Subject: [PATCH 1/8] ValidateCommand: pass $isStrict to outputResult() of with-dependencies too --- src/Composer/Command/ValidateCommand.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Composer/Command/ValidateCommand.php b/src/Composer/Command/ValidateCommand.php index 7ec15ccb9..12b9f9fb8 100644 --- a/src/Composer/Command/ValidateCommand.php +++ b/src/Composer/Command/ValidateCommand.php @@ -108,8 +108,9 @@ EOT $file = $path . '/composer.json'; if (is_dir($path) && file_exists($file)) { list($errors, $publishErrors, $warnings) = $validator->validate($file, $checkAll); - $this->outputResult($io, $package->getPrettyName(), $errors, $warnings, $checkPublish, $publishErrors); + $this->outputResult($io, $package->getPrettyName(), $errors, $warnings, $checkPublish, $publishErrors, false, array(), false, $isStrict); + // $errors include publish errors when exists $depCode = $errors ? 2 : ($isStrict && $warnings ? 1 : 0); $exitCode = max($depCode, $exitCode); } From b5e41d679295734b08fb2371a1173e0018f57648 Mon Sep 17 00:00:00 2001 From: Guilliam Xavier Date: Thu, 13 Feb 2020 14:43:26 +0100 Subject: [PATCH 2/8] ValidateCommand: always display all warnings, independently of --strict --- src/Composer/Command/ValidateCommand.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/Composer/Command/ValidateCommand.php b/src/Composer/Command/ValidateCommand.php index 12b9f9fb8..99a74146b 100644 --- a/src/Composer/Command/ValidateCommand.php +++ b/src/Composer/Command/ValidateCommand.php @@ -143,25 +143,31 @@ EOT $io->writeError('' . $name . ' is invalid, the following errors/warnings were found:'); } + $allWarnings = $warnings; + // If checking publish errors, display them as errors, otherwise just show them as warnings // Skip when it is a strict check and we don't want to check publish errors if ($checkPublish) { $errors = array_merge($errors, $publishErrors); - } elseif (!$isStrict) { - $warnings = array_merge($warnings, $publishErrors); + } else { + $allWarnings = array_merge($allWarnings, $publishErrors); } // If checking lock errors, display them as errors, otherwise just show them as warnings // Skip when it is a strict check and we don't want to check lock errors if ($checkLock) { $errors = array_merge($errors, $lockErrors); - } elseif (!$isStrict) { - $warnings = array_merge($warnings, $lockErrors); + } else { + $allWarnings = array_merge($allWarnings, $lockErrors); + } + + if (!$isStrict) { + $warnings = $allWarnings; } $messages = array( 'error' => $errors, - 'warning' => $warnings, + 'warning' => $allWarnings, ); foreach ($messages as $style => $msgs) { From 901d177179e25210333ba3ca3345cf46792031f4 Mon Sep 17 00:00:00 2001 From: Guilliam Xavier Date: Thu, 13 Feb 2020 14:46:50 +0100 Subject: [PATCH 3/8] ValidateCommand: factorize $printSchemaUrl code --- src/Composer/Command/ValidateCommand.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Composer/Command/ValidateCommand.php b/src/Composer/Command/ValidateCommand.php index 99a74146b..aa37e978b 100644 --- a/src/Composer/Command/ValidateCommand.php +++ b/src/Composer/Command/ValidateCommand.php @@ -126,23 +126,25 @@ EOT private function outputResult($io, $name, &$errors, &$warnings, $checkPublish = false, $publishErrors = array(), $checkLock = false, $lockErrors = array(), $printSchemaUrl = false, $isStrict = false) { + $doPrintSchemaUrl = false; + if (!$errors && !$publishErrors && !$warnings) { $io->write('' . $name . ' is valid'); } elseif (!$errors && !$publishErrors) { $io->writeError('' . $name . ' is valid, but with a few warnings'); - if ($printSchemaUrl) { - $io->writeError('See https://getcomposer.org/doc/04-schema.md for details on the schema'); - } + $doPrintSchemaUrl = $printSchemaUrl; } elseif (!$errors) { $io->writeError('' . $name . ' is valid for simple usage with composer but has'); $io->writeError('strict errors that make it unable to be published as a package:'); - if ($printSchemaUrl) { - $io->writeError('See https://getcomposer.org/doc/04-schema.md for details on the schema'); - } + $doPrintSchemaUrl = $printSchemaUrl; } else { $io->writeError('' . $name . ' is invalid, the following errors/warnings were found:'); } + if ($doPrintSchemaUrl) { + $io->writeError('See https://getcomposer.org/doc/04-schema.md for details on the schema'); + } + $allWarnings = $warnings; // If checking publish errors, display them as errors, otherwise just show them as warnings From 2f4bd85219e1c49e7dc904cca204fedae0b826b2 Mon Sep 17 00:00:00 2001 From: Guilliam Xavier Date: Thu, 13 Feb 2020 14:57:38 +0100 Subject: [PATCH 4/8] ValidateCommand: de-invert if-elseif-else to reduce code duplication --- src/Composer/Command/ValidateCommand.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Composer/Command/ValidateCommand.php b/src/Composer/Command/ValidateCommand.php index aa37e978b..14c4a83af 100644 --- a/src/Composer/Command/ValidateCommand.php +++ b/src/Composer/Command/ValidateCommand.php @@ -108,6 +108,7 @@ EOT $file = $path . '/composer.json'; if (is_dir($path) && file_exists($file)) { list($errors, $publishErrors, $warnings) = $validator->validate($file, $checkAll); + $this->outputResult($io, $package->getPrettyName(), $errors, $warnings, $checkPublish, $publishErrors, false, array(), false, $isStrict); // $errors include publish errors when exists @@ -128,17 +129,17 @@ EOT { $doPrintSchemaUrl = false; - if (!$errors && !$publishErrors && !$warnings) { - $io->write('' . $name . ' is valid'); - } elseif (!$errors && !$publishErrors) { - $io->writeError('' . $name . ' is valid, but with a few warnings'); - $doPrintSchemaUrl = $printSchemaUrl; - } elseif (!$errors) { + if ($errors) { + $io->writeError('' . $name . ' is invalid, the following errors/warnings were found:'); + } elseif ($publishErrors) { $io->writeError('' . $name . ' is valid for simple usage with composer but has'); $io->writeError('strict errors that make it unable to be published as a package:'); $doPrintSchemaUrl = $printSchemaUrl; + } elseif ($warnings) { + $io->writeError('' . $name . ' is valid, but with a few warnings'); + $doPrintSchemaUrl = $printSchemaUrl; } else { - $io->writeError('' . $name . ' is invalid, the following errors/warnings were found:'); + $io->write('' . $name . ' is valid'); } if ($doPrintSchemaUrl) { From 35562dcd49ba52d576902b3060680f477d32cb44 Mon Sep 17 00:00:00 2001 From: Guilliam Xavier Date: Thu, 13 Feb 2020 15:48:36 +0100 Subject: [PATCH 5/8] ValidateCommand: add a comment that we didn't forget $lockErrors --- src/Composer/Command/ValidateCommand.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Composer/Command/ValidateCommand.php b/src/Composer/Command/ValidateCommand.php index 14c4a83af..9c973758e 100644 --- a/src/Composer/Command/ValidateCommand.php +++ b/src/Composer/Command/ValidateCommand.php @@ -140,6 +140,7 @@ EOT $doPrintSchemaUrl = $printSchemaUrl; } else { $io->write('' . $name . ' is valid'); + // if ($lockErrors) then they will be displayed below } if ($doPrintSchemaUrl) { From a222ec5b36dc496b46dc441e3b5210b2a282e17a Mon Sep 17 00:00:00 2001 From: Guilliam Xavier Date: Fri, 14 Feb 2020 10:19:27 +0100 Subject: [PATCH 6/8] ValidateCommand: remove actually unused code --- src/Composer/Command/ValidateCommand.php | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/Composer/Command/ValidateCommand.php b/src/Composer/Command/ValidateCommand.php index 9c973758e..860974145 100644 --- a/src/Composer/Command/ValidateCommand.php +++ b/src/Composer/Command/ValidateCommand.php @@ -96,7 +96,7 @@ EOT $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 `.'; } - $this->outputResult($io, $file, $errors, $warnings, $checkPublish, $publishErrors, $checkLock, $lockErrors, true, $isStrict); + $this->outputResult($io, $file, $errors, $warnings, $checkPublish, $publishErrors, $checkLock, $lockErrors, true); // $errors include publish and lock errors when exists $exitCode = $errors ? 2 : ($isStrict && $warnings ? 1 : 0); @@ -109,7 +109,7 @@ EOT if (is_dir($path) && file_exists($file)) { list($errors, $publishErrors, $warnings) = $validator->validate($file, $checkAll); - $this->outputResult($io, $package->getPrettyName(), $errors, $warnings, $checkPublish, $publishErrors, false, array(), false, $isStrict); + $this->outputResult($io, $package->getPrettyName(), $errors, $warnings, $checkPublish, $publishErrors); // $errors include publish errors when exists $depCode = $errors ? 2 : ($isStrict && $warnings ? 1 : 0); @@ -125,7 +125,7 @@ EOT return $exitCode; } - private function outputResult($io, $name, &$errors, &$warnings, $checkPublish = false, $publishErrors = array(), $checkLock = false, $lockErrors = array(), $printSchemaUrl = false, $isStrict = false) + private function outputResult($io, $name, &$errors, &$warnings, $checkPublish = false, $publishErrors = array(), $checkLock = false, $lockErrors = array(), $printSchemaUrl = false) { $doPrintSchemaUrl = false; @@ -147,10 +147,10 @@ EOT $io->writeError('See https://getcomposer.org/doc/04-schema.md for details on the schema'); } + // Avoid setting the exit code to 1 in case --strict and --no-check-publish/--no-check-lock are combined $allWarnings = $warnings; // If checking publish errors, display them as errors, otherwise just show them as warnings - // Skip when it is a strict check and we don't want to check publish errors if ($checkPublish) { $errors = array_merge($errors, $publishErrors); } else { @@ -158,17 +158,12 @@ EOT } // If checking lock errors, display them as errors, otherwise just show them as warnings - // Skip when it is a strict check and we don't want to check lock errors if ($checkLock) { $errors = array_merge($errors, $lockErrors); } else { $allWarnings = array_merge($allWarnings, $lockErrors); } - if (!$isStrict) { - $warnings = $allWarnings; - } - $messages = array( 'error' => $errors, 'warning' => $allWarnings, From ff8bf0ab822bce0cdcab1c3e1f965bfefbacec15 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Fri, 14 Feb 2020 10:45:35 +0100 Subject: [PATCH 7/8] Clarify code Co-Authored-By: Guilliam Xavier --- src/Composer/Command/ValidateCommand.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Composer/Command/ValidateCommand.php b/src/Composer/Command/ValidateCommand.php index 860974145..673c609c2 100644 --- a/src/Composer/Command/ValidateCommand.php +++ b/src/Composer/Command/ValidateCommand.php @@ -148,25 +148,25 @@ EOT } // Avoid setting the exit code to 1 in case --strict and --no-check-publish/--no-check-lock are combined - $allWarnings = $warnings; + $extraWarnings = []; // If checking publish errors, display them as errors, otherwise just show them as warnings if ($checkPublish) { $errors = array_merge($errors, $publishErrors); } else { - $allWarnings = array_merge($allWarnings, $publishErrors); + $extraWarnings = array_merge($extraWarnings, $publishErrors); } // If checking lock errors, display them as errors, otherwise just show them as warnings if ($checkLock) { $errors = array_merge($errors, $lockErrors); } else { - $allWarnings = array_merge($allWarnings, $lockErrors); + $extraWarnings = array_merge($extraWarnings, $lockErrors); } $messages = array( 'error' => $errors, - 'warning' => $allWarnings, + 'warning' => array_merge($warnings, $extraWarnings), ); foreach ($messages as $style => $msgs) { From a17e7e9bd3647768de21606787ea081dc5d53c48 Mon Sep 17 00:00:00 2001 From: Guilliam Xavier Date: Fri, 14 Feb 2020 10:57:19 +0100 Subject: [PATCH 8/8] ValidateCommand: fix array syntax for PHP 5.3 --- src/Composer/Command/ValidateCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Composer/Command/ValidateCommand.php b/src/Composer/Command/ValidateCommand.php index 673c609c2..6ab95ed1c 100644 --- a/src/Composer/Command/ValidateCommand.php +++ b/src/Composer/Command/ValidateCommand.php @@ -148,7 +148,7 @@ EOT } // Avoid setting the exit code to 1 in case --strict and --no-check-publish/--no-check-lock are combined - $extraWarnings = []; + $extraWarnings = array(); // If checking publish errors, display them as errors, otherwise just show them as warnings if ($checkPublish) {