Completed
Push — master ( 2546e0...ad929d )
by Alexey
12:49 queued 02:29
created

Language::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
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;
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_STRING, expecting T_FUNCTION or T_CONST
Loading history...
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
    }
35
}
36