Projector   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 60
Duplicated Lines 30 %

Importance

Changes 0
Metric Value
dl 18
loc 60
rs 10
c 0
b 0
f 0
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 8 8 2
A getLastClassParts() 0 5 1
A rollback() 8 8 2
A getRollbackMethod() 0 3 1
A getHandleMethod() 0 3 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * This file is part of the Simple EventStore Manager package.
4
 *
5
 * (c) Mauro Cassani<https://github.com/mauretto78>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace SimpleEventStoreManager\Infrastructure\Projector;
12
13
use SimpleEventStoreManager\Domain\Model\Contracts\EventInterface;
14
use SimpleEventStoreManager\Infrastructure\Projector\Exceptions\ProjectorHandleMethodDoesNotExistsException;
15
use SimpleEventStoreManager\Infrastructure\Projector\Exceptions\ProjectorRollbackMethodDoesNotExistsException;
16
17
abstract class Projector
18
{
19
    /**
20
     * @return array
21
     */
22
    abstract public function subcribedEvents();
23
24
    /**
25
     * {@inheritDoc}
26
     */
27 View Code Duplication
    public function handle(EventInterface $event)
0 ignored issues
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...
28
    {
29
        $method = $this->getHandleMethod($event);
30
        if (! method_exists($this, $method)) {
31
            throw new ProjectorHandleMethodDoesNotExistsException(get_class($this) . ' does not implement ' . $method . ' method.');
32
        }
33
34
        $this->$method($event);
35
    }
36
37
    /**
38
     * @param $event
39
     * @return string
40
     */
41
    private function getHandleMethod($event)
42
    {
43
        return 'apply' . $this->getLastClassParts($event);
0 ignored issues
show
Bug introduced by
Are you sure $this->getLastClassParts($event) of type array can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

43
        return 'apply' . /** @scrutinizer ignore-type */ $this->getLastClassParts($event);
Loading history...
44
    }
45
46
    /**
47
     * @param $class
48
     * @return array
49
     */
50
    private function getLastClassParts($class)
51
    {
52
        $classParts = explode('\\', get_class($class));
53
54
        return end($classParts);
55
    }
56
57
    /**
58
     * {@inheritDoc}
59
     */
60 View Code Duplication
    public function rollback(EventInterface $event)
0 ignored issues
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...
61
    {
62
        $method = $this->getRollbackMethod($event);
63
        if (! method_exists($this, $method)) {
64
            throw new ProjectorRollbackMethodDoesNotExistsException(get_class($this) . ' does not implement ' . $method . ' method.');
65
        }
66
67
        $this->$method($event);
68
    }
69
70
    /**
71
     * @param $event
72
     * @return string
73
     */
74
    private function getRollbackMethod($event)
75
    {
76
        return 'rollback' . $this->getLastClassParts($event);
0 ignored issues
show
Bug introduced by
Are you sure $this->getLastClassParts($event) of type array can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

76
        return 'rollback' . /** @scrutinizer ignore-type */ $this->getLastClassParts($event);
Loading history...
77
    }
78
}
79