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

Gender::__construct()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 2
nop 2
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace JeroenDesloovere\VCard\Property;
4
5
use JeroenDesloovere\VCard\Exception\PropertyException;
6
use JeroenDesloovere\VCard\Formatter\Property\GenderFormatter;
7
use JeroenDesloovere\VCard\Formatter\Property\NodeFormatterInterface;
8
use JeroenDesloovere\VCard\Parser\Property\GenderParser;
9
use JeroenDesloovere\VCard\Parser\Property\NodeParserInterface;
10
use JeroenDesloovere\VCard\Property\Parameter\GenderType;
11
12
final class Gender implements PropertyInterface, NodeInterface
13
{
14
    /**
15
     * @var GenderType
16
     */
17
    private $gender;
18
19
    /**
20
     * @var null|string
21
     */
22
    private $note;
23
24
    public function __construct(?GenderType $gender = null, ?string $note = null)
25
    {
26
        if ($gender === null && $note === null) {
27
            throw PropertyException::forEmptyProperty();
28
        }
29
30
        $this->gender = $gender ?? GenderType::empty();
31
        $this->note = $note;
32
    }
33
34
    public function getFormatter(): NodeFormatterInterface
35
    {
36
        return new GenderFormatter($this);
37
    }
38
39
    public static function getNode(): string
40
    {
41
        return 'GENDER';
42
    }
43
44
    public static function getParser(): NodeParserInterface
45
    {
46
        return new GenderParser();
47
    }
48
49
    public function isAllowedMultipleTimes(): bool
50
    {
51
        return false;
52
    }
53
54
    public function getGender(): GenderType
55
    {
56
        return $this->gender;
57
    }
58
59
    public function getNote(): ?string
60
    {
61
        return $this->note;
62
    }
63
}
64