Use flags instead of boolean in ConfigValidator for checking version field

main
Kuba Werłos 4 years ago
parent 4ec73874cb
commit a54bf0e2d4

@ -87,7 +87,7 @@ EOT
$checkAll = $input->getOption('no-check-all') ? 0 : ValidatingArrayLoader::CHECK_ALL; $checkAll = $input->getOption('no-check-all') ? 0 : ValidatingArrayLoader::CHECK_ALL;
$checkPublish = !$input->getOption('no-check-publish'); $checkPublish = !$input->getOption('no-check-publish');
$checkLock = !$input->getOption('no-check-lock'); $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'); $isStrict = $input->getOption('strict');
list($errors, $publishErrors, $warnings) = $validator->validate($file, $checkAll, $checkVersion); list($errors, $publishErrors, $warnings) = $validator->validate($file, $checkAll, $checkVersion);

@ -28,6 +28,8 @@ use Composer\Spdx\SpdxLicenses;
*/ */
class ConfigValidator class ConfigValidator
{ {
const CHECK_VERSION = 1;
private $io; private $io;
public function __construct(IOInterface $io) public function __construct(IOInterface $io)
@ -40,11 +42,11 @@ class ConfigValidator
* *
* @param string $file The path to the file * @param string $file The path to the file
* @param int $arrayLoaderValidationFlags Flags for ArrayLoader validation * @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 * @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(); $errors = array();
$publishErrors = 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.'; $warnings[] = 'The version field is present, it is recommended to leave it out if the package is published on Packagist.';
} }

Loading…
Cancel
Save