Completed
Push — master ( f0cb91...c4f1d3 )
by Ivan
02:22
created

CombinedFilter   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 93.75%

Importance

Changes 0
Metric Value
wmc 6
c 0
b 0
f 0
lcom 1
cbo 1
dl 0
loc 60
ccs 15
cts 16
cp 0.9375
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A filter() 0 10 2
A filterLocale() 0 11 2
A addLocale() 0 6 2
1
<?php
2
3
namespace CodeZero\BrowserLocale\Filters;
4
5
class CombinedFilter implements Filter
6
{
7
    /**
8
     * The filtered results.
9
     *
10
     * @var array
11
     */
12
    protected $filtered;
13
14
    /**
15
     * Filter the locales.
16
     *
17
     * @param array $locales
18
     *
19
     * @return array
20
     */
21 1
    public function filter(array $locales)
22
    {
23 1
        $this->filtered = [];
24
25 1
        foreach ($locales as $locale) {
26 1
            $this->filterLocale($locale);
27
        }
28
29 1
        return $this->filtered;
30
    }
31
32
    /**
33
     * Filter the given Locale.
34
     *
35
     * @param \CodeZero\BrowserLocale\Locale $locale
36
     *
37
     * @return void
38
     */
39 1
    protected function filterLocale($locale)
40
    {
41 1
        if (empty($locale->locale)) {
42
            return;
43
        }
44
45 1
        $language = substr($locale->locale, 0, 2);
46
47 1
        $this->addLocale($locale->locale);
48 1
        $this->addLocale($language);
49 1
    }
50
51
    /**
52
     * Add a locale to the results array.
53
     *
54
     * @param string $locale
55
     *
56
     * @return void
57
     */
58 1
    protected function addLocale($locale)
59
    {
60 1
        if ( ! in_array($locale, $this->filtered)) {
61 1
            $this->filtered[] = $locale;
62
        }
63 1
    }
64
}
65