Completed
Push — master ( 50808e...33b518 )
by Gianluca
05:07
created

EntityResolver   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Test Coverage

Coverage 52.63%

Importance

Changes 0
Metric Value
wmc 6
lcom 2
cbo 1
dl 0
loc 67
ccs 10
cts 19
cp 0.5263
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setEventManager() 0 6 1
A getEventManager() 0 4 1
A setResolvers() 0 16 3
A getResolvers() 0 4 1
1
<?php
2
3
namespace DoctrineORMModule\Options;
4
5
use InvalidArgumentException;
6
use Zend\Stdlib\AbstractOptions;
7
8
class EntityResolver extends AbstractOptions
9
{
10
    /**
11
     * Set the configuration key for the EventManager. Event manager key
12
     * is assembled as "doctrine.eventmanager.{key}" and pulled from
13
     * service locator.
14
     *
15
     * @var string
16
     */
17
    protected $eventManager = 'orm_default';
18
19
    /**
20
     * An array that maps a class name (or interface name) to another class
21
     * name
22
     *
23
     * @var array
24
     */
25
    protected $resolvers = array();
26
27
    /**
28
     * @param  string $eventManager
29
     * @return self
30
     */
31
    public function setEventManager($eventManager)
32
    {
33
        $this->eventManager = $eventManager;
34
35
        return $this;
36
    }
37
38
    /**
39
     * @return string
40
     */
41 56
    public function getEventManager()
42
    {
43 56
        return "doctrine.eventmanager.{$this->eventManager}";
44
    }
45
46
    /**
47
     * @param  array                    $resolvers
48
     * @throws InvalidArgumentException
49
     */
50 56
    public function setResolvers(array $resolvers)
51
    {
52 56
        foreach ($resolvers as $old => $new) {
53 56
            if (!class_exists($new)) {
54
                throw new InvalidArgumentException(
55
                    sprintf(
56
                        '%s is resolved to the entity %s, which does not exist',
57
                        $old,
58
                        $new
59
                    )
60
                );
61
            }
62
63 56
            $this->resolvers[$old] = $new;
64 56
        }
65 56
    }
66
67
    /**
68
     * @return array
69
     */
70 56
    public function getResolvers()
71
    {
72 56
        return $this->resolvers;
73
    }
74
}
75