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
61d0a73
commit f7b6c27
Showing
40 changed files
with
1,673 additions
and
48 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,93 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<files psalm-version="5.18.0@b113f3ed0259fd6e212d87c3df80eec95a6abf19"/> | ||
<files psalm-version="5.18.0@b113f3ed0259fd6e212d87c3df80eec95a6abf19"> | ||
<file src="test/DataGenerator/AggregateGenerator.php"> | ||
<PropertyTypeCoercion> | ||
<code>$generators</code> | ||
</PropertyTypeCoercion> | ||
</file> | ||
<file src="test/DataGenerator/Composer/StabilityFlagGenerator.php"> | ||
<UnusedClass> | ||
<code>StabilityFlagGenerator</code> | ||
</UnusedClass> | ||
</file> | ||
<file src="test/DataGenerator/Composer/TildeVersionRangeGenerator.php"> | ||
<MixedArgument> | ||
<code>$otherValue</code> | ||
<code>$otherValue</code> | ||
<code>$otherValue</code> | ||
<code>$valuesWithMajor</code> | ||
<code>$valuesWithMajorAndMinor</code> | ||
<code>$valuesWithMajorMinorAndPatch</code> | ||
<code>$valuesWithMajorMinorPatchAndFourth</code> | ||
</MixedArgument> | ||
<MixedAssignment> | ||
<code>$otherValue</code> | ||
<code>$otherValue</code> | ||
<code>$otherValue</code> | ||
</MixedAssignment> | ||
<UndefinedVariable> | ||
<code>$valuesWithMajor</code> | ||
<code>$valuesWithMajorAndMinor</code> | ||
<code>$valuesWithMajorMinorAndPatch</code> | ||
<code>$valuesWithMajorMinorPatchAndFourth</code> | ||
</UndefinedVariable> | ||
<UnusedMethod> | ||
<code>foo</code> | ||
</UnusedMethod> | ||
</file> | ||
<file src="test/DataGenerator/SemanticVersionGenerator.php"> | ||
<UnusedClass> | ||
<code>SemanticVersionGenerator</code> | ||
</UnusedClass> | ||
</file> | ||
<file src="test/DataGenerator/ValueGenerator.php"> | ||
<PropertyTypeCoercion> | ||
<code>$values</code> | ||
</PropertyTypeCoercion> | ||
</file> | ||
<file src="test/DataProvider/Composer/CaretVersionRangeProvider.php"> | ||
<PossiblyUnusedMethod> | ||
<code>valid</code> | ||
</PossiblyUnusedMethod> | ||
</file> | ||
<file src="test/DataProvider/Composer/ExactVersionConstraintProvider.php"> | ||
<PossiblyUnusedMethod> | ||
<code>valid</code> | ||
</PossiblyUnusedMethod> | ||
</file> | ||
<file src="test/DataProvider/Composer/GreaterThanOrEqualVersionRangeProvider.php"> | ||
<PossiblyUnusedMethod> | ||
<code>valid</code> | ||
</PossiblyUnusedMethod> | ||
</file> | ||
<file src="test/DataProvider/Composer/GreaterThanVersionRangeProvider.php"> | ||
<PossiblyUnusedMethod> | ||
<code>valid</code> | ||
</PossiblyUnusedMethod> | ||
</file> | ||
<file src="test/DataProvider/Composer/HyphenatedVersionRangeProvider.php"> | ||
<PossiblyUnusedMethod> | ||
<code>valid</code> | ||
</PossiblyUnusedMethod> | ||
</file> | ||
<file src="test/DataProvider/Composer/LessThanOrEqualVersionRangeProvider.php"> | ||
<PossiblyUnusedMethod> | ||
<code>valid</code> | ||
</PossiblyUnusedMethod> | ||
</file> | ||
<file src="test/DataProvider/Composer/LessThanVersionRangeProvider.php"> | ||
<PossiblyUnusedMethod> | ||
<code>valid</code> | ||
</PossiblyUnusedMethod> | ||
</file> | ||
<file src="test/DataProvider/Composer/TildeVersionRangeProvider.php"> | ||
<PossiblyUnusedMethod> | ||
<code>valid</code> | ||
</PossiblyUnusedMethod> | ||
</file> | ||
<file src="test/DataProvider/Composer/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,68 @@ | ||
<?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 = <<<'PCRE' | ||
/^ | ||
~ | ||
v? | ||
( | ||
# classic version with up to four parts | ||
( | ||
(0|[1-9]\d*)(\.(0|[1-9]\d*)){0,3} | ||
) | | ||
# classic version with up to four parts, optional separator, and stability flag | ||
( | ||
(0|[1-9]\d*)(\.(0|[1-9]\d*)){0,3}[-._]?(a|alpha|b|beta|dev|p|patch|pl|rc|RC|stable) | ||
) | | ||
# classic version with up to four parts, optional separator, stability flag (except "dev"), optional separator, and build number | ||
( | ||
(0|[1-9]\d*)(\.(0|[1-9]\d*)){0,3}[-._]?(a|alpha|b|beta|p|patch|pl|rc|RC|stable)[.-]?\d+ | ||
) | | ||
# version-like branch | ||
( | ||
(0|[1-9]\d*)(\.(0|[1-9]\d*)){0,2}\.x[-._]?dev | ||
) | ||
) | ||
$/xJ | ||
PCRE; | ||
|
||
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\DataGenerator; | ||
|
||
final class AffixingGenerator implements StringGenerator | ||
{ | ||
public function __construct( | ||
private readonly StringGenerator $prefixGenerator, | ||
private readonly StringGenerator $valueGenerator, | ||
private readonly StringGenerator $suffixGenerator, | ||
) { | ||
} | ||
|
||
public function generate(): \Generator | ||
{ | ||
foreach ($this->prefixGenerator->generate() as $prefix) { | ||
foreach ($this->valueGenerator->generate() as $value) { | ||
foreach ($this->suffixGenerator->generate() as $suffix) { | ||
yield \sprintf( | ||
'%s%s%s', | ||
$prefix, | ||
$value, | ||
$suffix, | ||
); | ||
} | ||
} | ||
} | ||
} | ||
} |
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,36 @@ | ||
<?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\DataGenerator; | ||
|
||
final class AggregateGenerator implements StringGenerator | ||
{ | ||
/** | ||
* @var list<StringGenerator> | ||
*/ | ||
private readonly array $generators; | ||
|
||
public function __construct(StringGenerator ...$generators) | ||
{ | ||
$this->generators = $generators; | ||
} | ||
|
||
public function generate(): \Generator | ||
{ | ||
foreach ($this->generators as $generator) { | ||
foreach ($generator->generate() as $value) { | ||
yield $value; | ||
} | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
test/DataGenerator/Composer/CaretVersionRangeGenerator.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,39 @@ | ||
<?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\DataGenerator\Composer; | ||
|
||
use Ergebnis\VersionConstraint\Test; | ||
|
||
/** | ||
* @see https://getcomposer.org/doc/articles/versions.md#exact-version-constraint | ||
*/ | ||
final class CaretVersionRangeGenerator implements Test\DataGenerator\StringGenerator | ||
{ | ||
private readonly Test\DataGenerator\StringGenerator $generator; | ||
|
||
public function __construct() | ||
{ | ||
$this->generator = new Test\DataGenerator\PrefixingGenerator( | ||
new Test\DataGenerator\ValueGenerator('^'), | ||
new Test\DataGenerator\Composer\ExactVersionConstraintGenerator(), | ||
); | ||
} | ||
|
||
public function generate(): \Generator | ||
{ | ||
foreach ($this->generator->generate() as $caretVersionRange) { | ||
yield $caretVersionRange; | ||
} | ||
} | ||
} |
Oops, something went wrong.