|
@@ 108-125 (lines=18) @@
|
| 105 |
|
* |
| 106 |
|
* @throws \MoneyMan\Exception\CannotAddDifferentCurrenciesException |
| 107 |
|
*/ |
| 108 |
|
public function add(Money $money) |
| 109 |
|
{ |
| 110 |
|
// Validate they are of the same currency. |
| 111 |
|
if (!$this->hasSameCurrencyAs($money)) { |
| 112 |
|
throw new CannotAddDifferentCurrenciesException( |
| 113 |
|
'To directly add two money objects together, they must be of the same currency.' . |
| 114 |
|
'Use \MoneyMan\Exchange::add(\MoneyMan\Money, \MoneyMan\Money) to add \MoneyMan\Money ' . |
| 115 |
|
'objects of different currencies.' |
| 116 |
|
); |
| 117 |
|
} |
| 118 |
|
|
| 119 |
|
$total_amount = $this->getAmount() + $money->getAmount(); |
| 120 |
|
|
| 121 |
|
return new self( |
| 122 |
|
$total_amount, |
| 123 |
|
$this->getCurrency() |
| 124 |
|
); |
| 125 |
|
} |
| 126 |
|
|
| 127 |
|
/** |
| 128 |
|
* Subtracts the incoming \MoneyMan\Money object's amount from this object. |
|
@@ 139-156 (lines=18) @@
|
| 136 |
|
* |
| 137 |
|
* @throws \MoneyMan\Exception\CannotSubtractDifferentCurrenciesException |
| 138 |
|
*/ |
| 139 |
|
public function subtract(Money $money) |
| 140 |
|
{ |
| 141 |
|
// Validate they are of the same currency. |
| 142 |
|
if (!$this->hasSameCurrencyAs($money)) { |
| 143 |
|
throw new CannotSubtractDifferentCurrenciesException( |
| 144 |
|
'To directly subtract one money object from another, they must be of the same currency.' . |
| 145 |
|
'Use \MoneyMan\Exchange::subtract(\MoneyMan\Money, \MoneyMan\Money) to subtract \MoneyMan\Money ' . |
| 146 |
|
'objects of different currencies.' |
| 147 |
|
); |
| 148 |
|
} |
| 149 |
|
|
| 150 |
|
$total_amount = $this->getAmount() - $money->getAmount(); |
| 151 |
|
|
| 152 |
|
return new self( |
| 153 |
|
$total_amount, |
| 154 |
|
$this->getCurrency() |
| 155 |
|
); |
| 156 |
|
} |
| 157 |
|
|
| 158 |
|
/** |
| 159 |
|
* Determine if this \MoneyMan\Money object has the same currency as another |