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 (#21)
by jrdn
05:40 queued 03:32
created

Entity::addChildEntity()   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 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 AggregateRoot */
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;
0 ignored issues
show
Documentation Bug introduced by
$aggregateRoot is of type object<SmoothPhp\Contrac...Sourcing\AggregateRoot>, but the property $aggregateRoot was declared to be of type object<SmoothPhp\EventSourcing\AggregateRoot>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
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
}