Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Class RatesDB {
- private $rates = [];
- public function __construct($rates) {
- //I think here should be the function that get's rates from fixerio
- }
- public function getRate($currency)
- {
- return $rates[$currency];
- }
- }
- Class Currency {
- public $code;
- public $rate;
- public function __construct(string $code, RatesDB $rates) {
- $this->code = $code;
- $this->rate = $rates->getRate($code);
- }
- }
- Class Money {
- public $amount;
- public $currency;
- public function __construct(integer $amount, Currency $currency) {
- $this->amount = $amount;
- $this->currency = $currency;
- }
- public function getConvertedEquivelant(Currency $convertedCurrency): Money
- {
- $baseValue = $this->amount / $this->currency->rate;
- return new Money(($baseValue * $convertedCurrency->rate), $convertedCurrency);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement