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

Locale::isLocale()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 7
rs 10
c 1
b 0
f 0
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