Passed
Push — develop ( 0d66a7...37c69c )
by Laurent
05:34 queued 02:39
created

Currency::symbol()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 0
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 Administration\Domain\Settings\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 function getValue(): string
36
    {
37
        return $this->currency;
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
55
    {
56
        return self::SYMBOL[\array_search($currency, self::CURRENCY, true)];
57
    }
58
}
59