diff --git a/src/Tests/Tests/epv_test_validate_composer.php b/src/Tests/Tests/epv_test_validate_composer.php index 79ddfd3..a9fbd15 100644 --- a/src/Tests/Tests/epv_test_validate_composer.php +++ b/src/Tests/Tests/epv_test_validate_composer.php @@ -47,6 +47,7 @@ public function validateFile(FileInterface $file) $this->validateName($file); $this->validateLicense($file); + $this->validateVersion($file); } /** @@ -58,17 +59,37 @@ private function validateLicense(ComposerFileInterface $file) { $json = $file->getJson(); $this->addMessageIfBooleanTrue(!isset($json['license']), Output::FATAL, 'The license key is missing'); - $this->addMessageIfBooleanTrue($json['license'] != 'GPL-2.0', Output::ERROR, 'It is required to use the GPL-2.0 as license. MIT is not allowed as per the extension database policies.'); + $this->addMessageIfBooleanTrue(isset($json['license']) && $json['license'] != 'GPL-2.0', Output::ERROR, 'It is required to use the GPL-2.0 as license. MIT is not allowed as per the extension database policies.'); } private function validateName(ComposerFileInterface $file) { $json = $file->getJson(); $this->addMessageIfBooleanTrue(!isset($json['name']), Output::FATAL, 'The name key is missing'); - $this->addMessageIfBooleanTrue(strpos($json['name'], '_') !== false, Output::FATAL, 'The namespace should not contain underscores'); + $this->addMessageIfBooleanTrue(isset($json['name']) && strpos($json['name'], '_') !== false, Output::FATAL, 'The namespace should not contain underscores'); } + /** + * @param ComposerFileInterface $file + */ + private function validateVersion(ComposerFileInterface $file) + { + $json = $file->getJson(); + + if (isset($json['extra']) && isset($json['extra']['soft-require']) && isset($json['extra']['soft-require']['phpbb/phpbb'])) + { + // https://github.com/phpbb/customisation-db/blob/3.1.x/contribution/extension/type.php#L296 + $regex = '/(<|<=|~|\^|>|>=)([0-9]+(\.[0-9]+)?)\.[*x]/'; + + if (preg_match($regex, $json['extra']['soft-require']['phpbb/phpbb'])) + { + $replace = preg_replace($regex, '$1$2', $json['extra']['soft-require']['phpbb/phpbb']);; + $this->addMessageIfBooleanTrue(true, Output::ERROR, sprintf('A invalid version constraint is used in soft-require: phpbb/phpbb. You can\'t combine a <|<=|~|\^|>|>= with a *|x. Please replace %s with %s', $json['extra']['soft-require']['phpbb/phpbb'], $replace)); + } + } + } + private function addMessageIfBooleanTrue($addMessage, $type, $message) { if ($addMessage)