Total Complexity | 4 |
Total Lines | 26 |
Duplicated Lines | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
8 | class Language implements LanguageInterface |
||
9 | { |
||
10 | private string $code; |
||
|
|||
11 | |||
12 | public function __construct(string $code) |
||
13 | { |
||
14 | $this->code = $this->validate($code); |
||
15 | } |
||
16 | |||
17 | public function getCode(): string |
||
18 | { |
||
19 | return $this->code; |
||
20 | } |
||
21 | |||
22 | private function validate(string $code): string |
||
23 | { |
||
24 | $code = mb_strtoupper(trim($code)); |
||
25 | $validatedCode = ''; |
||
26 | |||
27 | try { |
||
28 | $validatedCode = constant('\CodeblogPro\GeoLocation\Application\Enums\AvailableLanguages::' . $code); |
||
29 | } catch (\Exception $exception) { |
||
30 | throw new IncorrectLanguageCodeException(); |
||
31 | } |
||
32 | |||
33 | return $validatedCode; |
||
34 | } |
||
36 |