Version   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 113
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 76.47%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 0
dl 0
loc 113
c 0
b 0
f 0
ccs 13
cts 17
cp 0.7647
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getMajor() 0 4 1
A getMinor() 0 4 1
A getPatch() 0 4 1
A getPreRelease() 0 4 1
A getBuildMetadata() 0 4 1
A map() 0 8 2
A isStable() 0 4 2
1
<?php
2
3
/*
4
 * This file is part of questocat/version-comparator package.
5
 *
6
 * (c) questocat <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Questocat\VersionComparator;
13
14
class Version
15
{
16
    /**
17
     * The major version number.
18
     *
19
     * @var int
20
     */
21
    protected $major = 0;
22
23
    /**
24
     * The minor version number.
25
     *
26
     * @var int
27
     */
28
    protected $minor = 0;
29
30
    /**
31
     * The patch number.
32
     *
33
     * @var int
34
     */
35
    protected $patch = 0;
36
37
    /**
38
     * The pre-release version number.
39
     *
40
     * @var array
41
     */
42
    protected $preRelease = [];
43
44
    /**
45
     * The build metadata identifiers.
46
     *
47
     * @var array
48
     */
49
    protected $buildMetadata = [];
50
51
    /**
52
     * Get major.
53
     *
54
     * @return int
55
     */
56 8
    public function getMajor()
57
    {
58 8
        return $this->major;
59
    }
60
61
    /**
62
     * Get minor.
63
     *
64
     * @return int
65
     */
66 8
    public function getMinor()
67
    {
68 8
        return $this->minor;
69
    }
70
71
    /**
72
     * Get patch.
73
     *
74
     * @return int
75
     */
76 8
    public function getPatch()
77
    {
78 8
        return $this->patch;
79
    }
80
81
    /**
82
     * Get preRelease.
83
     *
84
     * @return array
85
     */
86 6
    public function getPreRelease()
87
    {
88 6
        return $this->preRelease;
89
    }
90
91
    /**
92
     * Get buildMetadata.
93
     *
94
     * @return array
95
     */
96
    public function getBuildMetadata()
97
    {
98
        return $this->buildMetadata;
99
    }
100
101
    /**
102
     * Map the given array onto the version's properties.
103
     *
104
     * @param array $attributes
105
     *
106
     * @return $this
107
     */
108 8
    public function map(array $attributes)
109
    {
110 8
        foreach ($attributes as $key => $value) {
111 8
            $this->{$key} = $value;
112 8
        }
113
114 8
        return $this;
115
    }
116
117
    /**
118
     * Checks if the version number is stable.
119
     *
120
     * @return bool
121
     */
122
    public function isStable()
123
    {
124
        return empty($this->preRelease) && 0 !== $this->major;
125
    }
126
}
127