From 9f893cc5e297c4f1a12dfebcb64fce3dacffc408 Mon Sep 17 00:00:00 2001 From: core23 Date: Wed, 5 Jun 2024 18:18:09 +0200 Subject: [PATCH] Internal refactoring --- src/Version/Persister/TagPersister.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/Version/Persister/TagPersister.php b/src/Version/Persister/TagPersister.php index 17353db..983e8ce 100644 --- a/src/Version/Persister/TagPersister.php +++ b/src/Version/Persister/TagPersister.php @@ -48,12 +48,6 @@ public function getCurrentVersion(Context $context): string // Extract versions from tags and sort them $versions = $this->getVersionFromTags($tags, $context); - if ([] === $versions) { - throw new NoReleaseFoundException('No versions found in tag list'); - } - - usort($versions, [$context->versionGenerator, 'compareVersions']); - if ($this->versionedBranch) { $branchVersions = $this->getPrefixedVersions($context, $versions); @@ -62,6 +56,8 @@ public function getCurrentVersion(Context $context): string } } + \assert([] !== $versions); + return array_pop($versions); } @@ -102,10 +98,17 @@ private function getVersionFromTag(string $tagName, Context $context): string private function getVersionFromTags(array $tags, Context $context): array { $versions = []; + foreach ($tags as $tag) { $versions[] = $this->getVersionFromTag($tag, $context); } + if ([] === $versions) { + throw new NoReleaseFoundException('No versions found in tag list'); + } + + usort($versions, [$context->versionGenerator, 'compareVersions']); + return $versions; }