Total Complexity | 6 |
Total Lines | 52 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
11 | class Currency implements CurrencyInterface, \JsonSerializable |
||
12 | { |
||
13 | private const _CODE_LENGTH = 9; |
||
14 | |||
15 | /** @var string */ |
||
16 | private $code; |
||
17 | |||
18 | /** |
||
19 | * @param string $code |
||
20 | */ |
||
21 | 136 | public function __construct(string $code) |
|
22 | { |
||
23 | 136 | if (\strlen($code) > static::_CODE_LENGTH) { |
|
24 | 1 | throw new \InvalidArgumentException('Currency code must be not longer then ' . static::_CODE_LENGTH); |
|
25 | } |
||
26 | 135 | $this->code = strtoupper($code); |
|
27 | 135 | } |
|
28 | |||
29 | /** |
||
30 | * Checks whether this currency is the same as an other. |
||
31 | * |
||
32 | * @param Currency $currency |
||
33 | * |
||
34 | * @return bool |
||
35 | */ |
||
36 | 51 | public function equals(Currency $currency): bool |
|
37 | { |
||
38 | 51 | return $this->code === $currency->code; |
|
39 | } |
||
40 | |||
41 | /** |
||
42 | * @return string |
||
43 | */ |
||
44 | 22 | public function __toString() |
|
45 | { |
||
46 | 22 | return $this->getCode(); |
|
47 | } |
||
48 | |||
49 | /** |
||
50 | * Returns the currency code. |
||
51 | */ |
||
52 | 23 | public function getCode(): string |
|
55 | } |
||
56 | |||
57 | /** |
||
58 | * {@inheritdoc} |
||
59 | */ |
||
60 | 2 | public function jsonSerialize(): string |
|
65 |