Passed
Push — new-version ( ea57ed...2c5e64 )
by Jeroen
05:46 queued 02:59
created

Version::isVersion3()   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
use JeroenDesloovere\VCard\Formatter\Property\NodeFormatterInterface;
7
use JeroenDesloovere\VCard\Formatter\Property\Parameter\VersionFormatter;
8
use JeroenDesloovere\VCard\Parser\Property\NodeParserInterface;
9
use JeroenDesloovere\VCard\Parser\Property\Parameter\VersionParser;
10
use JeroenDesloovere\VCard\Property\SimpleNodeInterface;
11
12
final class Version implements PropertyParameterInterface, SimpleNodeInterface
13
{
14
    protected const VERSION_3 = '3.0';
15
    protected const VERSION_4 = '4.0';
16
17
    public const POSSIBLE_VALUES = [
18
        self::VERSION_3,
19
        self::VERSION_4,
20
    ];
21
22
    private $value;
23
24
    public function __construct(string $value)
25
    {
26
        if (!in_array($value, self::POSSIBLE_VALUES, true)) {
27
            throw PropertyParameterException::forWrongValue($value, self::POSSIBLE_VALUES);
28
        }
29
30
        $this->value = $value;
31
    }
32
33
    public function __toString(): string
34
    {
35
        return $this->value;
36
    }
37
38
    public function getFormatter(): NodeFormatterInterface
39
    {
40
        return new VersionFormatter($this);
41
    }
42
43
    public static function getNode(): string
44
    {
45
        return 'VERSION';
46
    }
47
48
    public static function getParser(): NodeParserInterface
49
    {
50
        return new VersionParser();
51
    }
52
53
    public static function version3(): self
54
    {
55
        return new self(self::VERSION_3);
56
    }
57
58
    public function isVersion3(): bool
59
    {
60
        return $this->value === self::VERSION_3;
61
    }
62
63
    public static function version4(): self
64
    {
65
        return new self(self::VERSION_4);
66
    }
67
68
    public function isVersion4(): bool
69
    {
70
        return $this->value === self::VERSION_4;
71
    }
72
}
73