| Total Lines | 24 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 24 | public function forVersions(VersionCollection $versions) : Version |
||
| 25 | { |
||
| 26 | Assert::that($versions->count()) |
||
| 27 | ->greaterThan(0, 'Cannot determine latest minor version from an empty collection'); |
||
| 28 | |||
| 29 | $stableVersions = $versions->matching(new class implements Constraint { |
||
| 30 | public function assert(Version $version) : bool |
||
| 31 | { |
||
| 32 | return ! $version->isPreRelease(); |
||
| 33 | } |
||
| 34 | }); |
||
| 35 | |||
| 36 | $versionsSortedDescending = $stableVersions->sortedDescending(); |
||
| 37 | |||
| 38 | $lastVersion = $versionsSortedDescending->first(); |
||
| 39 | |||
| 40 | $matchingMinorVersions = $stableVersions |
||
| 41 | ->matching(CompositeConstraint::and( |
||
| 42 | OperationConstraint::lessOrEqualTo($lastVersion), |
||
| 43 | OperationConstraint::greaterOrEqualTo(Version::fromString($lastVersion->getMajor() . '.' . $lastVersion->getMinor() . '.0')) |
||
| 44 | )) |
||
| 45 | ->sortedAscending(); |
||
| 46 | |||
| 47 | return $matchingMinorVersions->first(); |
||
| 48 | } |
||
| 50 |