Passed
Push — master ( 2ee0d1...1e8995 )
by Tomasz
03:21
created

Unit::getProfile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Aggrego\Domain\Model\Unit;
6
7
use Aggrego\Domain\Api\Application\Event\Aggregate;
8
use Aggrego\Domain\Api\Application\Profile\UnitTransformation\Transformation;
9
use Aggrego\Domain\Model\ProgressiveBoard\Board;
10
use Aggrego\Domain\Model\Unit\Events\UnitCreatedEvent;
11
use Aggrego\Domain\Model\Unit\Exception\UnfinishedStepPassedForTransformationException;
12
use Aggrego\Domain\Profile\Profile;
13
use Aggrego\Domain\Shared\Event\Model\TraitAggregate;
14
use Aggrego\Domain\Shared\ValueObject\Data;
15
use Aggrego\Domain\Shared\ValueObject\Key;
16
use Aggrego\Domain\Shared\ValueObject\Uuid;
17
18
class Unit implements Aggregate
19
{
20
    use TraitAggregate;
21
22
    /** @var Uuid */
23
    private $uuid;
24
25
    /** @var Key */
26
    private $key;
27
28
    /** @var Profile */
29
    private $profile;
30
31
    /** @var Data */
32
    private $data;
33
34
    private function __construct(Uuid $uuid, Key $key, Profile $profile, Data $data)
35
    {
36
        $this->uuid = $uuid;
37
        $this->key = $key;
38
        $this->profile = $profile;
39
        $this->data = $data;
40
41
        $this->pushEvent(new UnitCreatedEvent($this));
42
    }
43
44
    public static function createFromBoard(Board $board, Transformation $transformation): self
45
    {
46
        if (!$board->isStepReadyForNextTransformation()) {
47
            throw new UnfinishedStepPassedForTransformationException();
48
        }
49
50
        return new Unit(
51
            $board->getUuid(),
52
            $board->getKey(),
53
            $board->getProfile(),
54
            $transformation->process($board->getStep())
55
        );
56
    }
57
58
    public function getUuid(): Uuid
59
    {
60
        return $this->uuid;
61
    }
62
63
    public function getKey(): Key
64
    {
65
        return $this->key;
66
    }
67
68
    public function getProfile(): Profile
69
    {
70
        return $this->profile;
71
    }
72
73
    public function getData(): Data
74
    {
75
        return $this->data;
76
    }
77
}
78