composer / semver

Semantic versioning utilities with the addition of version constraints parsing and checking.
MIT License
3.15k stars 76 forks source link

Comparator::equalTo return false when compare two constraints. #63

Closed Maurisss94 closed 5 years ago

Maurisss94 commented 5 years ago

Hi, i need to check if two versions constraints 5.7.* are equal, and not want to do with comparator ===.

But my surprirse is, when i check this line Comparator::equalTo($this->composer['require'][$dependency], $version), the result is false, but the two strings are 5.7.*.

Somebody can help me?

stof commented 5 years ago

5.7.* is a version constraint, not a version. The Comparator class is about comparing versions.

Maurisss94 commented 5 years ago

And what class should be use, to compare constraints?

stof commented 5 years ago

Constraints cannot directly be compared to each other as done by the Comparator class, because constraints are not ordered (saying $constraint1 > $constraint2 does not make any sense).

What are you trying to achieve exactly ?

Maurisss94 commented 5 years ago

Sure, it makes a lot of sense. I wanted to compare both versions and constraints between two composer.json files, and pick up the package with the newest version. I will use the equality comparer ==, for constraints and the Comparator class for versions.

Thank you.

alcohol commented 5 years ago

The only thing you could compare between constraints is their upper and lower boundaries. Comparing the constraints themselves does not make much sense as @stof said because they generally represent a range.

stof commented 5 years ago

The only thing you could compare between constraints is their upper and lower boundaries.

even that may not always work fine, as constraints don't represent one range, but a union of ranges (due to the || operator)