1
0
Fork 0
mirror of https://github.com/composer/composer synced 2025-05-11 09:32:55 +00:00

Add a warning for unbound constraints in the validating loader

Closes #2165
This commit is contained in:
Christophe Coevoet 2013-10-12 02:29:16 +02:00
parent 9dcada5e25
commit 6cc95c43e3
2 changed files with 42 additions and 1 deletions

View file

@ -14,6 +14,7 @@ namespace Composer\Package\Loader;
use Composer\Package;
use Composer\Package\BasePackage;
use Composer\Package\LinkConstraint\VersionConstraint;
use Composer\Package\Version\VersionParser;
/**
@ -142,6 +143,8 @@ class ValidatingArrayLoader implements LoaderInterface
}
}
$unboundConstraint = new VersionConstraint('=', $this->versionParser->normalize('dev-master'));
foreach (array_keys(BasePackage::$supportedLinkTypes) as $linkType) {
if ($this->validateArray($linkType) && isset($this->config[$linkType])) {
foreach ($this->config[$linkType] as $package => $constraint) {
@ -153,13 +156,27 @@ class ValidatingArrayLoader implements LoaderInterface
unset($this->config[$linkType][$package]);
} elseif ('self.version' !== $constraint) {
try {
$this->versionParser->parseConstraints($constraint);
$linkConstraint = $this->versionParser->parseConstraints($constraint);
} catch (\Exception $e) {
$this->errors[] = $linkType.'.'.$package.' : invalid version constraint ('.$e->getMessage().')';
unset($this->config[$linkType][$package]);
continue;
}
if ('conflict' === $linkType || 'require-dev' === $linkType) {
continue; // conflict can be unbound, and require-dev constraints will not impact shared libraries as they are root-only
}
if ($linkConstraint->matches($unboundConstraint)) {
$this->warnings[] = $linkType.'.'.$package.' : unbound version constraint detected ('.$constraint.')';
unset($this->config[$linkType][$package]);
}
}
}
if (empty($this->config[$linkType])) {
unset($this->config[$linkType]);
}
}
}