CurrencyPair::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 7
rs 9.4285
cc 1
eloc 5
nc 1
nop 3
1
<?php
2
3
namespace Kanunak\Money;
4
5
class CurrencyPair
6
{
7
    /** @var Currency  */
8
    private $currencyFrom;
9
10
    /** @var Currency  */
11
    private $currencyTo;
12
13
    /** @var  float */
14
    private $ratio;
15
16
    /**
17
     * @param Currency $currencyFrom
18
     * @param Currency $currencyTo
19
     * @param $ratio
20
     */
21
    public function __construct(Currency $currencyFrom, Currency $currencyTo, $ratio)
22
    {
23
        $this->validateRatio($ratio);
24
        $this->currencyFrom = $currencyFrom;
25
        $this->currencyTo = $currencyTo;
26
        $this->ratio = $ratio;
27
    }
28
29
    /**
30
     * @return Currency
31
     */
32
    public function currencyFrom()
33
    {
34
        return $this->currencyFrom;
35
    }
36
37
    /**
38
     * @return Currency
39
     */
40
    public function currencyTo()
41
    {
42
        return $this->currencyTo;
43
    }
44
45
    /**
46
     * @return float
47
     */
48
    public function ratio()
49
    {
50
        return $this->ratio;
51
    }
52
53
    /**
54
     * @param $ratio
55
     * @throw \InvalidArgumentException
56
     */
57
    private function validateRatio($ratio)
58
    {
59
        if (!is_float($ratio)) {
60
            throw new \InvalidArgumentException('Ratio is not float');
61
        }
62
    }
63
}
64