Skip to content

Commit

Permalink
Add detection of constraints which do not match anything in validate …
Browse files Browse the repository at this point in the history
…command, fixes #11802 (#11829)
  • Loading branch information
Seldaek committed Feb 6, 2024
1 parent 8a69c05 commit 0f70c0a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Composer/Package/Loader/ValidatingArrayLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
use Composer\Semver\Constraint\Constraint;
use Composer\Package\Version\VersionParser;
use Composer\Repository\PlatformRepository;
use Composer\Semver\Constraint\MatchNoneConstraint;
use Composer\Semver\Intervals;
use Composer\Spdx\SpdxLicenses;

/**
Expand Down Expand Up @@ -290,6 +292,11 @@ public function load(array $config, string $class = 'Composer\Package\CompletePa
) {
$this->warnings[] = $linkType.'.'.$package.' : exact version constraints ('.$constraint.') should be avoided if the package follows semantic versioning';
}

$compacted = Intervals::compactConstraint($linkConstraint);
if ($compacted instanceof MatchNoneConstraint) {
$this->warnings[] = $linkType.'.'.$package.' : this version constraint cannot possibly match anything ('.$constraint.')';
}
}

if ($linkType === 'conflict' && isset($this->config['replace']) && $keys = array_intersect_key($this->config['replace'], $this->config['conflict'])) {
Expand Down
14 changes: 14 additions & 0 deletions tests/Composer/Test/Package/Loader/ValidatingArrayLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,20 @@ public static function warningProvider(): array
],
false,
],
[
[
'name' => 'foo/bar',
'require' => [
'foo/baz' => '>1, <0.5',
'bar/baz' => 'dev-main, >0.5',
],
],
[
'require.foo/baz : this version constraint cannot possibly match anything (>1, <0.5)',
'require.bar/baz : this version constraint cannot possibly match anything (dev-main, >0.5)',
],
false,
],
[
[
'name' => 'foo/bar',
Expand Down

0 comments on commit 0f70c0a

Please sign in to comment.