Completed
Push — master ( 00ae50...77d591 )
by Narcotic
27:26 queued 18:13
created

CoreUtils   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 61.9%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 0
dl 0
loc 59
ccs 13
cts 21
cp 0.619
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getVersionInHeaderFormat() 0 9 2
A getVersion() 0 8 2
A getWrapperVersion() 0 10 3
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  https://opensource.org/licenses/MIT MIT 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 = [];
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