Passed
Push — new-version ( 5cf7df...15c810 )
by Jeroen
03:21
created

Email::getFormatter()   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;
4
5
use JeroenDesloovere\VCard\Exception\PropertyException;
6
use JeroenDesloovere\VCard\Formatter\Property\EmailFormatter;
7
use JeroenDesloovere\VCard\Formatter\Property\NodeFormatterInterface;
8
use JeroenDesloovere\VCard\Parser\Property\EmailParser;
9
use JeroenDesloovere\VCard\Parser\Property\NodeParserInterface;
10
use JeroenDesloovere\VCard\Property\Parameter\Type;
11
12
final class Email implements PropertyInterface, NodeInterface
13
{
14
    /**
15
     * @var null|string
16
     */
17
    private $email;
18
19
    /**
20
     * @var Type
21
     */
22
    private $type;
23
24
    public function __construct(
25
        ?string $email = null,
26
        Type $type = null
27
    ) {
28
        if ($email === null && $type === null) {
29
            throw PropertyException::forEmptyProperty();
30
        }
31
32
        $this->email = $email;
33
        $this->type = $type ?? Type::home();
34
    }
35
36
    public function getFormatter(): NodeFormatterInterface
37
    {
38
        return new EmailFormatter($this);
39
    }
40
41
    public static function getNode(): string
42
    {
43
        return 'EMAIL';
44
    }
45
46
    public static function getParser(): NodeParserInterface
47
    {
48
        return new EmailParser();
49
    }
50
51
    public function isAllowedMultipleTimes(): bool
52
    {
53
        return true;
54
    }
55
56
    public function getEmail(): ?string
57
    {
58
        return $this->email;
59
    }
60
61
    public function getType(): Type
62
    {
63
        return $this->type;
64
    }
65
66
    public function setType(Type $type)
67
    {
68
        $this->type = $type;
69
    }
70
}
71