Passed
Branch new-version (84e8bd)
by Jeroen
03:20
created

Version::getValue()   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_4 = '4.0';
15
16
    public const POSSIBLE_VALUES = [
17
        self::VERSION_4,
18
    ];
19
20
    private $value;
21
22
    public function __construct(string $value)
23
    {
24
        if (!in_array($value, self::POSSIBLE_VALUES, true)) {
25
            throw PropertyParameterException::forWrongValue($value, self::POSSIBLE_VALUES);
26
        }
27
28
        $this->value = $value;
29
    }
30
31
    public function __toString(): string
32
    {
33
        return $this->value;
34
    }
35
36
    public function getFormatter(): NodeFormatterInterface
37
    {
38
        return new VersionFormatter($this);
39
    }
40
41
    public static function getNode(): string
42
    {
43
        return 'VERSION';
44
    }
45
46
    public static function getParser(): NodeParserInterface
47
    {
48
        return new VersionParser();
49
    }
50
51
    public static function version4(): self
52
    {
53
        return new self(self::VERSION_4);
54
    }
55
56
    public function isVersion4(): bool
57
    {
58
        return $this->value === self::VERSION_4;
59
    }
60
}
61