Skip to content

Amount: greaterThanOrEqual / lessThanOrEqual / compareTo #7

@navidkashani

Description

@navidkashani

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:

  1. 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).
  2. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions