-
-
Notifications
You must be signed in to change notification settings - Fork 71
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
Introduce a comparison component #428
Conversation
Pull Request Test Coverage Report for Build 6953644254
💛 - Coveralls |
*/ | ||
function equal(mixed $a, mixed $b): bool | ||
{ | ||
return compare($a, $b) === Order::Equal; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking about adding a Equable
check here and use the Equable::equals()
method if possible. This could work for equal and not equal.
However, it would mean adding additional comparisons for less_or_equal
and greater_or_equal
. Not sure if it's a good idea and worth adding.
[![Mend Renovate logo banner](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [azjezz/psl](https://togithub.com/azjezz/psl) | `2.7.0` -> `2.8.0` | [![age](https://developer.mend.io/api/mc/badges/age/packagist/azjezz%2fpsl/2.8.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/packagist/azjezz%2fpsl/2.8.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/packagist/azjezz%2fpsl/2.7.0/2.8.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/packagist/azjezz%2fpsl/2.7.0/2.8.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | --- > [!WARNING] > Some dependencies could not be looked up. Check the Dependency Dashboard for more information. --- ### Release Notes <details> <summary>azjezz/psl (azjezz/psl)</summary> ### [`v2.8.0`](https://togithub.com/azjezz/psl/releases/tag/2.8.0): Lenalee - 2.8.0 [Compare Source](https://togithub.com/azjezz/psl/compare/2.7.0...2.8.0) #### What's Changed - chore(ga): bump actions/checkout from 3 to 4 by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/azjezz/psl/pull/420](https://togithub.com/azjezz/psl/pull/420) - Fix mutations + math float tests by [@​veewee](https://togithub.com/veewee) in [https://github.com/azjezz/psl/pull/427](https://togithub.com/azjezz/psl/pull/427) - Introduce a comparison component by [@​veewee](https://togithub.com/veewee) in [https://github.com/azjezz/psl/pull/428](https://togithub.com/azjezz/psl/pull/428) - Indicate support for PHP 8.3 by [@​gsteel](https://togithub.com/gsteel) in [https://github.com/azjezz/psl/pull/430](https://togithub.com/azjezz/psl/pull/430) #### New Contributors - [@​gsteel](https://togithub.com/gsteel) made their first contribution in [https://github.com/azjezz/psl/pull/430](https://togithub.com/azjezz/psl/pull/430) **Full Changelog**: azjezz/psl@2.7.0...2.8.0 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/ben-challis/sql-migrations). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy41OS44IiwidXBkYXRlZEluVmVyIjoiMzcuNTkuOCIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
This PR introduces a comparison component:
compare
andequal
function to your own classes:Comparable<T>
Equable<T>
compare(T $a, T $b): Order
equal(T $a, T $b): bool
not_equal(T $a, T $b): bool
less(T $a, T $b): bool
less_or_equal(T $a, T $b): bool
greater(T $a, T $b): bool
greater_or_equal(T $a, T $b): bool
sort(T $a, T $b): -1 | 0 | 1
(as shortcut for e.g. vec sorting)Option
component was added.<=>
comparison operatorIncomparableException
mixed
. (At that moment, PHPs default compare system kicks in. A user could opt-in on throwing an exception manually in the class that implements Comparable)Some examples
OPTION
COVARIANCE
MIXED
I've tried throwing a lot of different types at the
<=>
operator and wasn't able to make PHP throw exceptions.Therefore, any non
Comparable
object falls back to PHPs internal sorting system.As long as I cannot find incomparable values, I won't enforce having to deal with
IncomparableException
from the API.(The mutation test issues are solved in #427)