Passed
Push — develop ( e3219b...3a1d34 )
by Laurent
01:38
created

Currency::toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the G.L.S.R. Apps package.
7
 *
8
 * (c) Dev-Int Création <[email protected]>.
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Company\Domain\Model\VO;
15
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 static function fromCurrency(self $currency): string
36
    {
37
        return $currency->toString();
38
    }
39
40
    public function getValue(): string
41
    {
42
        return $this->currency;
43
    }
44
45
    public function currency(): string
46
    {
47
        return $this->currency;
48
    }
49
50
    public function symbol(): string
51
    {
52
        return $this->symbol;
53
    }
54
55
    private static function isCurrency(string $currency): string
56
    {
57
        if (!\in_array(\strtolower($currency), self::CURRENCY, true)) {
58
            throw new InvalidCurrency();
59
        }
60
61
        return \strtolower($currency);
62
    }
63
64
    private static function isSymbol(string $currency): string
65
    {
66
        return self::SYMBOL[\array_search($currency, self::CURRENCY, true)];
67
    }
68
69
    private function toString(): string
70
    {
71
        return $this->currency;
72
    }
73
}
74