generated from ergebnis/php-package-template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhancement: Implement Composer\TildeVersionRange
- Loading branch information
1 parent
a8d8d40
commit 4d91170
Showing
16 changed files
with
630 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,51 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<files psalm-version="5.18.0@b113f3ed0259fd6e212d87c3df80eec95a6abf19"/> | ||
<files psalm-version="5.18.0@b113f3ed0259fd6e212d87c3df80eec95a6abf19"> | ||
<file src="test/DataProvider/CaretVersionRangeProvider.php"> | ||
<PossiblyUnusedMethod> | ||
<code>valid</code> | ||
</PossiblyUnusedMethod> | ||
</file> | ||
<file src="test/DataProvider/GreaterThanOrEqualVersionRangeProvider.php"> | ||
<PossiblyUnusedMethod> | ||
<code>valid</code> | ||
</PossiblyUnusedMethod> | ||
</file> | ||
<file src="test/DataProvider/GreaterThanVersionRangeProvider.php"> | ||
<PossiblyUnusedMethod> | ||
<code>valid</code> | ||
</PossiblyUnusedMethod> | ||
</file> | ||
<file src="test/DataProvider/HyphenatedVersionRangeProvider.php"> | ||
<PossiblyUnusedMethod> | ||
<code>valid</code> | ||
</PossiblyUnusedMethod> | ||
</file> | ||
<file src="test/DataProvider/LessThanOrEqualVersionRangeProvider.php"> | ||
<PossiblyUnusedMethod> | ||
<code>valid</code> | ||
</PossiblyUnusedMethod> | ||
</file> | ||
<file src="test/DataProvider/LessThanVersionRangeProvider.php"> | ||
<PossiblyUnusedMethod> | ||
<code>valid</code> | ||
</PossiblyUnusedMethod> | ||
</file> | ||
<file src="test/DataProvider/TildeVersionRangeProvider.php"> | ||
<MixedArgument> | ||
<code>$otherValue</code> | ||
<code>$otherValue</code> | ||
</MixedArgument> | ||
<MixedAssignment> | ||
<code>$otherValue</code> | ||
<code>$otherValue</code> | ||
</MixedAssignment> | ||
<PossiblyUnusedMethod> | ||
<code>valid</code> | ||
</PossiblyUnusedMethod> | ||
</file> | ||
<file src="test/DataProvider/WildCardVersionRangeProvider.php"> | ||
<PossiblyUnusedMethod> | ||
<code>valid</code> | ||
</PossiblyUnusedMethod> | ||
</file> | ||
</files> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) 2017-2023 Andreas Möller | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE.md file that was distributed with this source code. | ||
* | ||
* @see https://github.com/ergebnis/version-constraint | ||
*/ | ||
|
||
namespace Ergebnis\VersionConstraint\Composer; | ||
|
||
final class TildeVersionRange | ||
{ | ||
private const REGEX = '/^~(?P<prefix>v)?(?P<major>0|[1-9]\d*)(\.(?P<minor>0|[1-9]\d*)(\.(?P<patch>0|[1-9]\d*)(\.(?P<fourth>0|[1-9]\d*))?)?)?(-(?P<stabilityflag>(alpha|beta|dev|RC|stable)))?$/'; | ||
|
||
private function __construct(private readonly string $value) | ||
{ | ||
} | ||
|
||
/** | ||
* @throws Exception\InvalidTildeVersionRange | ||
*/ | ||
public static function fromString(string $value): self | ||
{ | ||
if (1 !== \preg_match(self::REGEX, $value)) { | ||
throw Exception\InvalidTildeVersionRange::fromString($value); | ||
} | ||
|
||
return new self($value); | ||
} | ||
|
||
public function toString(): string | ||
{ | ||
return $this->value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) 2017-2023 Andreas Möller | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE.md file that was distributed with this source code. | ||
* | ||
* @see https://github.com/ergebnis/version-constraint | ||
*/ | ||
|
||
namespace Ergebnis\VersionConstraint\Test\DataProvider; | ||
|
||
final class CaretVersionRangeProvider | ||
{ | ||
/** | ||
* @see https://getcomposer.org/doc/articles/versions.md#caret-version-range- | ||
* | ||
* @return \Generator<string, array{0: string}> | ||
*/ | ||
public static function valid(): \Generator | ||
{ | ||
$values = [ | ||
'^1', | ||
'^1.0', | ||
'^1.0.0', | ||
'^v1', | ||
'^v1.0', | ||
'^v1.0.0', | ||
]; | ||
|
||
foreach ($values as $value) { | ||
yield $value => [ | ||
$value, | ||
]; | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
test/DataProvider/GreaterThanOrEqualVersionRangeProvider.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) 2017-2023 Andreas Möller | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE.md file that was distributed with this source code. | ||
* | ||
* @see https://github.com/ergebnis/version-constraint | ||
*/ | ||
|
||
namespace Ergebnis\VersionConstraint\Test\DataProvider; | ||
|
||
final class GreaterThanOrEqualVersionRangeProvider | ||
{ | ||
/** | ||
* @see https://getcomposer.org/doc/articles/versions.md#version-range | ||
* | ||
* @return \Generator<string, array{0: string}> | ||
*/ | ||
public static function valid(): \Generator | ||
{ | ||
$values = [ | ||
'>=1', | ||
'>=1.0', | ||
'>=1.0.0', | ||
'>=v1', | ||
'>=v1.0', | ||
'>=v1.0.0', | ||
]; | ||
|
||
foreach ($values as $value) { | ||
yield $value => [ | ||
$value, | ||
]; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) 2017-2023 Andreas Möller | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE.md file that was distributed with this source code. | ||
* | ||
* @see https://github.com/ergebnis/version-constraint | ||
*/ | ||
|
||
namespace Ergebnis\VersionConstraint\Test\DataProvider; | ||
|
||
final class GreaterThanVersionRangeProvider | ||
{ | ||
/** | ||
* @see https://getcomposer.org/doc/articles/versions.md#version-range | ||
* | ||
* @return \Generator<string, array{0: string}> | ||
*/ | ||
public static function valid(): \Generator | ||
{ | ||
$values = [ | ||
'>1', | ||
'>1.0', | ||
'>1.0.0', | ||
'>v1', | ||
'>v1.0', | ||
'>v1.0.0', | ||
]; | ||
|
||
foreach ($values as $value) { | ||
yield $value => [ | ||
$value, | ||
]; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) 2017-2023 Andreas Möller | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE.md file that was distributed with this source code. | ||
* | ||
* @see https://github.com/ergebnis/version-constraint | ||
*/ | ||
|
||
namespace Ergebnis\VersionConstraint\Test\DataProvider; | ||
|
||
final class HyphenatedVersionRangeProvider | ||
{ | ||
/** | ||
* @see https://getcomposer.org/doc/articles/versions.md#hyphenated-version-range- | ||
* | ||
* @return \Generator<string, array{0: string}> | ||
*/ | ||
public static function valid(): \Generator | ||
{ | ||
$leftValues = [ | ||
'1', | ||
'1.0', | ||
'1.0.0', | ||
'v1', | ||
'v1.0', | ||
'v1.0.0', | ||
]; | ||
|
||
$rightValues = [ | ||
'2', | ||
'2.0', | ||
'2.0.0', | ||
'v2', | ||
'v2.0', | ||
'v2.0.0', | ||
]; | ||
|
||
foreach ($leftValues as $leftValue) { | ||
foreach ($rightValues as $rightValue) { | ||
$value = \sprintf( | ||
'%s - %s', | ||
$leftValue, | ||
$rightValue, | ||
); | ||
|
||
yield $value => [ | ||
$value, | ||
]; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) 2017-2023 Andreas Möller | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE.md file that was distributed with this source code. | ||
* | ||
* @see https://github.com/ergebnis/version-constraint | ||
*/ | ||
|
||
namespace Ergebnis\VersionConstraint\Test\DataProvider; | ||
|
||
final class LessThanOrEqualVersionRangeProvider | ||
{ | ||
/** | ||
* @see https://getcomposer.org/doc/articles/versions.md#version-range | ||
* | ||
* @return \Generator<string, array{0: string}> | ||
*/ | ||
public static function valid(): \Generator | ||
{ | ||
$values = [ | ||
'<=1', | ||
'<=1.0', | ||
'<=1.0.0', | ||
'<=v1', | ||
'<=v1.0', | ||
'<=v1.0.0', | ||
]; | ||
|
||
foreach ($values as $value) { | ||
yield $value => [ | ||
$value, | ||
]; | ||
} | ||
} | ||
} |
Oops, something went wrong.