From a54bf0e2d4003c9a442a96f3501a90667048e965 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Wer=C5=82os?= Date: Sat, 18 Apr 2020 09:24:54 +0200 Subject: [PATCH] Use flags instead of boolean in ConfigValidator for checking version field --- src/Composer/Command/ValidateCommand.php | 2 +- src/Composer/Util/ConfigValidator.php | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Composer/Command/ValidateCommand.php b/src/Composer/Command/ValidateCommand.php index cb178d263..8da0854a3 100644 --- a/src/Composer/Command/ValidateCommand.php +++ b/src/Composer/Command/ValidateCommand.php @@ -87,7 +87,7 @@ EOT $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'); + $checkVersion = $input->getOption('no-check-version') ? 0 : ConfigValidator::CHECK_VERSION; $isStrict = $input->getOption('strict'); list($errors, $publishErrors, $warnings) = $validator->validate($file, $checkAll, $checkVersion); diff --git a/src/Composer/Util/ConfigValidator.php b/src/Composer/Util/ConfigValidator.php index 4d6998dec..aae5879b3 100644 --- a/src/Composer/Util/ConfigValidator.php +++ b/src/Composer/Util/ConfigValidator.php @@ -28,6 +28,8 @@ use Composer\Spdx\SpdxLicenses; */ class ConfigValidator { + const CHECK_VERSION = 1; + private $io; public function __construct(IOInterface $io) @@ -40,11 +42,11 @@ class ConfigValidator * * @param string $file The path to the file * @param int $arrayLoaderValidationFlags Flags for ArrayLoader validation - * @param bool $checkVersion Whether or not check if version field is present + * @param int $flags Flags for validation * * @return array a triple containing the errors, publishable errors, and warnings */ - public function validate($file, $arrayLoaderValidationFlags = ValidatingArrayLoader::CHECK_ALL, $checkVersion = true) + public function validate($file, $arrayLoaderValidationFlags = ValidatingArrayLoader::CHECK_ALL, $flags = self::CHECK_VERSION) { $errors = array(); $publishErrors = array(); @@ -110,7 +112,7 @@ class ConfigValidator } } - if ($checkVersion && isset($manifest['version'])) { + if (($flags & self::CHECK_VERSION) && isset($manifest['version'])) { $warnings[] = 'The version field is present, it is recommended to leave it out if the package is published on Packagist.'; }