Completed
Push — master ( 2c39fe...466032 )
by Marco
01:45
created

AbstractVersion::getVersion()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 0
crap 2
1
<?php namespace Comodojo\Foundation\Base;
2
3
use \Comodojo\Foundation\Base\Configuration;
4
use \Comodojo\Foundation\Base\ConfigurationTrait;
5
6
/**
7
 * @package     Comodojo Foundation
8
 * @author      Marco Giovinazzi <[email protected]>
9
 * @license     MIT
10
 *
11
 * LICENSE:
12
 *
13
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
 * THE SOFTWARE.
20
 */
21
22
abstract class AbstractVersion {
23
24
    use ConfigurationTrait;
25
26
    /**
27
     * Component name
28
     *
29
     * @var string
30
     */
31
    protected $name;
32
33
    /**
34
     * Component brief description
35
     *
36
     * @var string
37
     */
38
    protected $description;
39
40
    /**
41
     * Current version
42
     *
43
     * @var     string
44
     */
45
    protected $version;
46
47
    /**
48
     * Ascii fancy logo
49
     *
50
     * @var     string
51
     */
52
    protected $ascii;
53
54
    /**
55
     * Prefix for configuration item names
56
     *
57
     * @var     string
58
     */
59
    protected $prefix;
60
61
    /**
62
     * Template for full-description;
63
     *
64
     * @var     string
65
     */
66
    protected $template = "\n{ascii}\n{description} ({version})\n";
67
68
    /**
69
     * Create a version identifier class
70
     *
71
     * @param Configuration|null $configuration
72
     * @param string $prefix
0 ignored issues
show
Bug introduced by
There is no parameter named $prefix. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
73
     */
74 2
    public function __construct(Configuration $configuration = null) {
75
76 2
        if ($configuration !== null) $this->setConfiguration($configuration);
77
78 2
    }
79
80
    /**
81
     * Get the version name
82
     *
83
     * @return string
84
     */
85 2
    public function getName() {
86
87 2
        $name_override = $this->getConfigurationOverride("name");
88
89 2
        return $name_override !== null ? $name_override : $this->name;
90
91
    }
92
93
    /**
94
     * Get the version description
95
     *
96
     * @return string
97
     */
98 2
    public function getDescription() {
99
100 2
        $desc_override = $this->getConfigurationOverride("description");
101
102 2
        return $desc_override !== null ? $desc_override : $this->description;
103
104
    }
105
106
    /**
107
     * Get the current version
108
     *
109
     * @return string
110
     */
111 1
    public function getVersion() {
112
113 1
        $release_override = $this->getConfigurationOverride("release");
114
115 1
        return $release_override !== null ? $release_override : $this->version;
116
117
    }
118
119
    /**
120
     * Get the version ascii
121
     *
122
     * @return string
123
     */
124 1
    public function getAscii() {
125
126 1
        $ascii_override = $this->getConfigurationOverride("ascii");
127
128 1
        return $ascii_override !== null ? $ascii_override : $this->ascii;
129
130
    }
131
132
    /**
133
     * Return a composed-version of nominal values
134
     *
135
     * @return  string
136
     */
137
    public function getFullDescription() {
138
139
        return strtr($this->template, [
140
            "{name}" => $this->getName(),
141
            "{description}" => $this->getDescription(),
142
            "{version}" => $this->getVersion(),
143
            "{ascii}" => $this->getAscii()
144
        ]);
145
146
    }
147
148 2
    private function getConfigurationOverride($item) {
149
150 2
        return $this->configuration !== null ?
151 1
            $this->configuration->get($this->prefix."version-$item") :
152 2
            null;
153
154
    }
155
156
}
157