Completed
Push — master ( cb1d4b...ee462c )
by Tomáš
03:34
created

Country::getCode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
ccs 2
cts 2
cp 1
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Inspirum\Balikobot\Model\Values;
4
5
class Country
6
{
7
    /**
8
     * Names
9
     *
10
     * @var array<string,string>
11
     */
12
    private $names;
13
14
    /**
15
     * Alpha-2 country code
16
     *
17
     * @var string
18
     */
19
    private $code;
20
21
    /**
22
     * Continent name
23
     *
24
     * @var string
25
     */
26
    private $continent;
27
28
    /**
29
     * Phone prefix
30
     *
31
     * @var float
32
     */
33
    private $phonePrefix;
34
35
    /**
36
     * Currency code
37
     *
38
     * @var string
39
     */
40
    private $currencyCode;
41
42
    /**
43
     * Country constructor
44
     *
45
     * @param array<string,string> $names
46
     * @param string               $code
47
     * @param string               $currencyCode
48
     * @param float                $phonePrefix
49
     * @param string               $continent
50
     */
51 1
    public function __construct(
52
        array $names,
53
        string $code,
54
        string $currencyCode,
55
        float $phonePrefix,
56
        string $continent
57
    ) {
58 1
        $this->names        = $names;
59 1
        $this->code         = $code;
60 1
        $this->currencyCode = $currencyCode;
61 1
        $this->phonePrefix  = $phonePrefix;
62 1
        $this->continent    = $continent;
63 1
    }
64
65
    /**
66
     * @return array<string,string>
67
     */
68 1
    public function getNames(): array
69
    {
70 1
        return $this->names;
71
    }
72
73
    /**
74
     * @param string $locale
75
     *
76
     * @return string|null
77
     */
78 1
    public function getName(string $locale): ?string
79
    {
80 1
        return $this->names[$locale] ?? null;
81
    }
82
83
    /**
84
     * @return string
85
     */
86 1
    public function getCode(): string
87
    {
88 1
        return $this->code;
89
    }
90
91
    /**
92
     * @return string
93
     */
94 1
    public function getContinent(): string
95
    {
96 1
        return $this->continent;
97
    }
98
99
    /**
100
     * @return float
101
     */
102 1
    public function getPhonePrefix(): float
103
    {
104 1
        return $this->phonePrefix;
105
    }
106
107
    /**
108
     * @return string
109
     */
110 1
    public function getCurrencyCode(): string
111
    {
112 1
        return $this->currencyCode;
113
    }
114
115
    /**
116
     * @param array<string,mixed> $data
117
     *
118
     * @return \Inspirum\Balikobot\Model\Values\Country
119
     */
120 1
    public static function newInstanceFromData(array $data): self
121
    {
122 1
        return new self(
123
            [
124 1
                'cs' => $data['name_cz'],
125 1
                'en' => $data['name_en'],
126
            ],
127 1
            $data['iso_code'],
128 1
            $data['currency'],
129 1
            $data['phone_prefix'],
130 1
            $data['continent']
131
        );
132
    }
133
}
134