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

Gender::equals()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 1
c 1
b 0
f 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
crap 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