Completed
Pull Request — new-version (#111)
by Tom
02:24
created

GenderType::female()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace JeroenDesloovere\VCard\Property\Parameter;
4
5
use JeroenDesloovere\VCard\Exception\PropertyParameterException;
6
7
final class GenderType
8
{
9
    private const EMPTY = '';
10
11
    private const MALE = 'M';
12
13
    private const FEMALE = 'F';
14
15
    private const OTHER = 'O';
16
17
    /**
18
     * N stands for "none or not applicable"
19
     */
20
    private const NONE = 'N';
21
22
    private const UNKNOWN = 'U';
23
24
    public const POSSIBLE_VALUES = [
25
        self::EMPTY,
26
        self::MALE,
27
        self::FEMALE,
28
        self::OTHER,
29
        self::NONE,
30
        self::UNKNOWN,
31
    ];
32
33
    /**
34
     * @var string
35
     */
36
    private $value;
37
38
    public function __construct(string $value)
39
    {
40
        if (!in_array($value, self::POSSIBLE_VALUES, true)) {
41
            throw PropertyParameterException::forWrongValue($value, self::POSSIBLE_VALUES);
42
        }
43
44
        $this->value = $value;
45
    }
46
47
    public function __toString(): string
48
    {
49
        return $this->value;
50
    }
51
52
    public static function empty(): self
53
    {
54
        return new self(self::EMPTY);
55
    }
56
57
    public function isEmpty(): bool
58
    {
59
        return $this->value === self::EMPTY;
60
    }
61
62
    public static function male(): self
63
    {
64
        return new self(self::MALE);
65
    }
66
67
    public function isMale(): bool
68
    {
69
        return $this->value === self::MALE;
70
    }
71
72
    public static function female(): self
73
    {
74
        return new self(self::FEMALE);
75
    }
76
77
    public function isFemale(): bool
78
    {
79
        return $this->value === self::FEMALE;
80
    }
81
82
    public static function other(): self
83
    {
84
        return new self(self::OTHER);
85
    }
86
87
    public function isOther(): bool
88
    {
89
        return $this->value === self::OTHER;
90
    }
91
92
    public static function none(): self
93
    {
94
        return new self(self::NONE);
95
    }
96
97
    public function isNone(): bool
98
    {
99
        return $this->value === self::NONE;
100
    }
101
102
    public static function unknown(): self
103
    {
104
        return new self(self::UNKNOWN);
105
    }
106
107
    public function isUnknown(): bool
108
    {
109
        return $this->value === self::UNKNOWN;
110
    }
111
}
112