Locale::__invoke()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
crap 1
1
<?php
2
/**
3
 *
4
 * This file is part of Aura for PHP.
5
 *
6
 * @license http://opensource.org/licenses/bsd-license.php BSD
7
 *
8
 */
9
namespace Aura\Filter\Rule\Validate;
10
11
/**
12
 *
13
 * Validates that the value is in the list of allowed locale codes.
14
 *
15
 * @package Aura.Filter
16
 *
17
 */
18
class Locale
19
{
20
    /**
21
     *
22
     * Valid locale codes; generated via `locale -a` on Mac OS X 10.7.5.
23
     *
24
     * @var array
25
     *
26
     */
27
    protected $codes = array(
28
        'af_ZA', 'am_ET', 'be_BY', 'bg_BG', 'ca_ES', 'cs_CZ', 'da_DK',
29
        'de_AT', 'de_CH', 'de_DE', 'el_GR', 'en_AU', 'en_CA', 'en_GB',
30
        'en_IE', 'en_NZ', 'en_US', 'es_ES', 'et_EE', 'eu_ES', 'fi_FI',
31
        'fr_BE', 'fr_CA', 'fr_CH', 'fr_FR', 'he_IL', 'hi_IN', 'hr_HR',
32
        'hu_HU', 'hy_AM', 'is_IS', 'it_CH', 'it_IT', 'ja_JP', 'kk_KZ',
33
        'ko_KR', 'lt_LT', 'nl_BE', 'nl_NL', 'no_NO', 'pl_PL', 'pt_BR',
34
        'pt_PT', 'ro_RO', 'ru_RU', 'sk_SK', 'sl_SI', 'sr_YU', 'sv_SE',
35
        'tr_TR', 'uk_UA', 'zh_CN', 'zh_HK', 'zh_TW',
36
    );
37
38
    /**
39
     *
40
     * Validates that the value is in the list of allowed locale codes.
41
     *
42
     * @param object $subject The subject to be filtered.
43
     *
44
     * @param string $field The subject field name.
45
     *
46
     * @return bool True if valid, false if not.
47
     *
48
     */
49 9
    public function __invoke($subject, $field)
50
    {
51 9
        $value = $subject->$field;
52 9
        return in_array($value, $this->codes);
53
    }
54
}
55