Completed
Push — master ( 024186...18bea3 )
by Peter
06:06
created

NameResolverContainer::changeResolver()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * GpsLab component.
4
 *
5
 * @author    Peter Gribanov <[email protected]>
6
 * @copyright Copyright (c) 2016, Peter Gribanov
7
 * @license   http://opensource.org/licenses/MIT
8
 */
9
10
namespace GpsLab\Domain\Event\NameResolver;
11
12
/**
13
 * It's a global container for get event name resolver in entities.
14
 *
15
 * It's need for not duplicate code
16
 *
17
 * @see AggregateEventsRaiseInSelfTrait::getMethodNameFromEvent()
18
 * @see SwitchListenerTrait::getMethodNameFromEvent()
19
 */
20
class NameResolverContainer
21
{
22
    /**
23
     * @var EventNameResolverInterface
24
     */
25
    private static $resolver;
26
27
    /**
28
     * @param EventNameResolverInterface $resolver
29
     */
30 1
    public static function changeResolver(EventNameResolverInterface $resolver)
31
    {
32 1
        self::$resolver = $resolver;
33 1
    }
34
35
    /**
36
     * @return EventNameResolverInterface
37
     */
38 5
    public static function getResolver()
39
    {
40 5
        if (!(self::$resolver instanceof EventNameResolverInterface)) {
41 1
            self::$resolver = new EventClassLastPartResolver(); // default name resolver
42 1
        }
43
44 5
        return self::$resolver;
45
    }
46
}
47