Skip to content

Commit

Permalink
Merge pull request #46 from paul999/validate_version
Browse files Browse the repository at this point in the history
Add a message if version is invalid.
  • Loading branch information
paul999 committed Jan 31, 2016
2 parents dbdad9d + 54b1774 commit 2098836
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/Tests/Tests/epv_test_validate_composer.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public function validateFile(FileInterface $file)

$this->validateName($file);
$this->validateLicense($file);
$this->validateVersion($file);
}

/**
Expand All @@ -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)
Expand Down

0 comments on commit 2098836

Please sign in to comment.