Passed
Push — develop ( e3219b...3a1d34 )
by Laurent
01:38
created

Locale::__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
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 Company\Domain\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 static function fromLocale(self $locale): string
33
    {
34
        return $locale->toString();
35
    }
36
37
    public function toString(): string
38
    {
39
        return $this->locale;
40
    }
41
42
    private static function isLocale(string $locale): string
43
    {
44
        if (!\in_array(\strtolower($locale), self::LOCALE, true)) {
45
            throw new InvalidLocale();
46
        }
47
48
        return \strtolower($locale);
49
    }
50
}
51