AbstractEntity   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 23
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A setAggregateRoot() 0 12 3
1
<?php
2
/*
3
 * This file is part of the Borobudur-Cqrs package.
4
 *
5
 * (c) Hexacodelabs <http://hexacodelabs.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Borobudur\Cqrs;
12
13
use Borobudur\Cqrs\Exception\InvalidArgumentException;
14
15
/**
16
 * @author      Iqbal Maulana <[email protected]>
17
 * @created     8/18/15
18
 */
19
abstract class AbstractEntity implements EntityInterface
20
{
21
    /**
22
     * @var AggregateRootInterface
23
     */
24
    protected $aggregateRoot;
25
26
    /**
27
     * {@inheritdoc}
28
     */
29
    final public function setAggregateRoot(AggregateRootInterface $aggregateRoot)
30
    {
31
        if (null !== $this->aggregateRoot && $aggregateRoot !== $this->aggregateRoot) {
32
            throw new InvalidArgumentException(sprintf(
33
               'Aggregate root "%s" already registered on "%s".',
34
                get_class($aggregateRoot),
35
                get_called_class()
36
            ));
37
        }
38
39
        $this->aggregateRoot = $aggregateRoot;
40
    }
41
}
42