Currency::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace BenTools\Currency\Model;
4
5
use Symfony\Component\Intl\Intl;
6
7
final class Currency implements CurrencyInterface
8
{
9
    /**
10
     * @var string
11
     */
12
    private $code;
13
14
    /**
15
     * Currency constructor.
16
     * @param string $code
17
     */
18
    public function __construct(string $code)
19
    {
20
        $this->code = strtoupper($code);
21
    }
22
23
    /**
24
     * @inheritDoc
25
     */
26
    public function getCode(): string
27
    {
28
        return $this->code;
29
    }
30
31
    /**
32
     * @inheritDoc
33
     */
34
    public function getName(string $locale = null): string
35
    {
36
        if (class_exists('Symfony\Component\Intl\Intl')) {
37
            return Intl::getCurrencyBundle()->getCurrencyName($this->getCode(), $locale) ?? $this->code;
38
        }
39
        return $this->code;
40
    }
41
}
42