Completed
Push — master ( dc6cfe...b219e3 )
by Byron
01:58
created

Language::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
namespace badams\MicrosoftTranslator;
3
4
use badams\MicrosoftTranslator\Exceptions\UnsupportedLanguageException;
5
6
/**
7
 * Class Language
8
 * @package badams\MicrosoftTranslator
9
 */
10
class Language
11
{
12
    /**
13
     * @var string
14
     */
15
    protected $code;
16
17
    /**
18
     * List of officially supported language code
19
     *
20
     * @var array
21
     */
22
    private $languages = [
23
        'ar' => 'Arabic',
24
        'bs-Latn' => 'Bosnian (Latin)',
25
        'bg' => 'Bulgarian',
26
        'ca' => 'Catalan',
27
        'zh-CHS' => 'Chinese Simplified',
28
        'zh-CHT' => 'Chinese Traditional',
29
        'hr' => 'Croatian',
30
        'cs' => 'Czech',
31
        'da' => 'Danish',
32
        'nl' => 'Dutch',
33
        'en' => 'English',
34
        'et' => 'Estonian',
35
        'fi' => 'Finnish',
36
        'fr' => 'French',
37
        'de' => 'German',
38
        'el' => 'Greek',
39
        'ht' => 'Haitian Creole',
40
        'he' => 'Hebrew',
41
        'hi' => 'Hindi',
42
        'mww' => 'Hmong Daw',
43
        'hu' => 'Hungarian',
44
        'id' => 'Indonesian',
45
        'it' => 'Italian',
46
        'ja' => 'Japanese',
47
        'sw' => 'Kiswahili',
48
        'tlh' => 'Klingon',
49
        'tlh-Qaak' => 'Klingon (pIqaD)',
50
        'ko' => 'Korean',
51
        'lv' => 'Latvian',
52
        'lt' => 'Lithuanian',
53
        'ms' => 'Malay',
54
        'mt' => 'Maltese',
55
        'no' => 'Norwegian',
56
        'fa' => 'Persian',
57
        'pl' => 'Polish',
58
        'pt' => 'Portuguese',
59
        'otq' => 'Querétaro Otomi',
60
        'ro' => 'Romanian',
61
        'ru' => 'Russian',
62
        'sr-Cyrl' => 'Serbian (Cyrillic)',
63
        'sr-Latn' => 'Serbian (Latin)',
64
        'sk' => 'Slovak',
65
        'sl' => 'Slovenian',
66
        'es' => 'Spanish',
67
        'sv' => 'Swedish',
68
        'th' => 'Thai',
69
        'tr' => 'Turkish',
70
        'uk' => 'Ukrainian',
71
        'ur' => 'Urdu',
72
        'vi' => 'Vietnamese',
73
        'cy' => 'Welsh',
74
        'yua' => 'Yucatec Maya',
75
    ];
76
77
    /**
78
     * Language constructor.
79
     * @param $code
80
     */
81 33
    public function __construct($code)
82
    {
83 33
        $this->code = strtolower((string)$code);
84
85 33
        if (!array_key_exists($this->code, $this->languages)) {
86 9
            throw new UnsupportedLanguageException(sprintf('%s is not a supported language code', $this->code));
87
        }
88 24
    }
89
90
    /**
91
     * @return string
92
     */
93 24
    public function __toString()
94
    {
95 24
        return $this->code;
96
    }
97
98
    /**
99
     * @return string;
0 ignored issues
show
Documentation introduced by
The doc-type string; could not be parsed: Expected "|" or "end of type", but got ";" at position 6. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
100
     */
101 6
    public function getEnglishName()
102
    {
103 6
        return $this->languages[$this->code];
104
    }
105
}