Completed
Push — master ( 52d799...bb7198 )
by Tobias
13:11
created

ConfigurationManager::getFirstName()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

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