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