Skip to content

Commit

Permalink
change version comparison so that a version without a pre-release suf…
Browse files Browse the repository at this point in the history
…fix is always greater than a version with a pre-release suffix
  • Loading branch information
sebastianheuer committed Jul 8, 2018
1 parent 872340c commit 45a2ec5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

All notable changes to phar-io/version are documented in this file using the [Keep a CHANGELOG](http://keepachangelog.com/) principles.

## [2.0.1] - 08.07.2018

### Fixed

- Versions without a pre-release suffix are now always considered greater
than versions without a pre-release suffix. Example: `3.0.0 > 3.0.0-alpha.1`

## [2.0.0] - 23.06.2018

Changes to public API:
Expand Down Expand Up @@ -33,4 +40,5 @@ Changes to public API:
- [#10](https://github.com/phar-io/version/issues/10): Version numbers containing
a numeric suffix as seen in Debian packages are now supported.

[2.0.1]: https://github.com/phar-io/version/compare/2.0.0...2.0.1
[2.0.0]: https://github.com/phar-io/version/compare/1.0.1...2.0.0
4 changes: 2 additions & 2 deletions src/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ public function isGreaterThan(Version $version) {
}

if ($version->hasPreReleaseSuffix() && !$this->hasPreReleaseSuffix()) {
return false;
return true;
}

if (!$version->hasPreReleaseSuffix() && $this->hasPreReleaseSuffix()) {
return true;
return false;
}

return $this->getPreReleaseSuffix()->isGreaterThan($version->getPreReleaseSuffix());
Expand Down
2 changes: 2 additions & 0 deletions tests/Unit/VersionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ public function versionGreaterThanProvider() {
[new Version('2.5.8'), new Version('3.1.2'), false],
[new Version('3.0.0-alpha1'), new Version('3.0.0-alpha2'), false],
[new Version('3.0.0-alpha2'), new Version('3.0.0-alpha1'), true],
[new Version('3.0.0-alpha.1'), new Version('3.0.0'), false],
[new Version('3.0.0'), new Version('3.0.0-alpha.1'), true],
];
}

Expand Down

0 comments on commit 45a2ec5

Please sign in to comment.