Total Complexity | 7 |
Total Lines | 41 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
16 | final class Currency |
||
17 | { |
||
18 | public const CURRENCY = ['euro']; |
||
19 | public const SYMBOL = ['€']; |
||
20 | |||
21 | private string $currency; |
||
22 | private string $symbol; |
||
23 | |||
24 | public function __construct(string $currency) |
||
25 | { |
||
26 | $this->currency = self::isCurrency($currency); |
||
27 | $this->symbol = self::isSymbol($this->currency); |
||
28 | } |
||
29 | |||
30 | public static function fromString(string $currency): self |
||
31 | { |
||
32 | return new self($currency); |
||
33 | } |
||
34 | |||
35 | public function getValue(): string |
||
38 | } |
||
39 | |||
40 | public function symbol(): string |
||
41 | { |
||
42 | return $this->symbol; |
||
43 | } |
||
44 | |||
45 | private static function isCurrency(string $currency): string |
||
46 | { |
||
47 | if (!\in_array(\strtolower($currency), self::CURRENCY, true)) { |
||
48 | throw new InvalidCurrency(); |
||
49 | } |
||
50 | |||
51 | return \strtolower($currency); |
||
52 | } |
||
53 | |||
54 | private static function isSymbol(string $currency): string |
||
57 | } |
||
58 | } |
||
59 |