Domain   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
lcom 1
cbo 6
dl 0
loc 43
rs 10
c 1
b 0
f 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A addModel() 0 9 1
A addUseCase() 0 9 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
        $model->setDomain($this);
40
41
        $this->pushEvent(
42
            new ModelAdded(new \DateTime(), $model)
43
        );
44
    }
45
46
    public function addUseCase(UseCase $useCase)
47
    {
48
        $this->useCases[] = $useCase;
49
        $useCase->setDomain($this);
50
51
        $this->pushEvent(
52
            new UseCaseAdded(new \DateTime(), $useCase)
53
        );
54
    }
55
}
56