Skip to content

Commit 2098836

Browse files
committed
Merge pull request #46 from paul999/validate_version
Add a message if version is invalid.
2 parents dbdad9d + 54b1774 commit 2098836

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

src/Tests/Tests/epv_test_validate_composer.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public function validateFile(FileInterface $file)
4747

4848
$this->validateName($file);
4949
$this->validateLicense($file);
50+
$this->validateVersion($file);
5051
}
5152

5253
/**
@@ -58,17 +59,37 @@ private function validateLicense(ComposerFileInterface $file)
5859
{
5960
$json = $file->getJson();
6061
$this->addMessageIfBooleanTrue(!isset($json['license']), Output::FATAL, 'The license key is missing');
61-
$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.');
62+
$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.');
6263
}
6364

6465
private function validateName(ComposerFileInterface $file)
6566
{
6667
$json = $file->getJson();
6768
$this->addMessageIfBooleanTrue(!isset($json['name']), Output::FATAL, 'The name key is missing');
68-
$this->addMessageIfBooleanTrue(strpos($json['name'], '_') !== false, Output::FATAL, 'The namespace should not contain underscores');
69+
$this->addMessageIfBooleanTrue(isset($json['name']) && strpos($json['name'], '_') !== false, Output::FATAL, 'The namespace should not contain underscores');
6970

7071
}
7172

73+
/**
74+
* @param ComposerFileInterface $file
75+
*/
76+
private function validateVersion(ComposerFileInterface $file)
77+
{
78+
$json = $file->getJson();
79+
80+
if (isset($json['extra']) && isset($json['extra']['soft-require']) && isset($json['extra']['soft-require']['phpbb/phpbb']))
81+
{
82+
// https://github.com/phpbb/customisation-db/blob/3.1.x/contribution/extension/type.php#L296
83+
$regex = '/(<|<=|~|\^|>|>=)([0-9]+(\.[0-9]+)?)\.[*x]/';
84+
85+
if (preg_match($regex, $json['extra']['soft-require']['phpbb/phpbb']))
86+
{
87+
$replace = preg_replace($regex, '$1$2', $json['extra']['soft-require']['phpbb/phpbb']);;
88+
$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));
89+
}
90+
}
91+
}
92+
7293
private function addMessageIfBooleanTrue($addMessage, $type, $message)
7394
{
7495
if ($addMessage)

0 commit comments

Comments
 (0)