Locale   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 58
ccs 23
cts 23
cp 1
rs 10
c 0
b 0
f 0
wmc 11
lcom 1
cbo 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A from() 0 4 1
A withoutRegion() 0 10 2
A region() 0 14 3
A get() 0 4 1
A equals() 0 4 2
A __toString() 0 4 1
1
<?php
2
3
namespace Thinktomorrow\Locale\Values;
4
5
final class Locale
6
{
7
    /**
8
     * @var string Locale key identifier
9
     */
10
    private $value;
11
12 95
    private function __construct(string $value)
13
    {
14 95
        $this->value = $value;
15 95
    }
16
17 95
    public static function from(string $value)
18
    {
19 95
        return new static($value);
20
    }
21
22 3
    public function withoutRegion()
23
    {
24 3
        $value = $this->value;
25
26 3
        if ($region = $this->region()) {
27 3
            $value = str_replace(['-'.$region, '_'.$region], '', $value);
28
        }
29
30 3
        return new static($value);
31
    }
32
33 4
    public function region(): ?string
34
    {
35 4
        $value = $this->value;
36
37 4
        if (false !== strpos($value, '-')) {
38 4
            return substr($value, strpos($value, '-') + 1);
39
        }
40
41 3
        if (false !== strpos($value, '_')) {
42 3
            return substr($value, strpos($value, '_') + 1);
43
        }
44
45 3
        return null;
46
    }
47
48 79
    public function get(): string
49
    {
50 79
        return $this->value;
51
    }
52
53 1
    public function equals($other): bool
54
    {
55 1
        return get_class($this) === get_class($other) && (string) $this === (string) $other;
56
    }
57
58 77
    public function __toString(): string
59
    {
60 77
        return $this->get();
61
    }
62
}
63