rdehnhardt /
exchange-rate
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Rdehnhardt\ExchangeRate; |
||
| 4 | |||
| 5 | use Rdehnhardt\ExchangeRate\Excaptions\NotFoundException; |
||
| 6 | |||
| 7 | class Exchange |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * @var Fixer |
||
| 11 | */ |
||
| 12 | private $fixer; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * Exchange constructor. |
||
| 16 | * @param Fixer $fixer |
||
| 17 | */ |
||
| 18 | public function __construct(Fixer $fixer) |
||
| 19 | { |
||
| 20 | $this->fixer = $fixer; |
||
| 21 | } |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @param $amount |
||
| 25 | * @param $from |
||
| 26 | * @param $to |
||
| 27 | * @param null $rate |
||
|
0 ignored issues
–
show
Documentation
Bug
introduced
by
Loading history...
|
|||
| 28 | * @return int |
||
| 29 | * @throws NotFoundException |
||
| 30 | */ |
||
| 31 | public function rate($amount, $from, $to, $rate = null) |
||
| 32 | { |
||
| 33 | if ($rate === null) { |
||
| 34 | $rate = $this->fixer->get($from, $to); |
||
| 35 | } |
||
| 36 | |||
| 37 | return $amount * $rate; |
||
| 38 | } |
||
| 39 | } |
||
| 40 |