From c97b7a9be5701ea606ef3eecb01016903f9d25ac Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Mon, 14 Jan 2019 16:37:33 +0100 Subject: [PATCH] Fix implementation of filterPackages --- src/Composer/Repository/ComposerRepository.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/Composer/Repository/ComposerRepository.php b/src/Composer/Repository/ComposerRepository.php index 829883b58..6e3994380 100644 --- a/src/Composer/Repository/ComposerRepository.php +++ b/src/Composer/Repository/ComposerRepository.php @@ -185,17 +185,25 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito private function filterPackages(array $packages, $constraint = null, $returnFirstMatch = false) { - $packages = array(); + if (null === $constraint) { + if ($returnFirstMatch) { + return reset($packages); + } + + return $packages; + } + + $filteredPackages = array(); foreach ($packages as $package) { - $pkgConstraint = new Constraint('==', $package->getVersion()); - if (null === $constraint || $constraint->matches($pkgConstraint)) { + + if ($constraint->matches($pkgConstraint)) { if ($returnFirstMatch) { return $package; } - $packages[] = $package; + $filteredPackages[] = $package; } } @@ -203,7 +211,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito return null; } - return $packages; + return $filteredPackages; } public function getPackages()