/** * @param Money $price * @param User $bidder */ public function addBid(Money $price, User $bidder) { if ($this->owner->equals($bidder)) { throw new InvalidArgumentException("You may not bid on your own auction"); } if (!$this->currentPrice->isLessThan($price)) { throw new InvalidArgumentException("Your bid must be higher than the current"); } if ($this->wasEnded()) { throw new LogicException("You may not bid on a ended auction"); } $this->currentPrice = $price; }
/** * @param Money|string|int|float $amount * @param int $precision * @return string */ public function display($amount, $precision = 2) { $amount = Utils::toStringAmount($amount); $money = new Money($amount); if ($this->isLeftSign) { if ($money->isLessThan('0')) { return '-' . $this->sign . $money->abs()->format($precision); } else { return $this->sign . $money->format($precision); } } else { return $money->format($precision) . $this->sign; } }
public function testCanCompareLessMoney() { $price = new Money(1, new Currency('EUR')); $higherPrice = new Money(2, new Currency('EUR')); $this->assertTrue($price->isLessThan($higherPrice)); }