laravel-6 support

This commit is contained in:
RafficMohammed
2023-01-08 01:17:22 +05:30
parent 1a5c16ae4b
commit 774eed8b0e
4962 changed files with 279380 additions and 297961 deletions

View File

@@ -0,0 +1,28 @@
<?php declare(strict_types = 1);
/*
* This file is part of PharIo\Version.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Version;
class BuildMetaData {
/** @var string */
private $value;
public function __construct(string $value) {
$this->value = $value;
}
public function asString(): string {
return $this->value;
}
public function equals(BuildMetaData $other): bool {
return $this->asString() === $other->asString();
}
}

View File

@@ -1,61 +1,51 @@
<?php
<?php declare(strict_types = 1);
namespace PharIo\Version;
class PreReleaseSuffix {
private $valueScoreMap = [
'dev' => 0,
'a' => 1,
private const valueScoreMap = [
'dev' => 0,
'a' => 1,
'alpha' => 1,
'b' => 2,
'beta' => 2,
'rc' => 3,
'p' => 4,
'b' => 2,
'beta' => 2,
'rc' => 3,
'p' => 4,
'pl' => 4,
'patch' => 4,
];
/**
* @var string
*/
/** @var string */
private $value;
/**
* @var int
*/
/** @var int */
private $valueScore;
/**
* @var int
*/
/** @var int */
private $number = 0;
/** @var string */
private $full;
/**
* @param string $value
* @throws InvalidPreReleaseSuffixException
*/
public function __construct($value) {
public function __construct(string $value) {
$this->parseValue($value);
}
/**
* @return string
*/
public function getValue() {
public function asString(): string {
return $this->full;
}
public function getValue(): string {
return $this->value;
}
/**
* @return int|null
*/
public function getNumber() {
public function getNumber(): ?int {
return $this->number;
}
/**
* @param PreReleaseSuffix $suffix
*
* @return bool
*/
public function isGreaterThan(PreReleaseSuffix $suffix) {
public function isGreaterThan(PreReleaseSuffix $suffix): bool {
if ($this->valueScore > $suffix->valueScore) {
return true;
}
@@ -67,29 +57,26 @@ class PreReleaseSuffix {
return $this->getNumber() > $suffix->getNumber();
}
/**
* @param $value
*
* @return int
*/
private function mapValueToScore($value) {
if (array_key_exists($value, $this->valueScoreMap)) {
return $this->valueScoreMap[$value];
}
private function mapValueToScore(string $value): int {
$value = \strtolower($value);
return 0;
return self::valueScoreMap[$value];
}
private function parseValue($value) {
$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));
private function parseValue(string $value): void {
$regex = '/-?((dev|beta|b|rc|alpha|a|patch|p|pl)\.?(\d*)).*$/i';
if (\preg_match($regex, $value, $matches) !== 1) {
throw new InvalidPreReleaseSuffixException(\sprintf('Invalid label %s', $value));
}
$this->value = $matches[1];
if (isset($matches[2])) {
$this->number = (int)$matches[2];
$this->full = $matches[1];
$this->value = $matches[2];
if ($matches[3] !== '') {
$this->number = (int)$matches[3];
}
$this->valueScore = $this->mapValueToScore($this->value);
$this->valueScore = $this->mapValueToScore($matches[2]);
}
}

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types = 1);
/*
* This file is part of PharIo\Version.
*
@@ -7,71 +7,84 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Version;
class Version {
/**
* @var VersionNumber
*/
/** @var string */
private $originalVersionString;
/** @var VersionNumber */
private $major;
/**
* @var VersionNumber
*/
/** @var VersionNumber */
private $minor;
/**
* @var VersionNumber
*/
/** @var VersionNumber */
private $patch;
/**
* @var PreReleaseSuffix
*/
/** @var null|PreReleaseSuffix */
private $preReleaseSuffix;
/**
* @var string
*/
private $versionString = '';
/** @var null|BuildMetaData */
private $buildMetadata;
/**
* @param string $versionString
*/
public function __construct($versionString) {
public function __construct(string $versionString) {
$this->ensureVersionStringIsValid($versionString);
$this->versionString = $versionString;
$this->originalVersionString = $versionString;
}
/**
* @return PreReleaseSuffix
* @throws NoPreReleaseSuffixException
*/
public function getPreReleaseSuffix() {
public function getPreReleaseSuffix(): PreReleaseSuffix {
if ($this->preReleaseSuffix === null) {
throw new NoPreReleaseSuffixException('No pre-release suffix set');
}
return $this->preReleaseSuffix;
}
/**
* @return string
*/
public function getVersionString() {
return $this->versionString;
public function getOriginalString(): string {
return $this->originalVersionString;
}
/**
* @return bool
*/
public function hasPreReleaseSuffix() {
public function getVersionString(): string {
$str = \sprintf(
'%d.%d.%d',
$this->getMajor()->getValue() ?? 0,
$this->getMinor()->getValue() ?? 0,
$this->getPatch()->getValue() ?? 0
);
if (!$this->hasPreReleaseSuffix()) {
return $str;
}
return $str . '-' . $this->getPreReleaseSuffix()->asString();
}
public function hasPreReleaseSuffix(): bool {
return $this->preReleaseSuffix !== null;
}
/**
* @param Version $version
*
* @return bool
*/
public function isGreaterThan(Version $version) {
public function equals(Version $other): bool {
if ($this->getVersionString() !== $other->getVersionString()) {
return false;
}
if ($this->hasBuildMetaData() !== $other->hasBuildMetaData()) {
return false;
}
if ($this->hasBuildMetaData() && $other->hasBuildMetaData() &&
!$this->getBuildMetaData()->equals($other->getBuildMetaData())) {
return false;
}
return true;
}
public function isGreaterThan(Version $version): bool {
if ($version->getMajor()->getValue() > $this->getMajor()->getValue()) {
return false;
}
@@ -111,38 +124,54 @@ class Version {
return $this->getPreReleaseSuffix()->isGreaterThan($version->getPreReleaseSuffix());
}
/**
* @return VersionNumber
*/
public function getMajor() {
public function getMajor(): VersionNumber {
return $this->major;
}
/**
* @return VersionNumber
*/
public function getMinor() {
public function getMinor(): VersionNumber {
return $this->minor;
}
/**
* @return VersionNumber
*/
public function getPatch() {
public function getPatch(): VersionNumber {
return $this->patch;
}
/**
* @param array $matches
* @psalm-assert-if-true BuildMetaData $this->buildMetadata
* @psalm-assert-if-true BuildMetaData $this->getBuildMetaData()
*/
private function parseVersion(array $matches) {
$this->major = new VersionNumber($matches['Major']);
$this->minor = new VersionNumber($matches['Minor']);
$this->patch = isset($matches['Patch']) ? new VersionNumber($matches['Patch']) : new VersionNumber(null);
public function hasBuildMetaData(): bool {
return $this->buildMetadata !== null;
}
if (isset($matches['PreReleaseSuffix'])) {
/**
* @throws NoBuildMetaDataException
*/
public function getBuildMetaData(): BuildMetaData {
if (!$this->hasBuildMetaData()) {
throw new NoBuildMetaDataException('No build metadata set');
}
return $this->buildMetadata;
}
/**
* @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']);
$this->patch = isset($matches['Patch']) ? new VersionNumber((int)$matches['Patch']) : new VersionNumber(0);
if (isset($matches['PreReleaseSuffix']) && $matches['PreReleaseSuffix'] !== '') {
$this->preReleaseSuffix = new PreReleaseSuffix($matches['PreReleaseSuffix']);
}
if (isset($matches['BuildMetadata'])) {
$this->buildMetadata = new BuildMetaData($matches['BuildMetadata']);
}
}
/**
@@ -150,23 +179,27 @@ class Version {
*
* @throws InvalidVersionException
*/
private function ensureVersionStringIsValid($version) {
private function ensureVersionStringIsValid($version): void {
$regex = '/^v?
(?<Major>(0|(?:[1-9][0-9]*)))
(?P<Major>0|[1-9]\d*)
\\.
(?<Minor>(0|(?:[1-9][0-9]*)))
(?P<Minor>0|[1-9]\d*)
(\\.
(?<Patch>(0|(?:[1-9][0-9]*)))
(?P<Patch>0|[1-9]\d*)
)?
(?:
-
(?<PreReleaseSuffix>(?:(dev|beta|b|RC|alpha|a|patch|p)\.?\d*))
)?
$/x';
(?<PreReleaseSuffix>(?:(dev|beta|b|rc|alpha|a|patch|p|pl)\.?\d*))
)?
(?:
\\+
(?P<BuildMetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-@]+)*)
)?
$/xi';
if (preg_match($regex, $version, $matches) !== 1) {
if (\preg_match($regex, $version, $matches) !== 1) {
throw new InvalidVersionException(
sprintf("Version string '%s' does not follow SemVer semantics", $version)
\sprintf("Version string '%s' does not follow SemVer semantics", $version)
);
}

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types = 1);
/*
* This file is part of PharIo\Version.
*
@@ -7,26 +7,20 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Version;
class VersionConstraintParser {
/**
* @param string $value
*
* @return VersionConstraint
*
* @throws UnsupportedVersionConstraintException
*/
public function parse($value) {
if (strpos($value, '||') !== false) {
public function parse(string $value): VersionConstraint {
if (\strpos($value, '|') !== false) {
return $this->handleOrGroup($value);
}
if (!preg_match('/^[\^~\*]?[\d.\*]+(?:-.*)?$/', $value)) {
if (!\preg_match('/^[\^~*]?v?[\d.*]+(?:-.*)?$/i', $value)) {
throw new UnsupportedVersionConstraintException(
sprintf('Version constraint %s is not supported.', $value)
\sprintf('Version constraint %s is not supported.', $value)
);
}
@@ -37,86 +31,85 @@ 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
*
* @return OrVersionConstraintGroup
*/
private function handleOrGroup($value) {
private function handleOrGroup(string $value): OrVersionConstraintGroup {
$constraints = [];
foreach (explode('||', $value) as $groupSegment) {
$constraints[] = $this->parse(trim($groupSegment));
foreach (\preg_split('{\s*\|\|?\s*}', \trim($value)) as $groupSegment) {
$constraints[] = $this->parse(\trim($groupSegment));
}
return new OrVersionConstraintGroup($value, $constraints);
}
/**
* @param string $value
*
* @return AndVersionConstraintGroup
*/
private function handleTildeOperator($value) {
$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
*
* @return AndVersionConstraintGroup
*/
private function handleCaretOperator($value) {
$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
);
}
}

View File

@@ -1,123 +1,88 @@
<?php
<?php declare(strict_types = 1);
namespace PharIo\Version;
class VersionConstraintValue {
/**
* @var VersionNumber
*/
/** @var VersionNumber */
private $major;
/**
* @var VersionNumber
*/
/** @var VersionNumber */
private $minor;
/**
* @var VersionNumber
*/
/** @var VersionNumber */
private $patch;
/**
* @var string
*/
/** @var string */
private $label = '';
/**
* @var string
*/
/** @var string */
private $buildMetaData = '';
/**
* @var string
*/
/** @var string */
private $versionString = '';
/**
* @param string $versionString
*/
public function __construct($versionString) {
public function __construct(string $versionString) {
$this->versionString = $versionString;
$this->parseVersion($versionString);
}
/**
* @return string
*/
public function getLabel() {
public function getLabel(): string {
return $this->label;
}
/**
* @return string
*/
public function getBuildMetaData() {
public function getBuildMetaData(): string {
return $this->buildMetaData;
}
/**
* @return string
*/
public function getVersionString() {
public function getVersionString(): string {
return $this->versionString;
}
/**
* @return VersionNumber
*/
public function getMajor() {
public function getMajor(): VersionNumber {
return $this->major;
}
/**
* @return VersionNumber
*/
public function getMinor() {
public function getMinor(): VersionNumber {
return $this->minor;
}
/**
* @return VersionNumber
*/
public function getPatch() {
public function getPatch(): VersionNumber {
return $this->patch;
}
/**
* @param $versionString
*/
private function parseVersion($versionString) {
private function parseVersion(string $versionString): void {
$this->extractBuildMetaData($versionString);
$this->extractLabel($versionString);
$this->stripPotentialVPrefix($versionString);
$versionSegments = explode('.', $versionString);
$this->major = new VersionNumber($versionSegments[0]);
$versionSegments = \explode('.', $versionString);
$this->major = new VersionNumber(\is_numeric($versionSegments[0]) ? (int)$versionSegments[0] : null);
$minorValue = isset($versionSegments[1]) ? $versionSegments[1] : null;
$patchValue = isset($versionSegments[2]) ? $versionSegments[2] : null;
$minorValue = isset($versionSegments[1]) && \is_numeric($versionSegments[1]) ? (int)$versionSegments[1] : null;
$patchValue = isset($versionSegments[2]) && \is_numeric($versionSegments[2]) ? (int)$versionSegments[2] : null;
$this->minor = new VersionNumber($minorValue);
$this->patch = new VersionNumber($patchValue);
}
/**
* @param string $versionString
*/
private function extractBuildMetaData(&$versionString) {
if (preg_match('/\+(.*)/', $versionString, $matches) == 1) {
private function extractBuildMetaData(string &$versionString): void {
if (\preg_match('/\+(.*)/', $versionString, $matches) === 1) {
$this->buildMetaData = $matches[1];
$versionString = str_replace($matches[0], '', $versionString);
$versionString = \str_replace($matches[0], '', $versionString);
}
}
/**
* @param string $versionString
*/
private function extractLabel(&$versionString) {
if (preg_match('/\-(.*)/', $versionString, $matches) == 1) {
$this->label = $matches[1];
$versionString = str_replace($matches[0], '', $versionString);
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(string &$versionString): void {
if ($versionString[0] !== 'v') {
return;
}
$versionString = \substr($versionString, 1);
}
}

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types = 1);
/*
* This file is part of PharIo\Version.
*
@@ -7,35 +7,22 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Version;
class VersionNumber {
/**
* @var int
*/
/** @var ?int */
private $value;
/**
* @param mixed $value
*/
public function __construct($value) {
if (is_numeric($value)) {
$this->value = $value;
}
public function __construct(?int $value) {
$this->value = $value;
}
/**
* @return bool
*/
public function isAny() {
public function isAny(): bool {
return $this->value === null;
}
/**
* @return int
*/
public function getValue() {
public function getValue(): ?int {
return $this->value;
}
}

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types = 1);
/*
* This file is part of PharIo\Version.
*
@@ -7,26 +7,17 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Version;
abstract class AbstractVersionConstraint implements VersionConstraint {
/**
* @var string
*/
private $originalValue = '';
/** @var string */
private $originalValue;
/**
* @param string $originalValue
*/
public function __construct($originalValue) {
public function __construct(string $originalValue) {
$this->originalValue = $originalValue;
}
/**
* @return string
*/
public function asString() {
public function asString(): string {
return $this->originalValue;
}
}

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types = 1);
/*
* This file is part of PharIo\Version.
*
@@ -7,31 +7,22 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Version;
class AndVersionConstraintGroup extends AbstractVersionConstraint {
/**
* @var VersionConstraint[]
*/
/** @var VersionConstraint[] */
private $constraints = [];
/**
* @param string $originalValue
* @param VersionConstraint[] $constraints
*/
public function __construct($originalValue, array $constraints) {
public function __construct(string $originalValue, array $constraints) {
parent::__construct($originalValue);
$this->constraints = $constraints;
}
/**
* @param Version $version
*
* @return bool
*/
public function complies(Version $version) {
public function complies(Version $version): bool {
foreach ($this->constraints as $constraint) {
if (!$constraint->complies($version)) {
return false;

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types = 1);
/*
* This file is part of PharIo\Version.
*
@@ -7,23 +7,14 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Version;
class AnyVersionConstraint implements VersionConstraint {
/**
* @param Version $version
*
* @return bool
*/
public function complies(Version $version) {
public function complies(Version $version): bool {
return true;
}
/**
* @return string
*/
public function asString() {
public function asString(): string {
return '*';
}
}

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types = 1);
/*
* This file is part of PharIo\Version.
*
@@ -7,16 +7,16 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Version;
class ExactVersionConstraint extends AbstractVersionConstraint {
/**
* @param Version $version
*
* @return bool
*/
public function complies(Version $version) {
return $this->asString() == $version->getVersionString();
public function complies(Version $version): bool {
$other = $version->getVersionString();
if ($version->hasBuildMetaData()) {
$other .= '+' . $version->getBuildMetaData()->asString();
}
return $this->asString() === $other;
}
}

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types = 1);
/*
* This file is part of PharIo\Version.
*
@@ -7,32 +7,20 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Version;
class GreaterThanOrEqualToVersionConstraint extends AbstractVersionConstraint {
/**
* @var Version
*/
/** @var Version */
private $minimalVersion;
/**
* @param string $originalValue
* @param Version $minimalVersion
*/
public function __construct($originalValue, Version $minimalVersion) {
public function __construct(string $originalValue, Version $minimalVersion) {
parent::__construct($originalValue);
$this->minimalVersion = $minimalVersion;
}
/**
* @param Version $version
*
* @return bool
*/
public function complies(Version $version) {
return $version->getVersionString() == $this->minimalVersion->getVersionString()
public function complies(Version $version): bool {
return $version->getVersionString() === $this->minimalVersion->getVersionString()
|| $version->isGreaterThan($this->minimalVersion);
}
}

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types = 1);
/*
* This file is part of PharIo\Version.
*
@@ -7,17 +7,14 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Version;
class OrVersionConstraintGroup extends AbstractVersionConstraint {
/**
* @var VersionConstraint[]
*/
/** @var VersionConstraint[] */
private $constraints = [];
/**
* @param string $originalValue
* @param string $originalValue
* @param VersionConstraint[] $constraints
*/
public function __construct($originalValue, array $constraints) {
@@ -26,12 +23,7 @@ class OrVersionConstraintGroup extends AbstractVersionConstraint {
$this->constraints = $constraints;
}
/**
* @param Version $version
*
* @return bool
*/
public function complies(Version $version) {
public function complies(Version $version): bool {
foreach ($this->constraints as $constraint) {
if ($constraint->complies($version)) {
return true;

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types = 1);
/*
* This file is part of PharIo\Version.
*
@@ -7,42 +7,27 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Version;
class SpecificMajorAndMinorVersionConstraint extends AbstractVersionConstraint {
/**
* @var int
*/
private $major = 0;
/** @var int */
private $major;
/**
* @var int
*/
private $minor = 0;
/** @var int */
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;
$this->minor = $minor;
}
/**
* @param Version $version
*
* @return bool
*/
public function complies(Version $version) {
if ($version->getMajor()->getValue() != $this->major) {
public function complies(Version $version): bool {
if ($version->getMajor()->getValue() !== $this->major) {
return false;
}
return $version->getMinor()->getValue() == $this->minor;
return $version->getMinor()->getValue() === $this->minor;
}
}

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types = 1);
/*
* This file is part of PharIo\Version.
*
@@ -7,31 +7,19 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Version;
class SpecificMajorVersionConstraint extends AbstractVersionConstraint {
/**
* @var int
*/
private $major = 0;
/** @var int */
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;
}
/**
* @param Version $version
*
* @return bool
*/
public function complies(Version $version) {
return $version->getMajor()->getValue() == $this->major;
public function complies(Version $version): bool {
return $version->getMajor()->getValue() === $this->major;
}
}

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types = 1);
/*
* This file is part of PharIo\Version.
*
@@ -7,20 +7,10 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Version;
interface VersionConstraint {
/**
* @param Version $version
*
* @return bool
*/
public function complies(Version $version);
/**
* @return string
*/
public function asString();
public function complies(Version $version): bool;
public function asString(): string;
}

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types = 1);
/*
* This file is part of PharIo\Version.
*
@@ -7,8 +7,9 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Version;
interface Exception {
use Throwable;
interface Exception extends Throwable {
}

View File

@@ -1,7 +1,5 @@
<?php
<?php declare(strict_types = 1);
namespace PharIo\Version;
class InvalidPreReleaseSuffixException extends \Exception implements Exception {
}

View File

@@ -1,5 +1,4 @@
<?php
<?php declare(strict_types = 1);
namespace PharIo\Version;
class InvalidVersionException extends \InvalidArgumentException implements Exception {

View File

@@ -0,0 +1,5 @@
<?php declare(strict_types = 1);
namespace PharIo\Version;
class NoBuildMetaDataException extends \Exception implements Exception {
}

View File

@@ -0,0 +1,5 @@
<?php declare(strict_types = 1);
namespace PharIo\Version;
class NoPreReleaseSuffixException extends \Exception implements Exception {
}

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types = 1);
/*
* This file is part of PharIo\Version.
*
@@ -7,7 +7,6 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Version;
final class UnsupportedVersionConstraintException extends \RuntimeException implements Exception {