From f55d7185f5b53505a658e8efbfb23d2c786ce857 Mon Sep 17 00:00:00 2001 From: Paul Sohier Date: Sun, 31 Jan 2016 18:47:37 +0100 Subject: [PATCH 1/4] Add a message if version is invalid. --- .../Tests/epv_test_validate_composer.php | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/Tests/Tests/epv_test_validate_composer.php b/src/Tests/Tests/epv_test_validate_composer.php index 79ddfd3..2290126 100644 --- a/src/Tests/Tests/epv_test_validate_composer.php +++ b/src/Tests/Tests/epv_test_validate_composer.php @@ -58,17 +58,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['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) From 3e9ee608244eec67e02bd62813a68f941faeb937 Mon Sep 17 00:00:00 2001 From: Paul Sohier Date: Sun, 31 Jan 2016 18:50:17 +0100 Subject: [PATCH 2/4] Call the version validate function :) --- src/Tests/Tests/epv_test_validate_composer.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Tests/Tests/epv_test_validate_composer.php b/src/Tests/Tests/epv_test_validate_composer.php index 2290126..635c45e 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); } /** From 4957a6ffe2c4fae29e9fe654d73ccb439710fc77 Mon Sep 17 00:00:00 2001 From: Paul Sohier Date: Sun, 31 Jan 2016 18:54:12 +0100 Subject: [PATCH 3/4] Use correct array index --- src/Tests/Tests/epv_test_validate_composer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Tests/Tests/epv_test_validate_composer.php b/src/Tests/Tests/epv_test_validate_composer.php index 635c45e..7970bfe 100644 --- a/src/Tests/Tests/epv_test_validate_composer.php +++ b/src/Tests/Tests/epv_test_validate_composer.php @@ -84,7 +84,7 @@ private function validateVersion(ComposerFileInterface $file) if (preg_match($regex, $json['extra']['soft-require']['phpbb/phpbb'])) { - $replace = preg_replace($regex, '$1$2', $json['require']['phpbb/phpbb']);; + $replace = preg_replace($regex, '$1$2', $json['extra']['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)); } } From 54b177433f7daf5df9a6cd39a9e64ea4ef207ef5 Mon Sep 17 00:00:00 2001 From: Paul Sohier Date: Sun, 31 Jan 2016 18:56:47 +0100 Subject: [PATCH 4/4] And use soft-require as key ofcourse... --- src/Tests/Tests/epv_test_validate_composer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Tests/Tests/epv_test_validate_composer.php b/src/Tests/Tests/epv_test_validate_composer.php index 7970bfe..a9fbd15 100644 --- a/src/Tests/Tests/epv_test_validate_composer.php +++ b/src/Tests/Tests/epv_test_validate_composer.php @@ -84,7 +84,7 @@ private function validateVersion(ComposerFileInterface $file) if (preg_match($regex, $json['extra']['soft-require']['phpbb/phpbb'])) { - $replace = preg_replace($regex, '$1$2', $json['extra']['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)); } }