1 | <?php |
||
7 | class Converter |
||
8 | { |
||
9 | /** @var Price */ |
||
10 | private $price; |
||
11 | |||
12 | /** @var Currency */ |
||
13 | private $currency; |
||
14 | |||
15 | /** @var CurrenciesRepositoryContract */ |
||
16 | private $currencies; |
||
17 | |||
18 | /** @var Currency */ |
||
19 | private $base; |
||
20 | |||
21 | public function __construct(Currency $baseCurrency, CurrenciesRepositoryContract $currencies) |
||
27 | |||
28 | public function price(): Price |
||
32 | |||
33 | public function currency(): ?Currency |
||
37 | |||
38 | public function base(): Currency |
||
42 | |||
43 | /** |
||
44 | * Set the original price to be converted. |
||
45 | * |
||
46 | * @param Price $price |
||
47 | * @return $this |
||
48 | */ |
||
49 | public function from(Price $price): self |
||
55 | |||
56 | /** |
||
57 | * Set the currency that will be used for the convertion. |
||
58 | * |
||
59 | * @param string|Currency $currency |
||
60 | * @return $this |
||
61 | */ |
||
62 | public function to($currency): self |
||
70 | |||
71 | /** |
||
72 | * Convert the price to the currency. It will convert to the base currency first if needed. |
||
73 | * |
||
74 | * @return Price |
||
75 | */ |
||
76 | public function convert(): Price |
||
88 | |||
89 | /** |
||
90 | * Convert the amount performing different operations depending on the currency we want. |
||
91 | * |
||
92 | * @param $convertRatio |
||
93 | * @return float|int |
||
94 | */ |
||
95 | public function convertAmount(Currency $currency) |
||
103 | |||
104 | /** |
||
105 | * Convert the current price to EUR. |
||
106 | * |
||
107 | * @return Price |
||
108 | */ |
||
109 | public function convertToBase() |
||
117 | } |
||
118 |