Completed
Branch master (6ff579)
by Tomasz
06:50 queued 03:50
created

Domain::addModel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
1
<?php
2
/**
3
 * Copyright
4
 */
5
namespace Hexarchium\CoreDomain\Model\Domain\Entity;
6
7
use Hexarchium\CoreDomain\Aggregate\AbstractAggregateRoot;
8
use Hexarchium\CoreDomain\Model\Domain\DomainId;
9
use Hexarchium\CoreDomain\Model\Domain\Events\DomainCreated;
10
use Hexarchium\CoreDomain\Model\Domain\Events\ModelAdded;
11
12
class Domain extends AbstractAggregateRoot
13
{
14
    /** @var  Model[] */
15
    private $models;
16
17
    /**
18
     * Domain constructor.
19
     *
20
     * @param DomainId $id
21
     */
22
    public function __construct(DomainId $id)
23
    {
24
        parent::__construct($id);
25
        $this->models = [];
26
27
        $this->pushEvent(
28
            new DomainCreated(new \DateTime(), $this)
29
        );
30
    }
31
32
    public function addModel(Model $model)
33
    {
34
        $this->models[] = $model;
35
36
        $this->pushEvent(
37
            new ModelAdded(new \DateTime(), $model)
38
        );
39
    }
40
}
41