Context
Tracked for 0.7 off the pre-merge audit of #4. Feature ask, not a gap.
Motivation
Amount currently exposes equals, greaterThan, lessThan. That's enough for strict comparisons, but two real ergonomic needs aren't covered:
- Sorting.
usort($amounts, fn(\$a, \$b) => \$a->compareTo(\$b)) is the idiomatic PHP pattern; without compareTo callers have to hand-roll the tri-state or abuse ->rials directly (which defeats the VO encapsulation).
- Threshold checks.
$amount->greaterThanOrEqual($min) reads cleaner than $amount->greaterThan($min) || $amount->equals($min) and avoids the two-call hazard where one accessor might diverge from the other later.
Proposed API
public function greaterThanOrEqual(Amount \$other): bool;
public function lessThanOrEqual(Amount \$other): bool;
public function compareTo(Amount \$other): int; // -1 / 0 / 1
Open questions (defer)
- Short aliases (
gte/lte)? Defer — let pardakht / ersal call-site density decide whether the verbosity is worth trimming.
- Mixed-unit comparison (Toman vs Rial) — moot today since
Amount is rial-internally, but worth a line of doc confirming the comparison is always at the rial level.
Why 0.7, not 0.6.1
Additive API surface. Wants real downstream adoption (pardakht, ersal) to confirm the method names before they lock.
Context
Tracked for 0.7 off the pre-merge audit of #4. Feature ask, not a gap.
Motivation
Amountcurrently exposesequals,greaterThan,lessThan. That's enough for strict comparisons, but two real ergonomic needs aren't covered:usort($amounts, fn(\$a, \$b) => \$a->compareTo(\$b))is the idiomatic PHP pattern; withoutcompareTocallers have to hand-roll the tri-state or abuse->rialsdirectly (which defeats the VO encapsulation).$amount->greaterThanOrEqual($min)reads cleaner than$amount->greaterThan($min) || $amount->equals($min)and avoids the two-call hazard where one accessor might diverge from the other later.Proposed API
Open questions (defer)
gte/lte)? Defer — letpardakht/ersalcall-site density decide whether the verbosity is worth trimming.Amountis rial-internally, but worth a line of doc confirming the comparison is always at the rial level.Why 0.7, not 0.6.1
Additive API surface. Wants real downstream adoption (
pardakht,ersal) to confirm the method names before they lock.