Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix version comparison algorithm #116

Merged
merged 1 commit into from
Feb 25, 2021

Conversation

lcobucci
Copy link
Member

Q A
Documentation no
Bugfix yes
BC Break no
New Feature no
RFC no
QA no

Description

We were using a string-based comparison to handle this, which is rather error-prone since it considers '1.10.0' <= '1.9.0'.
This makes sure we use integers to perform the comparison in the correct hierarchy of the semver rules.

This seems to be the root cause of #74.

We were using a string-based comparison to handle this, which is rather
error-prone since it considers '1.10.0' <= '1.9.0'.

This makes sure we use integers to perform the comparison in the correct
hierarchy of the semver rules.

Signed-off-by: Luís Cobucci <lcobucci@gmail.com>
@lcobucci lcobucci added the Bug Something isn't working label Feb 25, 2021
@lcobucci lcobucci added this to the 1.9.2 milestone Feb 25, 2021
Copy link
Member

@Ocramius Ocramius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

Thanks for spotting this one, @lcobucci!

@Ocramius Ocramius self-assigned this Feb 25, 2021
@Ocramius Ocramius merged commit 7b43129 into laminas:1.9.x Feb 25, 2021
@lcobucci lcobucci deleted the fix-version-comparison branch February 25, 2021 11:44
@Ocramius Ocramius linked an issue Feb 25, 2021 that may be closed by this pull request
Comment on lines +92 to +102
private function compare(self $other): int
{
$comparison = $this->major <=> $other->major;

if ($comparison !== 0) {
return $comparison;
}

$comparison = $this->minor <=> $other->minor;

return $comparison !== 0 ? $comparison : $this->patch <=> $other->patch;
Copy link
Contributor

@bendavies bendavies Feb 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can all be condensed to:

return [$this->major, $this->minor, $this->patch] <=> [$other->major, $other->minor, $other->patch];

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bendavies cool, didn't know. Would you like to send a patch?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use something like:

it's been battle-tested since 2013 or so being part of the composer package.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be done, but this code was supposed to work on a very isolated scenario, so IMO, since it is tested and relatively well protected from mutants, introducing a dependency here will likely raise more issues due to the use-case scenario being widened (while it is intentionally narrow)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Randomly not creating next release branch
4 participants