Registry   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 44
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 4 1
A get() 0 4 1
A getFromConfiguration() 0 6 1
1
<?php
2
3
namespace Pim\Bundle\CustomEntityBundle\Manager;
4
5
use Pim\Bundle\CustomEntityBundle\Configuration\ConfigurationInterface;
6
7
/**
8
 * Registry for managers
9
 *
10
 * @author    Antoine Guigan <[email protected]>
11
 * @copyright 2014 Akeneo SAS (http://www.akeneo.com)
12
 * @license   http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
13
 */
14
class Registry
15
{
16
    /**
17
     * @var ManagerInterface[]
18
     */
19
    protected $managers = [];
20
21
    /**
22
     * Add a manager for a class name
23
     *
24
     * @param string           $key
25
     * @param ManagerInterface $manager
26
     */
27
    public function add($key, ManagerInterface $manager)
28
    {
29
        $this->managers[$key] = $manager;
30
    }
31
32
    /**
33
     * Returns a manager
34
     *
35
     * @param string $key
36
     *
37
     * @return ManagerInterface
38
     */
39
    public function get($key)
40
    {
41
        return $this->managers[$key];
42
    }
43
44
    /**
45
     * Returns a manager for a configuration
46
     *
47
     * @param ConfigurationInterface $configuration
48
     *
49
     * @return ManagerInterface
50
     */
51
    public function getFromConfiguration(ConfigurationInterface $configuration)
52
    {
53
        $options = $configuration->getOptions();
54
55
        return $this->get($options['manager']);
56
    }
57
}
58