Completed
Push — master ( 1ec574...c8c410 )
by Tobias
10:40 queued 40s
created

ConfigurationManager::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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
use Translation\Bundle\Model\Configuration;
15
16
/**
17
 * A service to easily access different configurations.
18
 *
19
 * @author Tobias Nyholm <[email protected]>
20
 */
21
class ConfigurationManager
22
{
23
    /**
24
     * @var Configuration[]
25
     */
26
    private $configuration = [];
27 1
28
    /**
29 1
     * @param string        $name
30 1
     * @param Configuration $configuration
31
     */
32
    public function addConfiguration($name, Configuration $configuration)
33
    {
34
        $this->configuration[$name] = $configuration;
35
    }
36
37
    /**
38
     * @param string $name
39
     *
40
     * @return null|Configuration
41
     */
42
    public function getConfiguration($name = 'default')
43
    {
44
        if (!isset($this->configuration[$name])) {
45
            if ($name === 'default') {
46
                return $this->getConfiguration($this->getFirstName());
47
            }
48
49
            return;
50
        }
51
52
        return $this->configuration[$name];
53
    }
54
55
    /**
56
     * @return string
57
     */
58
    public function getFirstName()
59
    {
60
        foreach ($this->configuration as $name => $config) {
61
            return $name;
62
        }
63
    }
64
65
    /**
66
     * @return array
67
     */
68
    public function getNames()
69
    {
70
        return array_keys($this->configuration);
71
    }
72
}
73