Alias   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 37
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 2
A toNative() 0 3 1
A equals() 0 3 1
1
<?php declare(strict_types=1);
2
3
namespace VSV\GVQ_API\Company\ValueObjects;
4
5
class Alias
6
{
7
    /**
8
     * @var string
9
     */
10
    private $value;
11
12
    /**
13
     * @param string $value
14
     */
15
    public function __construct(string $value)
16
    {
17
        if (!preg_match('/^[a-z0-9\-]{3,40}$/', $value)) {
18
            throw new \InvalidArgumentException(
19
                'Invalid value: '.$value.' for TranslatedAlias. Value should be '.
20
                'between 3 and 40 characters long and consist only of lowercase letters, numbers and "-"'
21
            );
22
        }
23
24
        $this->value = $value;
25
    }
26
27
    /**
28
     * @return string
29
     */
30
    public function toNative(): string
31
    {
32
        return $this->value;
33
    }
34
35
    /**
36
     * @param Alias $aliasString
37
     * @return bool
38
     */
39
    public function equals(Alias $aliasString): bool
40
    {
41
        return $this->toNative() === $aliasString->toNative();
42
    }
43
}
44