Completed
Push — master ( 2a0b01...28b040 )
by Tomasz
02:38
created

Domain::addUseCase()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
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
use Hexarchium\CoreDomain\Model\Domain\Events\UseCaseAdded;
12
13
class Domain extends AbstractAggregateRoot
14
{
15
    /** @var  Model[] */
16
    private $models;
17
18
    /** @var  UseCase[] */
19
    private $useCases;
20
21
    /**
22
     * Domain constructor.
23
     *
24
     * @param DomainId $id
25
     */
26
    public function __construct(DomainId $id)
27
    {
28
        parent::__construct($id);
29
        $this->models = [];
30
31
        $this->pushEvent(
32
            new DomainCreated(new \DateTime(), $this)
33
        );
34
    }
35
36
    public function addModel(Model $model)
37
    {
38
        $this->models[] = $model;
39
40
        $this->pushEvent(
41
            new ModelAdded(new \DateTime(), $model)
42
        );
43
    }
44
45
    public function addUseCase(UseCase $useCase)
46
    {
47
        $this->useCases[] = $useCase;
48
        $this->pushEvent(
49
            new UseCaseAdded(new \DateTime(), $useCase)
50
        );
51
    }
52
}
53