Completed
Pull Request — master (#602)
by Tom
07:15
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.94%

Importance

Changes 0
Metric Value
wmc 6
lcom 2
cbo 1
dl 0
loc 67
ccs 9
cts 17
cp 0.5294
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace DoctrineORMModule\Options;
6
7
use InvalidArgumentException;
8
use Laminas\Stdlib\AbstractOptions;
9
use function class_exists;
10
use function sprintf;
11
12
class EntityResolver extends AbstractOptions
13
{
14
    /**
15
     * Set the configuration key for the EventManager. Event manager key
16
     * is assembled as "doctrine.eventmanager.{key}" and pulled from
17
     * service locator.
18
     */
19
    protected string $eventManager = 'orm_default';
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_STRING, expecting T_FUNCTION or T_CONST
Loading history...
20
21
    /**
22
     * An array that maps a class name (or interface name) to another class
23
     * name
24
     *
25
     * @var string[]
26
     */
27
    protected array $resolvers = [];
28
29
    public function setEventManager(string $eventManager) : self
30
    {
31
        $this->eventManager = $eventManager;
32
33
        return $this;
34
    }
35
36
    public function getEventManager() : string
37
    {
38
        return 'doctrine.eventmanager.' . $this->eventManager;
39
    }
40
41 72
    /**
42
     * @param  string[] $resolvers
43 72
     *
44
     * @throws InvalidArgumentException
45
     */
46
    public function setResolvers(array $resolvers) : void
47
    {
48
        foreach ($resolvers as $old => $new) {
49
            if (! class_exists($new)) {
50 72
                throw new InvalidArgumentException(
51
                    sprintf(
52 72
                        '%s is resolved to the entity %s, which does not exist',
53 72
                        $old,
54
                        $new
55
                    )
56
                );
57
            }
58
59
            $this->resolvers[$old] = $new;
60
        }
61
    }
62
63 72
    /**
64
     * @return string[]
65 72
     */
66
    public function getResolvers() : array
67
    {
68
        return $this->resolvers;
69
    }
70
}
71