From 4064551e7b8413ff48aad3ca3a77ac08aab3b7cd Mon Sep 17 00:00:00 2001 From: Ben Thomson Date: Wed, 10 Apr 2024 15:10:19 +0800 Subject: [PATCH] If package has no versions, do not convert to a detailed package --- src/Package/Collection.php | 8 +++++++- src/Package/Packagist.php | 4 ++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Package/Collection.php b/src/Package/Collection.php index 14bb088..02cee07 100644 --- a/src/Package/Collection.php +++ b/src/Package/Collection.php @@ -2,6 +2,8 @@ namespace Winter\Packager\Package; +use Winter\Packager\Exceptions\PackagistException; + /** * Package collection. * @@ -197,7 +199,11 @@ public function toDetailed(): static continue; } - $package = $package->toDetailed(); + try { + $package = $package->toDetailed(); + } catch (PackagistException $e) { + // If we can't get detailed information, just leave it as-is. + } } return $this; diff --git a/src/Package/Packagist.php b/src/Package/Packagist.php index af2c181..bd76665 100644 --- a/src/Package/Packagist.php +++ b/src/Package/Packagist.php @@ -74,6 +74,10 @@ public static function getPackage( } } + if (!count($versions)) { + throw new PackagistException('Package has no versions'); + } + if (is_null($version)) { return $versions[array_keys($versions)[0]]; }