1
0
Fork 0

Add detection of constraints which do not match anything in validate command, fixes #11802 (#11829)

pull/11895/head
Jordi Boggiano 2024-02-06 12:57:52 +01:00 committed by GitHub
parent 8a69c0555b
commit 0f70c0a9c9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 0 deletions

View File

@ -17,6 +17,8 @@ use Composer\Pcre\Preg;
use Composer\Semver\Constraint\Constraint; use Composer\Semver\Constraint\Constraint;
use Composer\Package\Version\VersionParser; use Composer\Package\Version\VersionParser;
use Composer\Repository\PlatformRepository; use Composer\Repository\PlatformRepository;
use Composer\Semver\Constraint\MatchNoneConstraint;
use Composer\Semver\Intervals;
use Composer\Spdx\SpdxLicenses; use Composer\Spdx\SpdxLicenses;
/** /**
@ -290,6 +292,11 @@ class ValidatingArrayLoader implements LoaderInterface
) { ) {
$this->warnings[] = $linkType.'.'.$package.' : exact version constraints ('.$constraint.') should be avoided if the package follows semantic versioning'; $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'])) { if ($linkType === 'conflict' && isset($this->config['replace']) && $keys = array_intersect_key($this->config['replace'], $this->config['conflict'])) {

View File

@ -480,6 +480,20 @@ class ValidatingArrayLoaderTest extends TestCase
], ],
false, 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', 'name' => 'foo/bar',