Label::getPrecedence()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
/**
4
 * @copyright   (c) 2014-2017 brian ridley
5
 * @author      brian ridley <[email protected]>
6
 * @license     http://opensource.org/licenses/MIT MIT
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace ptlis\SemanticVersion\Version\Label;
13
14
/**
15
 * Value types for labels in version numbers.
16
 */
17
final class Label implements LabelInterface
18
{
19
    /** @var int */
20
    private $precedence;
21
22
    /** @var int|null */
23
    private $version;
24
25
    /** @var string */
26
    private $name;
27
28
29
    /**
30
     * Constructor.
31
     *
32
     * @param int $precedence
33
     * @param int|null $version
34
     * @param string $name
35
     */
36 11
    public function __construct($precedence, $version = null, $name = '')
37
    {
38
        $precedenceToNameMap = [
39 11
            self::PRECEDENCE_ALPHA => 'alpha',
40 11
            self::PRECEDENCE_BETA => 'beta',
41 11
            self::PRECEDENCE_RC => 'rc'
42 11
        ];
43
44 11
        $this->precedence = $precedence;
45 11
        $this->version = $version;
46
47 11
        if (array_key_exists($precedence, $precedenceToNameMap)) {
48 7
            $this->name = $precedenceToNameMap[$precedence];
49 7
        } else {
50 4
            $this->name = $name;
51
        }
52 11
    }
53
54
    /**
55
     * {@inheritDoc}
56
     */
57 6
    public function getPrecedence()
58
    {
59 6
        return $this->precedence;
60
    }
61
62
    /**
63
     * {@inheritDoc}
64
     */
65 11
    public function getName()
66
    {
67 11
        return strval($this->name);
68
    }
69
70
    /**
71
     * {@inheritDoc}
72
     */
73 11
    public function getVersion()
74
    {
75 11
        return $this->version;
76
    }
77
78
    /**
79
     * {@inheritDoc}
80
     */
81 11
    public function __toString()
82
    {
83 11
        $string =  $this->getName();
84
85 11
        if ($this->getVersion() > 0) {
86 5
            $string .= '.' . $this->getVersion();
87 5
        }
88
89 11
        return $string;
90
    }
91
}
92