Completed
Push — master ( d8eed1...b5183c )
by Peter
05:44
created

SwitchListenerTrait::changeEventNameResolver()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 2
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\Listener;
11
12
use GpsLab\Domain\Event\EventInterface;
13
use GpsLab\Domain\Event\NameResolver\EventClassLastPartResolver;
14
use GpsLab\Domain\Event\NameResolver\EventNameResolverInterface;
15
16
trait SwitchListenerTrait
17
{
18
    /**
19
     * @var EventNameResolverInterface
20
     */
21
    private $resolver;
22
23
    /**
24
     * @param EventNameResolverInterface $resolver
25
     */
26
    protected function changeEventNameResolver(EventNameResolverInterface $resolver)
27
    {
28
        $this->resolver = $resolver;
29
    }
30
31
    /**
32
     * @return EventNameResolverInterface
33
     */
34 1
    private function getEventNameResolver()
35
    {
36 1
        if (!($this->resolver instanceof EventNameResolverInterface)) {
37 1
            $this->resolver = new EventClassLastPartResolver(); // default name resolver
38 1
        }
39
40 1
        return $this->resolver;
41
    }
42
43
    /**
44
     * @param EventInterface $event
45
     */
46 1 View Code Duplication
    public function handle(EventInterface $event)
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
47
    {
48 1
        $event_name = $this->getEventNameResolver()->getEventName($event);
49 1
        $method = 'handle' . $event_name;
50
51 1
        if (method_exists($this, $method)) {
52 1
            call_user_func([$this, $method], $event);
53 1
        }
54 1
    }
55
}
56