Skip to content

Commit 36ea4a9

Browse files
committed
Ensure that we don't use a dynamic Iterator#current() call
1 parent d8b4a3b commit 36ea4a9

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

composer.lock

+12-15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Git/PickLastMinorVersionFromCollection.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
use Symfony\Component\Process\Exception\RuntimeException;
99
use Version\Version;
1010
use Version\VersionsCollection;
11+
use function iterator_to_array;
12+
use function reset;
1113

1214
final class PickLastMinorVersionFromCollection implements PickVersionFromVersionCollection
1315
{
@@ -20,14 +22,18 @@ public function forVersions(VersionsCollection $versions) : Version
2022
{
2123
$versions->sort(VersionsCollection::SORT_DESC);
2224

25+
/** @var Version[] $versionsAsArray */
26+
$versionsAsArray = iterator_to_array($versions->getIterator());
2327
/** @var Version $lastVersion */
24-
$lastVersion = $versions->getIterator()->current();
28+
$lastVersion = reset($versionsAsArray);
2529
$previousVersionInIteration = $lastVersion;
30+
2631
/** @var Version $version */
2732
foreach ($versions as $version) {
2833
if ($lastVersion->getMinor() !== $version->getMinor()) {
2934
return $previousVersionInIteration;
3035
}
36+
3137
$previousVersionInIteration = $version;
3238
}
3339

0 commit comments

Comments
 (0)