AbstractEvent::setAggregateRootId()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 14
rs 9.4285
cc 3
eloc 8
nc 2
nop 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