Passed
Push — develop ( 0d66a7...37c69c )
by Laurent
05:34 queued 02:39
created

Locale   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
dl 0
loc 28
rs 10
c 1
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getValue() 0 3 1
A fromString() 0 3 1
A isLocale() 0 7 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the G.L.S.R. Apps package.
7
 *
8
 * (c) Dev-Int Création <[email protected]>.
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Administration\Domain\Settings\Model\VO;
15
16
final class Locale
17
{
18
    public const LOCALE = ['fr'];
19
20
    private string $locale;
21
22
    public function __construct(string $locale)
23
    {
24
        $this->locale = self::isLocale($locale);
25
    }
26
27
    public static function fromString(string $locale): self
28
    {
29
        return new self($locale);
30
    }
31
32
    public function getValue(): string
33
    {
34
        return $this->locale;
35
    }
36
37
    private static function isLocale(string $locale): string
38
    {
39
        if (!\in_array(\strtolower($locale), self::LOCALE, true)) {
40
            throw new InvalidLocale();
41
        }
42
43
        return \strtolower($locale);
44
    }
45
}
46