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
Pull Request — develop (#22)
by jrdn
11:31 queued 08:22
created

Entity::apply()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
ccs 4
cts 5
cp 0.8
rs 9.4286
cc 2
eloc 4
nc 2
nop 1
crap 2.032
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
    /** @var \SmoothPhp\Contracts\EventSourcing\Entity[] */
17
    private $children = [];
18
19
    /**
20
     * @param Event $event
21
     * @throws Exception\AggregateRootAlreadyRegistered
22
     */
23 6
    public function handleRecursively(Event $event)
24
    {
25 6
        $this->handle($event);
26
27 6
        foreach ($this->children as $entity) {
28 3
            $entity->registerAggregateRoot($this->aggregateRoot);
29 3
            $entity->handleRecursively($event);
30 6
        }
31 6
    }
32
33
    /**
34
     * @param AggregateRootContract $aggregateRoot
35
     * @throws Exception\AggregateRootAlreadyRegistered
36
     */
37 9
    public function registerAggregateRoot(AggregateRootContract $aggregateRoot)
38
    {
39 9
        if (null !== $this->aggregateRoot && $this->aggregateRoot !== $aggregateRoot) {
40 3
            throw new Exception\AggregateRootAlreadyRegistered;
41
        }
42
43 9
        $this->aggregateRoot = $aggregateRoot;
44 9
    }
45
46
    /**
47
     * @param \SmoothPhp\Contracts\EventSourcing\Entity $entity
48
     */
49 3
    public function addChildEntity(\SmoothPhp\Contracts\EventSourcing\Entity $entity)
50
    {
51 3
        $this->children[] = $entity;
52 3
    }
53
54
    /**
55
     * @param Event $event
56
     * @throws Exception\NoAggregateRootRegistered
57
     */
58 3
    protected function apply(Event $event)
59
    {
60 3
        if (!$this->aggregateRoot) {
61
            throw new Exception\NoAggregateRootRegistered;
62
        }
63 3
        $this->aggregateRoot->apply($event);
64 3
    }
65
66
    /**
67
     * Handles event if capable.
68
     *
69
     * @param $event
70
     */
71 6 View Code Duplication
    protected function handle(Event $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...
72
    {
73 6
        $method = $this->getApplyMethod($event);
74 6
        if (!method_exists($this, $method)) {
75 6
            return;
76
        }
77
        $this->$method($event);
78
    }
79
80
    /**
81
     * @param Event $event
82
     * @return string
83
     */
84 6
    private function getApplyMethod(Event $event)
85
    {
86 6
        $classParts = explode('\\', get_class($event));
87
88 6
        return 'apply' . end($classParts);
89
    }
90
}