Completed
Push — develop ( e55011...fb44ee )
by
unknown
13s
created

CoreUtils::getVersion()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 0
cts 6
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 0
crap 6
1
<?php
2
/**
3
 * A service providing some core util functions.
4
 */
5
6
namespace Graviton\CoreBundle\Service;
7
8
/**
9
 * @author   List of contributors <https://github.com/libgraviton/graviton/graphs/contributors>
10
 * @license  http://opensource.org/licenses/gpl-license.php GNU Public License
11
 * @link     http://swisscom.ch
12
 */
13
class CoreUtils
14
{
15
    /**
16
     * @var array holds all version numbers of installed packages
17
     */
18
    private $versions;
19
20
    /**
21
     * @param array $versions Array containing version numbers of installed packages
22
     */
23 8
    public function __construct($versions)
24
    {
25 8
        $this->versions = $versions;
26 8
    }
27
28
    /**
29
     * returns versions in response header format
30
     *
31
     * @return string version
32
     */
33 2
    public function getVersionInHeaderFormat()
34
    {
35 2
        $versionHeader = '';
36 2
        foreach ($this->versions as $name => $version) {
37 2
            $versionHeader .= $version['id'] . ': ' . $version['version'] . '; ';
38 1
        }
39
40 2
        return $versionHeader;
41
    }
42
43
    /**
44
     * @return array versions
45
     */
46
    public function getVersion()
47
    {
48
        $ver = array();
49
        foreach ($this->versions as $version) {
50
            $ver[$version['id']]= $version['version'];
51
        }
52
        return $ver;
53
    }
54
55
    /**
56
     * Finds the version of the current wrapper.
57
     *
58
     * @return array wrapper version
59
     * @throws \RuntimeException in case version was not found in versions stack.
60
     */
61 2
    public function getWrapperVersion()
62
    {
63 2
        foreach ($this->versions as $version) {
64 2
            if ($version['id'] === 'self') {
65 2
                return $version;
66
            }
67
        }
68
69
        throw new \RuntimeException('No version »self« available.');
70
    }
71
}
72