AbstractEvent   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
c 2
b 0
f 0
lcom 1
cbo 2
dl 0
loc 35
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setAggregateRootId() 0 14 3
A getAggregateRootId() 0 4 1
1
<?php
2
3
namespace PhpDDD\Domain\Event;
4
5
use PhpDDD\Domain\Event\Utils\EventName;
6
use PhpDDD\Domain\Exception\RuntimeException;
7
8
abstract class AbstractEvent implements EventInterface
9
{
10
    /**
11
     * @var mixed
12
     */
13
    private $aggregateRootId;
14
15
    /**
16
     * @param mixed $aggregateRootId
17
     *
18
     * @throws RuntimeException When setting an aggregate id where one already exists.
19
     */
20
    public function setAggregateRootId($aggregateRootId)
21
    {
22
        if (null !== $this->aggregateRootId && $aggregateRootId !== $this->aggregateRootId) {
23
            $eventName = new EventName($this);
24
            throw new RuntimeException(
25
                sprintf(
26
                    'Event %s: The aggregate root id is already set and is different from the one given.',
27
                    $eventName
28
                )
29
            );
30
        }
31
32
        $this->aggregateRootId = $aggregateRootId;
33
    }
34
35
    /**
36
     * @return mixed
37
     */
38
    public function getAggregateRootId()
39
    {
40
        return $this->aggregateRootId;
41
    }
42
}
43