1
0
Fork 0

Refactor check-platform-reqs to use InstalledRepository and look for providers as well as platform packages, fixes #8645, closes #8676

Co-authored-by: Ellis <eantaya@nuglif.com>
Co-authored-by: Jordi Boggiano <j.boggiano@seld.be>
pull/8684/head
Jordi Boggiano 2020-03-10 14:53:42 +01:00
parent d63eb8179e
commit 2445ef5e1f
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
1 changed files with 58 additions and 45 deletions

View File

@ -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,33 +82,54 @@ EOT
*/
foreach ($requires as $require => $links) {
if (preg_match(PlatformRepository::PLATFORM_PACKAGE_REGEX, $require)) {
if (isset($currentPlatformPackageMap[$require])) {
$pass = true;
$version = $currentPlatformPackageMap[$require]->getVersion();
$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(new Constraint('=', $version))) {
$results[] = array(
$currentPlatformPackageMap[$require]->getPrettyName(),
$currentPlatformPackageMap[$require]->getPrettyVersion(),
if (!$link->getConstraint()->matches($candidateConstraint)) {
$reqResults[] = array(
$candidate->getName() === $require ? $candidate->getPrettyName() : $require,
$candidateConstraint->getPrettyString(),
$link,
'<error>failed</error>',
'<error>failed</error>'.($candidate->getName() === $require ? '' : ' <comment>provided by '.$candidate->getPrettyName().'</comment>'),
);
$pass = false;
$exitCode = max($exitCode, 1);
// 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,
'<info>success</info>',
'<info>success</info>'.($candidate->getName() === $require ? '' : ' <comment>provided by '.$candidate->getPrettyName().'</comment>'),
);
// candidate matched, skip to next requirement
continue 2;
}
} else {
// show the first error from every failed candidate
$results = array_merge($results, $reqResults);
$exitCode = max($exitCode, 1);
continue;
}
$results[] = array(
$require,
'n/a',
@ -126,7 +140,6 @@ EOT
$exitCode = max($exitCode, 2);
}
}
}
$this->printTable($output, $results);