From 90873140c187e0a209128e1cf4239147badfcffa Mon Sep 17 00:00:00 2001 From: Jan Gantzert Date: Sun, 15 Sep 2024 16:32:34 +0200 Subject: [PATCH 1/2] use first non development version as download if possible --- src/Entity/Package.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Entity/Package.php b/src/Entity/Package.php index a95777de..f82a2656 100644 --- a/src/Entity/Package.php +++ b/src/Entity/Package.php @@ -536,7 +536,18 @@ public function getVersions() public function getVersionByReference(string $reference): ?Version { - return $this->versions->findFirst(fn($k, $v) => $v->getReference() === $reference); + /** @var ArrayCollection[] $matchedVersions */ + $matchedVersions = $this->versions->partition(fn($k, $v) => $v->getReference() === $reference); + + if (count($matchedVersions) > 0) { + /** @var Version $matchedVersion */ + foreach ($matchedVersions[0] as $matchedVersion) { + if ($matchedVersion->isDevelopment() === false) { + return $matchedVersion; + } + } + } + return $matchedVersions[0]->first(); } /** From a6599482348f9c273cc05e091f3c1b428ba5488d Mon Sep 17 00:00:00 2001 From: Uladzimir Tsykun Date: Sat, 2 Nov 2024 12:12:20 +0100 Subject: [PATCH 2/2] Fix use first non development version PR --- src/Entity/Package.php | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/Entity/Package.php b/src/Entity/Package.php index f82a2656..2544559b 100644 --- a/src/Entity/Package.php +++ b/src/Entity/Package.php @@ -536,18 +536,15 @@ public function getVersions() public function getVersionByReference(string $reference): ?Version { - /** @var ArrayCollection[] $matchedVersions */ - $matchedVersions = $this->versions->partition(fn($k, $v) => $v->getReference() === $reference); - - if (count($matchedVersions) > 0) { - /** @var Version $matchedVersion */ - foreach ($matchedVersions[0] as $matchedVersion) { - if ($matchedVersion->isDevelopment() === false) { - return $matchedVersion; - } + $matchedVersions = $this->versions->filter(static fn(Version $v) => $v->getReference() === $reference); + + foreach ($matchedVersions as $matchedVersion) { + if ($matchedVersion->isDevelopment() === false) { + return $matchedVersion; } } - return $matchedVersions[0]->first(); + + return $matchedVersions->first() ?: null; } /**