Completed
Push — master ( 7c2774...f18b9d )
by Tobias
14:09 queued 06:53
created

ConfigurationManager   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 18.75%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 0
dl 0
loc 49
ccs 3
cts 16
cp 0.1875
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getConfiguration() 0 12 3
A getFirstName() 0 6 2
A getNames() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the PHP Translation package.
5
 *
6
 * (c) PHP Translation team <[email protected]>
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 Translation\Bundle\Service;
13
14
/**
15
 * @author Tobias Nyholm <[email protected]>
16
 */
17
class ConfigurationManager
18
{
19
    /**
20
     * @var array name => config
21
     */
22
    private $configuration = [];
23
24
    /**
25
     * @param array $configuration
26
     */
27 1
    public function __construct(array $configuration)
28
    {
29 1
        $this->configuration = $configuration;
30 1
    }
31
32
    /**
33
     * @return array
34
     */
35
    public function getConfiguration($name)
36
    {
37
        if (!isset($this->configuration[$name])) {
38
            if ($name === 'default') {
39
                return $this->getConfiguration($this->getFirstName());
40
            }
41
42
            return [];
43
        }
44
45
        return $this->configuration[$name];
46
    }
47
48
    /**
49
     * @return string
50
     */
51
    public function getFirstName()
52
    {
53
        foreach ($this->configuration as $name => $config) {
54
            return $name;
55
        }
56
    }
57
58
    /**
59
     * @return array
60
     */
61
    public function getNames()
62
    {
63
        return array_keys($this->configuration);
64
    }
65
}
66