Skip to content

Commit 1b95a8f

Browse files
authored
Matrix: Early quit if $constraint is invalid (#61)
1 parent 1319186 commit 1b95a8f

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/Matrices/Matrix.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace TypistTech\PhpMatrix\Matrices;
66

77
use Composer\Semver\Semver;
8+
use Composer\Semver\VersionParser;
89
use TypistTech\PhpMatrix\Exceptions\UnexpectedValueException as AppUnexpectedValueException;
910
use TypistTech\PhpMatrix\Releases\ReleasesInterface;
1011
use UnexpectedValueException;
@@ -13,6 +14,7 @@
1314
{
1415
public function __construct(
1516
private ReleasesInterface $releases,
17+
private VersionParser $versionParser = new VersionParser(),
1618
) {}
1719

1820
/**
@@ -21,6 +23,9 @@ public function __construct(
2123
public function satisfiedBy(string $constraint): array
2224
{
2325
try {
26+
// Validate constraint before passing to Semver::satisfiedBy();
27+
$this->versionParser->parseConstraints($constraint);
28+
2429
return Semver::satisfiedBy(
2530
$this->releases->all(),
2631
$constraint

0 commit comments

Comments
 (0)