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

Locale   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
c 0
b 0
f 0
dl 0
loc 33
rs 10
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A fromString() 0 3 1
A fromLocale() 0 3 1
A isLocale() 0 7 2
A toString() 0 3 1
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