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

Add basic comparison helper functions #5

Merged
merged 1 commit into from Jul 21, 2015

Conversation

legoktm
Copy link
Contributor

@legoktm legoktm commented Jul 16, 2015

Part of #2.

Implements helper functions for greater than, greater than or equal to,
less than, less than or equal to, equal to, and not equal to.

They all call Compare:compare() which takes an arbitrary comparison
operator.

use Composer\Semver\Constraint\VersionConstraint;
use InvalidArgumentException;

class Compare
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe this class should be final?

Copy link
Member

Choose a reason for hiding this comment

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

Can you expand on your suggestion? What would be the drawback of allowing extending?

Copy link
Contributor

Choose a reason for hiding this comment

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

Comaprator would be better than Compare IMO. Class names are better as noun than as verbs

Copy link
Member

Choose a reason for hiding this comment

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

You mean Comparator? Or how about Comparison?

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah, sorry for the typos. I typed too fast

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, renamed to Comparator, but not final.

@alcohol
Copy link
Member

alcohol commented Jul 17, 2015

Do you want to look into implementing the remaining methods as well? And if so, in this PR or another?

* Evaluate $version1 $comparison $version2.
*
* @param string $version1
* @param string $comparison Operator like ">" or "<=", etc.
Copy link
Contributor

Choose a reason for hiding this comment

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

I would rename the argument to $operator

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@legoktm
Copy link
Contributor Author

legoktm commented Jul 18, 2015

Do you want to look into implementing the remaining methods as well? And if so, in this PR or another?

I will submit a different PR for the other methods.

@alcohol
Copy link
Member

alcohol commented Jul 18, 2015

What about calling this class just Semver?

@legoktm
Copy link
Contributor Author

legoktm commented Jul 18, 2015

What about calling this class just Semver?

I am pretty terrible at naming things, so I typically defer to other people :P. So I can change it to whatever you and stof agree on...but we can also go with the current one and change the class name to a better one in the future before we make an initial release.

@alcohol
Copy link
Member

alcohol commented Jul 18, 2015

I personally find Comparator a bid awkward. But on the other hand it fits the context I guess. So I don't know.

@alcohol
Copy link
Member

alcohol commented Jul 18, 2015

/cc @Seldaek @stof @naderman what would you guys prefer?

@Seldaek
Copy link
Member

Seldaek commented Jul 20, 2015

I'd be fine with Composer\Semver\Semver as high level API. However the function names are all over the place. Only two have a To suffix, that should be unified one way or the other. And the greaterThanEqualTo IMO should have an Or in there if we want fully readable naming.

@naderman
Copy link
Member

I'd prefer Comparator to be honest, that's quite precisely what it is, and we have Semver in the namespace already, so that part is clear too.

@alcohol
Copy link
Member

alcohol commented Jul 20, 2015

But would you also add functions that handle increasing/decreasing versions etc into Comparator? Or would you create a new class for that then? Wouldn't it be nicer to have them all combined in just Semver? Or would you prefer multiple classes?

@Seldaek
Copy link
Member

Seldaek commented Jul 20, 2015

Maybe Comparator::compare and the rest stays on a Semver class as shortcuts?

@alcohol
Copy link
Member

alcohol commented Jul 20, 2015

Could you define "rest" and "shortcuts"? I'm a bit confused as to what you are referring to now.

@GrahamCampbell
Copy link
Contributor

I'd prefer Comparator to be honest

👍

@Seldaek
Copy link
Member

Seldaek commented Jul 20, 2015

rest: all methods except compare.
shortcut: all methods except compare, which don't do anything but defer to compare.

But yeah we can as well just keep it all in Comparator IMO. We'll need another class(es) for the other methods though, if we want to implement them at all.

Part of composer#2.

Implements helper functions for greater than, greater than or equal to,
less than, less than or equal to, equal to, and not equal to.

They all call Comparator::compare() which takes an arbitrary comparison
operator.
alcohol added a commit that referenced this pull request Jul 21, 2015
Add basic comparison helper functions
@alcohol alcohol merged commit 44196c3 into composer:master Jul 21, 2015
@legoktm
Copy link
Contributor Author

legoktm commented Jul 21, 2015

Only two have a To suffix, that should be unified one way or the other. And the greaterThanEqualTo IMO should have an Or in there if we want fully readable naming.

Added "Or" to those two functions. The lack of the "To" suffix on lessThan and greaterThan is intentional, those typically aren't used with "to" in English (e.g. https://en.wikipedia.org/wiki/Inequality_%28mathematics%29).

@alcohol
Copy link
Member

alcohol commented Jul 21, 2015

Thanks :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants