Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
5 / 5
CRAP
100.00% covered (success)
100.00%
1 / 1
Language
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
5 / 5
6
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
 fromString
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getCode
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 equals
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 __toString
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace App\Domain\Translation\ValueObject;
6
7 class Language
8{
9    public const DEFAULT_LOCALE = 'en';
10    public const SUPPORTED_LOCALES = ['en', 'pl'];
11
12    private string $code;
13
14    public function __construct(string $code)
15    {
16        $normalized = strtolower(trim($code));
17        if (!in_array($normalized, self::SUPPORTED_LOCALES, true)) {
18            $normalized = self::DEFAULT_LOCALE;
19        }
20
21        $this->code = $normalized;
22    }
23
24    public static function fromString(string $code): self
25    {
26        return new self($code);
27    }
28
29    public function getCode(): string
30    {
31        return $this->code;
32    }
33
34    public function equals(Language $other): bool
35    {
36        return $this->code === $other->getCode();
37    }
38
39    public function __toString(): string
40    {
41        return $this->code;
42    }
43}