Language::validate()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 7
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 12
ccs 0
cts 10
cp 0
crap 6
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;
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
The assignment to $validatedCode is dead and can be removed.
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