Passed
Pull Request — master (#3)
by Artem
02:31
created

Territory::getUnofficialLanguages()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 9
rs 9.6666
cc 2
eloc 4
nc 2
nop 0
1
<?php
2
3
namespace Sokil\IsoCodes\Database\Territory;
4
5
class Territory
6
{
7
    /**
8
     * @var string
9
     */
10
    private $alpha2;
11
12
    /**
13
     * @var array
14
     */
15
    private $languages;
16
17
    /**
18
     * @var array
19
     */
20
    private $officialLanguages;
21
22
    /**
23
     * @var array
24
     */
25
    private $unofficialLanguages;
26
27
    /**
28
     * Territory constructor.
29
     *
30
     * @param string $alpha2
31
     * @param array $languages
32
     */
33
    public function __construct(
34
        $alpha2,
35
        $languages
36
    ) {
37
        $this->alpha2 = $alpha2;
38
        $this->languages = $languages;
39
    }
40
41
    /**
42
     * @return string
43
     */
44
    public function getAlpha2()
45
    {
46
        return $this->alpha2;
47
    }
48
49
    /**
50
     * @return array
51
     */
52
    public function getLanguages()
53
    {
54
        return $this->languages;
55
    }
56
57
    /**
58
     * @return array
59
     */
60
    public function getOfficialLanguages()
61
    {
62
        if ($this->officialLanguages === null) {
0 ignored issues
show
introduced by
The condition $this->officialLanguages === null can never be true.
Loading history...
63
            $this->officialLanguages = array_filter($this->getLanguages(), function ($v) {
64
                return $v['official'];
65
            });
66
        }
67
68
        return $this->officialLanguages;
69
    }
70
71
    /**
72
     * @return array
73
     */
74
    public function getUnofficialLanguages()
75
    {
76
        if ($this->unofficialLanguages === null) {
0 ignored issues
show
introduced by
The condition $this->unofficialLanguages === null can never be true.
Loading history...
77
            $this->officialLanguages = array_filter($this->getLanguages(), function ($v) {
78
                return !$v['official'];
79
            });
80
        }
81
82
        return $this->unofficialLanguages;
83
    }
84
}
85