updated composer
This commit is contained in:
+6
-9
@@ -22,7 +22,7 @@ class PreReleaseSuffix {
|
||||
/** @var int */
|
||||
private $number = 0;
|
||||
|
||||
/** @var string */
|
||||
/** @var string */
|
||||
private $full;
|
||||
|
||||
/**
|
||||
@@ -56,12 +56,9 @@ class PreReleaseSuffix {
|
||||
return $this->getNumber() > $suffix->getNumber();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
*/
|
||||
private function mapValueToScore($value): int {
|
||||
$value = strtolower($value);
|
||||
|
||||
private function mapValueToScore(string $value): int {
|
||||
$value = \strtolower($value);
|
||||
|
||||
if (\array_key_exists($value, self::valueScoreMap)) {
|
||||
return self::valueScoreMap[$value];
|
||||
}
|
||||
@@ -69,14 +66,14 @@ class PreReleaseSuffix {
|
||||
return 0;
|
||||
}
|
||||
|
||||
private function parseValue($value): void {
|
||||
private function parseValue(string $value): void {
|
||||
$regex = '/-?((dev|beta|b|rc|alpha|a|patch|p)\.?(\d*)).*$/i';
|
||||
|
||||
if (\preg_match($regex, $value, $matches) !== 1) {
|
||||
throw new InvalidPreReleaseSuffixException(\sprintf('Invalid label %s', $value));
|
||||
}
|
||||
|
||||
$this->full = $matches[1];
|
||||
$this->full = $matches[1];
|
||||
$this->value = $matches[2];
|
||||
|
||||
if ($matches[3] !== '') {
|
||||
|
||||
+23
-9
@@ -10,6 +10,9 @@
|
||||
namespace PharIo\Version;
|
||||
|
||||
class Version {
|
||||
/** @var string */
|
||||
private $originalVersionString;
|
||||
|
||||
/** @var VersionNumber */
|
||||
private $major;
|
||||
|
||||
@@ -19,26 +22,32 @@ class Version {
|
||||
/** @var VersionNumber */
|
||||
private $patch;
|
||||
|
||||
/** @var PreReleaseSuffix */
|
||||
/** @var null|PreReleaseSuffix */
|
||||
private $preReleaseSuffix;
|
||||
|
||||
/**
|
||||
* @param string $versionString
|
||||
*/
|
||||
public function __construct($versionString) {
|
||||
public function __construct(string $versionString) {
|
||||
$this->ensureVersionStringIsValid($versionString);
|
||||
$this->originalVersionString = $versionString;
|
||||
}
|
||||
|
||||
public function getPreReleaseSuffix(): PreReleaseSuffix {
|
||||
if ($this->preReleaseSuffix === null) {
|
||||
throw new NoPreReleaseSuffixException('No pre-release suffix set');
|
||||
}
|
||||
|
||||
return $this->preReleaseSuffix;
|
||||
}
|
||||
|
||||
public function getOriginalString(): string {
|
||||
return $this->originalVersionString;
|
||||
}
|
||||
|
||||
public function getVersionString(): string {
|
||||
$str = sprintf(
|
||||
$str = \sprintf(
|
||||
'%d.%d.%d',
|
||||
$this->getMajor()->getValue(),
|
||||
$this->getMinor()->getValue(),
|
||||
$this->getPatch()->getValue()
|
||||
$this->getMajor()->getValue() ?? 0,
|
||||
$this->getMinor()->getValue() ?? 0,
|
||||
$this->getPatch()->getValue() ?? 0
|
||||
);
|
||||
|
||||
if (!$this->hasPreReleaseSuffix()) {
|
||||
@@ -108,6 +117,11 @@ class Version {
|
||||
return $this->patch;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string[] $matches
|
||||
*
|
||||
* @throws InvalidPreReleaseSuffixException
|
||||
*/
|
||||
private function parseVersion(array $matches): void {
|
||||
$this->major = new VersionNumber((int)$matches['Major']);
|
||||
$this->minor = new VersionNumber((int)$matches['Minor']);
|
||||
|
||||
+48
-45
@@ -11,11 +11,9 @@ namespace PharIo\Version;
|
||||
|
||||
class VersionConstraintParser {
|
||||
/**
|
||||
* @param string $value
|
||||
*
|
||||
* @throws UnsupportedVersionConstraintException
|
||||
*/
|
||||
public function parse($value): VersionConstraint {
|
||||
public function parse(string $value): VersionConstraint {
|
||||
if (\strpos($value, '||') !== false) {
|
||||
return $this->handleOrGroup($value);
|
||||
}
|
||||
@@ -33,34 +31,31 @@ class VersionConstraintParser {
|
||||
return $this->handleCaretOperator($value);
|
||||
}
|
||||
|
||||
$version = new VersionConstraintValue($value);
|
||||
$constraint = new VersionConstraintValue($value);
|
||||
|
||||
if ($version->getMajor()->isAny()) {
|
||||
if ($constraint->getMajor()->isAny()) {
|
||||
return new AnyVersionConstraint();
|
||||
}
|
||||
|
||||
if ($version->getMinor()->isAny()) {
|
||||
if ($constraint->getMinor()->isAny()) {
|
||||
return new SpecificMajorVersionConstraint(
|
||||
$version->getVersionString(),
|
||||
$version->getMajor()->getValue()
|
||||
$constraint->getVersionString(),
|
||||
$constraint->getMajor()->getValue() ?? 0
|
||||
);
|
||||
}
|
||||
|
||||
if ($version->getPatch()->isAny()) {
|
||||
if ($constraint->getPatch()->isAny()) {
|
||||
return new SpecificMajorAndMinorVersionConstraint(
|
||||
$version->getVersionString(),
|
||||
$version->getMajor()->getValue(),
|
||||
$version->getMinor()->getValue()
|
||||
$constraint->getVersionString(),
|
||||
$constraint->getMajor()->getValue() ?? 0,
|
||||
$constraint->getMinor()->getValue() ?? 0
|
||||
);
|
||||
}
|
||||
|
||||
return new ExactVersionConstraint($version->getVersionString());
|
||||
return new ExactVersionConstraint($constraint->getVersionString());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
*/
|
||||
private function handleOrGroup($value): OrVersionConstraintGroup {
|
||||
private function handleOrGroup(string $value): OrVersionConstraintGroup {
|
||||
$constraints = [];
|
||||
|
||||
foreach (\explode('||', $value) as $groupSegment) {
|
||||
@@ -70,43 +65,51 @@ class VersionConstraintParser {
|
||||
return new OrVersionConstraintGroup($value, $constraints);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
*/
|
||||
private function handleTildeOperator($value): AndVersionConstraintGroup {
|
||||
$version = new Version(\substr($value, 1));
|
||||
$constraints = [
|
||||
new GreaterThanOrEqualToVersionConstraint($value, $version)
|
||||
];
|
||||
private function handleTildeOperator(string $value): AndVersionConstraintGroup {
|
||||
$constraintValue = new VersionConstraintValue(\substr($value, 1));
|
||||
|
||||
if ($version->getPatch()->isAny()) {
|
||||
$constraints[] = new SpecificMajorVersionConstraint(
|
||||
$value,
|
||||
$version->getMajor()->getValue()
|
||||
);
|
||||
} else {
|
||||
$constraints[] = new SpecificMajorAndMinorVersionConstraint(
|
||||
$value,
|
||||
$version->getMajor()->getValue(),
|
||||
$version->getMinor()->getValue()
|
||||
);
|
||||
if ($constraintValue->getPatch()->isAny()) {
|
||||
return $this->handleCaretOperator($value);
|
||||
}
|
||||
|
||||
$constraints = [
|
||||
new GreaterThanOrEqualToVersionConstraint(
|
||||
$value,
|
||||
new Version(\substr($value, 1))
|
||||
),
|
||||
new SpecificMajorAndMinorVersionConstraint(
|
||||
$value,
|
||||
$constraintValue->getMajor()->getValue() ?? 0,
|
||||
$constraintValue->getMinor()->getValue() ?? 0
|
||||
)
|
||||
];
|
||||
|
||||
return new AndVersionConstraintGroup($value, $constraints);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
*/
|
||||
private function handleCaretOperator($value): AndVersionConstraintGroup {
|
||||
$version = new Version(\substr($value, 1));
|
||||
private function handleCaretOperator(string $value): AndVersionConstraintGroup {
|
||||
$constraintValue = new VersionConstraintValue(\substr($value, 1));
|
||||
|
||||
$constraints = [
|
||||
new GreaterThanOrEqualToVersionConstraint($value, new Version(\substr($value, 1)))
|
||||
];
|
||||
|
||||
if ($constraintValue->getMajor()->getValue() === 0) {
|
||||
$constraints[] = new SpecificMajorAndMinorVersionConstraint(
|
||||
$value,
|
||||
$constraintValue->getMajor()->getValue() ?? 0,
|
||||
$constraintValue->getMinor()->getValue() ?? 0
|
||||
);
|
||||
} else {
|
||||
$constraints[] = new SpecificMajorVersionConstraint(
|
||||
$value,
|
||||
$constraintValue->getMajor()->getValue() ?? 0
|
||||
);
|
||||
}
|
||||
|
||||
return new AndVersionConstraintGroup(
|
||||
$value,
|
||||
[
|
||||
new GreaterThanOrEqualToVersionConstraint($value, $version),
|
||||
new SpecificMajorVersionConstraint($value, $version->getMajor()->getValue())
|
||||
]
|
||||
$constraints
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
+5
-17
@@ -20,10 +20,7 @@ class VersionConstraintValue {
|
||||
/** @var string */
|
||||
private $versionString = '';
|
||||
|
||||
/**
|
||||
* @param string $versionString
|
||||
*/
|
||||
public function __construct($versionString) {
|
||||
public function __construct(string $versionString) {
|
||||
$this->versionString = $versionString;
|
||||
|
||||
$this->parseVersion($versionString);
|
||||
@@ -53,10 +50,7 @@ class VersionConstraintValue {
|
||||
return $this->patch;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $versionString
|
||||
*/
|
||||
private function parseVersion($versionString): void {
|
||||
private function parseVersion(string $versionString): void {
|
||||
$this->extractBuildMetaData($versionString);
|
||||
$this->extractLabel($versionString);
|
||||
$this->stripPotentialVPrefix($versionString);
|
||||
@@ -71,27 +65,21 @@ class VersionConstraintValue {
|
||||
$this->patch = new VersionNumber($patchValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $versionString
|
||||
*/
|
||||
private function extractBuildMetaData(&$versionString): void {
|
||||
private function extractBuildMetaData(string &$versionString): void {
|
||||
if (\preg_match('/\+(.*)/', $versionString, $matches) === 1) {
|
||||
$this->buildMetaData = $matches[1];
|
||||
$versionString = \str_replace($matches[0], '', $versionString);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $versionString
|
||||
*/
|
||||
private function extractLabel(&$versionString): void {
|
||||
private function extractLabel(string &$versionString): void {
|
||||
if (\preg_match('/-(.*)/', $versionString, $matches) === 1) {
|
||||
$this->label = $matches[1];
|
||||
$versionString = \str_replace($matches[0], '', $versionString);
|
||||
}
|
||||
}
|
||||
|
||||
private function stripPotentialVPrefix(&$versionString): void {
|
||||
private function stripPotentialVPrefix(string &$versionString): void {
|
||||
if ($versionString[0] !== 'v') {
|
||||
return;
|
||||
}
|
||||
|
||||
+1
-4
@@ -13,10 +13,7 @@ class GreaterThanOrEqualToVersionConstraint extends AbstractVersionConstraint {
|
||||
/** @var Version */
|
||||
private $minimalVersion;
|
||||
|
||||
/**
|
||||
* @param string $originalValue
|
||||
*/
|
||||
public function __construct($originalValue, Version $minimalVersion) {
|
||||
public function __construct(string $originalValue, Version $minimalVersion) {
|
||||
parent::__construct($originalValue);
|
||||
|
||||
$this->minimalVersion = $minimalVersion;
|
||||
|
||||
+3
-8
@@ -11,17 +11,12 @@ namespace PharIo\Version;
|
||||
|
||||
class SpecificMajorAndMinorVersionConstraint extends AbstractVersionConstraint {
|
||||
/** @var int */
|
||||
private $major = 0;
|
||||
private $major;
|
||||
|
||||
/** @var int */
|
||||
private $minor = 0;
|
||||
private $minor;
|
||||
|
||||
/**
|
||||
* @param string $originalValue
|
||||
* @param int $major
|
||||
* @param int $minor
|
||||
*/
|
||||
public function __construct($originalValue, $major, $minor) {
|
||||
public function __construct(string $originalValue, int $major, int $minor) {
|
||||
parent::__construct($originalValue);
|
||||
|
||||
$this->major = $major;
|
||||
|
||||
@@ -11,13 +11,9 @@ namespace PharIo\Version;
|
||||
|
||||
class SpecificMajorVersionConstraint extends AbstractVersionConstraint {
|
||||
/** @var int */
|
||||
private $major = 0;
|
||||
private $major;
|
||||
|
||||
/**
|
||||
* @param string $originalValue
|
||||
* @param int $major
|
||||
*/
|
||||
public function __construct($originalValue, $major) {
|
||||
public function __construct(string $originalValue, int $major) {
|
||||
parent::__construct($originalValue);
|
||||
|
||||
$this->major = $major;
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php declare(strict_types = 1);
|
||||
namespace PharIo\Version;
|
||||
|
||||
class NoPreReleaseSuffixException extends \Exception implements Exception {
|
||||
}
|
||||
Reference in New Issue
Block a user