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

Version   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 47
rs 10
c 0
b 0
f 0
wmc 8

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 2
A getFormatter() 0 3 1
A __toString() 0 3 1
A version4() 0 3 1
A getNode() 0 3 1
A isVersion4() 0 3 1
A getParser() 0 3 1
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