Completed
Pull Request — master (#8)
by Tomáš
03:09
created

Country::getPhonePrefixes()   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 prefixes
30
     *
31
     * @var array<string>
32
     */
33
    private $phonePrefixes;
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 array<string>        $phonePrefixes
49
     * @param string               $continent
50
     */
51 2
    public function __construct(
52
        array $names,
53
        string $code,
54
        string $currencyCode,
55
        array $phonePrefixes,
56
        string $continent
57
    ) {
58 2
        $this->names         = $names;
59 2
        $this->code          = $code;
60 2
        $this->currencyCode  = $currencyCode;
61 2
        $this->phonePrefixes = $phonePrefixes;
62 2
        $this->continent     = $continent;
63 2
    }
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 2
    public function getName(string $locale): ?string
79
    {
80 2
        return $this->names[$locale] ?? null;
81
    }
82
83
    /**
84
     * @return string
85
     */
86 2
    public function getCode(): string
87
    {
88 2
        return $this->code;
89
    }
90
91
    /**
92
     * @return string
93
     */
94 2
    public function getContinent(): string
95
    {
96 2
        return $this->continent;
97
    }
98
99
    /**
100
     * @return string
101
     */
102 2
    public function getPhonePrefix(): string
103
    {
104 2
        return $this->phonePrefixes[0];
105
    }
106
107
    /**
108
     * @return array<string>
109
     */
110 1
    public function getPhonePrefixes(): array
111
    {
112 1
        return $this->phonePrefixes;
113
    }
114
115
    /**
116
     * @return string
117
     */
118 2
    public function getCurrencyCode(): string
119
    {
120 2
        return $this->currencyCode;
121
    }
122
123
    /**
124
     * @param array<string,mixed> $data
125
     *
126
     * @return \Inspirum\Balikobot\Model\Values\Country
127
     */
128 2
    public static function newInstanceFromData(array $data): self
129
    {
130 2
        return new self(
131
            [
132 2
                'cs' => $data['name_cz'],
133 2
                'en' => $data['name_en'],
134
            ],
135 2
            $data['iso_code'],
136 2
            $data['currency'],
137 2
            is_array($data['phone_prefix']) ? $data['phone_prefix'] : [$data['phone_prefix']],
138 2
            $data['continent']
139
        );
140
    }
141
}
142