Advertisement
Guest User

Untitled

a guest
Feb 16th, 2018
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.85 KB | None | 0 0
  1.  
  2.  
  3. Class RatesDB {
  4.  
  5.     private $rates = [];
  6.  
  7.     public function __construct($rates) {
  8.         //I think here should be the function that get's rates from fixerio
  9.     }
  10.  
  11.     public function getRate($currency)
  12.     {
  13.         return $rates[$currency];
  14.     }
  15.  
  16. }
  17.  
  18. Class Currency {
  19.  
  20.     public $code;
  21.     public $rate;
  22.  
  23.     public function __construct(string $code, RatesDB $rates) {
  24.  
  25.         $this->code = $code;
  26.  
  27.         $this->rate = $rates->getRate($code);
  28.  
  29.     }
  30.  
  31. }
  32.  
  33. Class Money {
  34.    
  35.     public $amount;
  36.     public $currency;
  37.  
  38.     public function __construct(integer $amount, Currency $currency) {
  39.  
  40.         $this->amount = $amount;
  41.  
  42.         $this->currency = $currency;
  43.  
  44.     }
  45.  
  46.     public function getConvertedEquivelant(Currency $convertedCurrency): Money
  47.     {
  48.  
  49.         $baseValue = $this->amount / $this->currency->rate;
  50.  
  51.         return new Money(($baseValue * $convertedCurrency->rate), $convertedCurrency);
  52.  
  53.     }
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement