Skip to content
This repository has been archived by the owner on Mar 15, 2020. It is now read-only.

Update package to use Composer\Semver and more robust version sorting/comparing #34

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

padraic
Copy link
Collaborator

@padraic padraic commented May 8, 2017

Closes #31

$parser = new Parser;
return $parser->normalize(self::stripGitHash($version1))
=== $parser->normalize(self::stripGitHash($version2));
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Composer\Semver does not take kindly to versions containing git metadata tagged on to the end of it. This can be injected by Box, for example, when building PHARs. We use a small method to strip it out before passing to Semver.


/**
* @param array $versions
*/
public function __construct(array $versions = array())
{
$this->versions = $versions;
$this->parser = new Parser;
Copy link
Contributor

Choose a reason for hiding this comment

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

I recommend not omitting () during class instantiation without constructor parameters.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's not part of the PSR-2 standard which is enforced. We might adopt PSR-12 one day, if it ever leaves draft to get voted on, but I won't expect any contributor to follow a standard which we don't advertise/enforce upfront. That includes me and my own bias towards wondering why the seven hells I need to include parentheses when there are zero parameters ;).

Copy link
Member

Choose a reason for hiding this comment

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

I remember the first time I saw this I was confused as I didn't know it was possible, and when you call a function foo which has no arguments you call foo(), not foo. So I did wonder why the seven hells people took the liberty to change it with new :trollface:

In any case, it's my own bias as well and I don't think anyone would feel strongly about it 😄

Copy link
Contributor

Choose a reason for hiding this comment

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

That's why I don't like PSR-2 - too much room for improvement. Anyway please make it consistent across the code. If in all other places the () are not added, then don't added it here too.

) {
return true;
}
} catch (\UnexpectedValueException $e) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

UnexpectedValueException thrown by Composer\Semver. I should add a check that we do the following !== comparison only if the strategy in play is NOT github. Otherwise, we'll silently fail on invalid semver when there MUST be a valid semver version string.

In the event that a) we are using Github strategy, and b) Composer\Semver reports an invalid version string, throw an exception noting the problem which prevents comparing current version to new remote version.
@padraic padraic added this to the 1.1.0 milestone May 14, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants