PanovAlexey /
geo-location
| 1 | <?php |
||
| 2 | |||
| 3 | namespace CodeblogPro\GeoLocation\Application\Models; |
||
| 4 | |||
| 5 | use CodeblogPro\GeoLocation\Application\Interfaces\LanguageInterface; |
||
| 6 | use CodeblogPro\GeoLocation\Application\Exceptions\IncorrectLanguageCodeException; |
||
| 7 | |||
| 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 = ''; |
||
|
0 ignored issues
–
show
Unused Code
introduced
by
Loading history...
|
|||
| 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 | } |
||
| 35 | } |
||
| 36 |