CombinedFilter   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
dl 0
loc 53
ccs 13
cts 13
cp 1
rs 10
c 1
b 0
f 0
wmc 5

3 Methods

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