Countries   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 7
dl 0
loc 63
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getISONumber() 0 3 1
A getIndexDefinition() 0 6 1
A arrayToEntry() 0 8 2
A getByAlpha3() 0 3 1
A getByNumericCode() 0 3 1
A getByAlpha2() 0 3 1
1
<?php
2
3
namespace Sokil\IsoCodes\Database;
4
5
use Sokil\IsoCodes\AbstractDatabase;
6
use Sokil\IsoCodes\Database\Countries\Country;
7
8
class Countries extends AbstractDatabase
9
{
10
    public static function getISONumber()
11
    {
12
        return '3166-1';
13
    }
14
15
    /**
16
     * @param array $entry
17
     *
18
     * @return Country
19
     */
20
    protected function arrayToEntry(array $entry)
21
    {
22
        return new Country(
23
            $entry['name'],
24
            $entry['alpha_2'],
25
            $entry['alpha_3'],
26
            (int)$entry['numeric'],
27
            !empty($entry['official_name']) ? $entry['official_name'] : null
28
        );
29
    }
30
31
    /**
32
     * @return array
33
     */
34
    protected function getIndexDefinition()
35
    {
36
        return [
37
            'alpha_2',
38
            'alpha_3',
39
            'numeric'
40
        ];
41
    }
42
43
    /**
44
     * @param string $alpha2
45
     *
46
     * @return null|Country
47
     */
48
    public function getByAlpha2($alpha2)
49
    {
50
        return $this->find('alpha_2', $alpha2);
51
    }
52
53
    /**
54
     * @param string $alpha3
55
     *
56
     * @return null|Country
57
     */
58
    public function getByAlpha3($alpha3)
59
    {
60
        return $this->find('alpha_3', $alpha3);
61
    }
62
63
    /**
64
     * @param int $code
65
     *
66
     * @return null|Country
67
     */
68
    public function getByNumericCode($code)
69
    {
70
        return $this->find('numeric', $code);
71
    }
72
}
73