GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 91c2d7...3fa9d7 )
by Simon
31:57 queued 22:39
created

Entity   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 77
Duplicated Lines 10.39 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 82.14%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 11
c 2
b 0
f 0
lcom 1
cbo 4
dl 8
loc 77
ccs 23
cts 28
cp 0.8214
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A handleRecursively() 0 9 2
A registerAggregateRoot() 0 8 3
A getChildren() 0 4 1
A apply() 0 7 2
A handle() 8 8 2
A getApplyMethod() 0 6 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 namespace SmoothPhp\EventSourcing;
2
3
use SmoothPhp\Contracts\EventSourcing\Event;
4
use SmoothPhp\Contracts\EventSourcing\AggregateRoot as AggregateRootContract;
5
6
/**
7
 * Abstract class Entity
8
 *
9
 * @author jrdn hannah <[email protected]>
10
 */
11
abstract class Entity implements \SmoothPhp\Contracts\EventSourcing\Entity
12
{
13
    /** @var AggregateRootContract */
14
    private $aggregateRoot;
15
16
    /**
17
     * @param Event $event
18
     * @throws Exception\AggregateRootAlreadyRegistered
19
     */
20 6
    public function handleRecursively(Event $event)
21
    {
22 6
        $this->handle($event);
23
24 6
        foreach ($this->getChildren() as $entity) {
25 3
            $entity->registerAggregateRoot($this->aggregateRoot);
26 3
            $entity->handleRecursively($event);
27 6
        }
28 6
    }
29
30
    /**
31
     * @param AggregateRootContract $aggregateRoot
32
     * @throws Exception\AggregateRootAlreadyRegistered
33
     */
34 9
    public function registerAggregateRoot(AggregateRootContract $aggregateRoot)
35
    {
36 9
        if (null !== $this->aggregateRoot && $this->aggregateRoot !== $aggregateRoot) {
37 3
            throw new Exception\AggregateRootAlreadyRegistered;
38
        }
39
40 9
        $this->aggregateRoot = $aggregateRoot;
41 9
    }
42
43
    /**
44
     * @return \SmoothPhp\Contracts\EventSourcing\Entity[] $entity
45
     */
46
    public function getChildren()
47
    {
48
        return [];
49
    }
50
51
    /**
52
     * @param Event $event
53
     * @throws Exception\NoAggregateRootRegistered
54
     */
55 3
    protected function apply(Event $event)
56
    {
57 3
        if (!$this->aggregateRoot) {
58
            throw new Exception\NoAggregateRootRegistered;
59
        }
60 3
        $this->aggregateRoot->apply($event);
61 3
    }
62
63
    /**
64
     * Handles event if capable.
65
     *
66
     * @param $event
67
     */
68 6 View Code Duplication
    protected function handle(Event $event)
0 ignored issues
show
Duplication introduced by jrdn hannah
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...
69
    {
70 6
        $method = $this->getApplyMethod($event);
71 6
        if (!method_exists($this, $method)) {
72 6
            return;
73
        }
74
        $this->$method($event);
75
    }
76
77
    /**
78
     * @param Event $event
79
     * @return string
80
     */
81 6
    private function getApplyMethod(Event $event)
82
    {
83 6
        $classParts = explode('\\', get_class($event));
84
85 6
        return 'apply' . end($classParts);
86
    }
87
}