Completed
Push — master ( e8b19e...87df92 )
by Andrew
02:42
created

Gender   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 90.91%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
eloc 13
c 1
b 0
f 1
dl 0
loc 38
ccs 10
cts 11
cp 0.9091
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getValue() 0 3 1
A __toString() 0 3 1
A __construct() 0 7 2
A equals() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace KRDigital\NamesDetector\Entry;
6
7
use KRDigital\NamesDetector\Exception\InvalidGenderException;
8
9
class Gender
10
{
11
    public const GENDER_MALE = 'm';
12
13
    public const GENDER_FEMALE = 'f';
14
15
    private const ALLOWED_GENDERS = [
16
        self::GENDER_MALE,
17
        self::GENDER_FEMALE,
18
    ];
19
20
    /**
21
     * @var string
22
     */
23
    protected $value;
24
25 3
    public function __construct(string $value)
26
    {
27 3
        if (!\in_array($value, self::ALLOWED_GENDERS, true)) {
28
            throw new InvalidGenderException(\sprintf('Gender %s is not allowed', $value));
29
        }
30
31 3
        $this->value = $value;
32 3
    }
33
34 1
    public function __toString(): string
35
    {
36 1
        return $this->value;
37
    }
38
39 2
    public function getValue(): string
40
    {
41 2
        return $this->value;
42
    }
43
44 1
    public function equals(self $referenceGender): bool
45
    {
46 1
        return $this->getValue() === $referenceGender->getValue();
47
    }
48
}
49