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

ConfigurationManager::getNames()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
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