Exemplo n.º 1
0
 /**
  * @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;
 }
Exemplo n.º 2
0
 /**
  * @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;
     }
 }
Exemplo n.º 3
0
 public function testCanCompareLessMoney()
 {
     $price = new Money(1, new Currency('EUR'));
     $higherPrice = new Money(2, new Currency('EUR'));
     $this->assertTrue($price->isLessThan($higherPrice));
 }