diff --git a/src/Composer/Command/CheckPlatformReqsCommand.php b/src/Composer/Command/CheckPlatformReqsCommand.php
index 195a2c490..eba6d0946 100644
--- a/src/Composer/Command/CheckPlatformReqsCommand.php
+++ b/src/Composer/Command/CheckPlatformReqsCommand.php
@@ -20,6 +20,7 @@ use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Composer\Repository\PlatformRepository;
+use Composer\Repository\InstalledRepository;
class CheckPlatformReqsCommand extends BaseCommand
{
@@ -48,12 +49,13 @@ EOT
$requires = $composer->getPackage()->getRequires();
if ($input->getOption('no-dev')) {
- $dependencies = $composer->getLocker()->getLockedRepository(!$input->getOption('no-dev'))->getPackages();
+ $installedRepo = $composer->getLocker()->getLockedRepository(!$input->getOption('no-dev'));
+ $dependencies = $installedRepo->getPackages();
} else {
- $dependencies = $composer->getRepositoryManager()->getLocalRepository()->getPackages();
+ $installedRepo = $composer->getRepositoryManager()->getLocalRepository();
// fallback to lockfile if installed repo is empty
- if (!$dependencies) {
- $dependencies = $composer->getLocker()->getLockedRepository(true)->getPackages();
+ if (!$installedRepo->getPackages()) {
+ $installedRepo = $composer->getLocker()->getLockedRepository(true);
}
$requires += $composer->getPackage()->getDevRequires();
}
@@ -61,7 +63,8 @@ EOT
$requires[$require] = array($link);
}
- foreach ($dependencies as $package) {
+ $installedRepo = new InstalledRepository(array($installedRepo));
+ foreach ($installedRepo->getPackages() as $package) {
foreach ($package->getRequires() as $require => $link) {
$requires[$require][] = $link;
}
@@ -69,19 +72,9 @@ EOT
ksort($requires);
- $platformRepo = new PlatformRepository(array(), array());
- $currentPlatformPackages = $platformRepo->getPackages();
- $currentPlatformPackageMap = array();
-
- /**
- * @var PackageInterface $currentPlatformPackage
- */
- foreach ($currentPlatformPackages as $currentPlatformPackage) {
- $currentPlatformPackageMap[$currentPlatformPackage->getName()] = $currentPlatformPackage;
- }
+ $installedRepo->addRepository(new PlatformRepository(array(), array()));
$results = array();
-
$exitCode = 0;
/**
@@ -89,42 +82,62 @@ EOT
*/
foreach ($requires as $require => $links) {
if (preg_match(PlatformRepository::PLATFORM_PACKAGE_REGEX, $require)) {
- if (isset($currentPlatformPackageMap[$require])) {
- $pass = true;
- $version = $currentPlatformPackageMap[$require]->getVersion();
-
- foreach ($links as $link) {
- if (!$link->getConstraint()->matches(new Constraint('=', $version))) {
- $results[] = array(
- $currentPlatformPackageMap[$require]->getPrettyName(),
- $currentPlatformPackageMap[$require]->getPrettyVersion(),
- $link,
- 'failed',
- );
- $pass = false;
-
- $exitCode = max($exitCode, 1);
+ $candidates = $installedRepo->findPackagesWithReplacersAndProviders($require);
+ if ($candidates) {
+ $reqResults = array();
+ foreach ($candidates as $candidate) {
+ if ($candidate->getName() === $require) {
+ $candidateConstraint = new Constraint('=', $candidate->getVersion());
+ $candidateConstraint->setPrettyString($candidate->getPrettyVersion());
+ } else {
+ foreach (array_merge($candidate->getProvides(), $candidate->getReplaces()) as $link) {
+ if ($link->getTarget() === $require) {
+ $candidateConstraint = $link->getConstraint();
+ break;
+ }
+ }
+ }
+
+ foreach ($links as $link) {
+ if (!$link->getConstraint()->matches($candidateConstraint)) {
+ $reqResults[] = array(
+ $candidate->getName() === $require ? $candidate->getPrettyName() : $require,
+ $candidateConstraint->getPrettyString(),
+ $link,
+ 'failed'.($candidate->getName() === $require ? '' : ' provided by '.$candidate->getPrettyName().''),
+ );
+
+ // skip to next candidate
+ continue 2;
+ }
}
- }
- if ($pass) {
$results[] = array(
- $currentPlatformPackageMap[$require]->getPrettyName(),
- $currentPlatformPackageMap[$require]->getPrettyVersion(),
+ $candidate->getName() === $require ? $candidate->getPrettyName() : $require,
+ $candidateConstraint->getPrettyString(),
null,
- 'success',
+ 'success'.($candidate->getName() === $require ? '' : ' provided by '.$candidate->getPrettyName().''),
);
- }
- } else {
- $results[] = array(
- $require,
- 'n/a',
- $links[0],
- 'missing',
- );
- $exitCode = max($exitCode, 2);
+ // candidate matched, skip to next requirement
+ continue 2;
+ }
+
+ // show the first error from every failed candidate
+ $results = array_merge($results, $reqResults);
+ $exitCode = max($exitCode, 1);
+
+ continue;
}
+
+ $results[] = array(
+ $require,
+ 'n/a',
+ $links[0],
+ 'missing',
+ );
+
+ $exitCode = max($exitCode, 2);
}
}