Skip to content

Commit 7b43129

Browse files
authored
Merge pull request #116 from lcobucci/fix-version-comparison
Fix version comparison algorithm
2 parents 32f970e + 7ccf18b commit 7b43129

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/Git/Value/SemVerVersion.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,19 @@ public function isNewMajorRelease(): bool
8686

8787
public function lessThanEqual(self $other): bool
8888
{
89-
return $this->fullReleaseName() <= $other->fullReleaseName();
89+
return $this->compare($other) <= 0;
90+
}
91+
92+
private function compare(self $other): int
93+
{
94+
$comparison = $this->major <=> $other->major;
95+
96+
if ($comparison !== 0) {
97+
return $comparison;
98+
}
99+
100+
$comparison = $this->minor <=> $other->minor;
101+
102+
return $comparison !== 0 ? $comparison : $this->patch <=> $other->patch;
90103
}
91104
}

test/unit/Git/Value/SemVerVersionTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,12 @@ public function lessThanEqualProvider(): array
188188
['0.1.1', '0.1.0', false],
189189
['2.0.0', '1.0.0', false],
190190
['1.0.0', '2.0.0', true],
191+
['1.10.0', '1.9.0', false],
192+
['1.9.0', '1.10.0', true],
193+
['1.0.10', '1.0.9', false],
194+
['1.0.9', '1.0.10', true],
195+
['10.0.0', '9.0.0', false],
196+
['9.0.0', '10.0.0', true],
191197
];
192198
}
193199

0 commit comments

Comments
 (0)