Completed
Pull Request — master (#130)
by Gorka
02:55
created

Task::title()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Kreta package.
5
 *
6
 * (c) Beñat Espiña <[email protected]>
7
 * (c) Gorka Laucirica <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
declare(strict_types=1);
14
15
namespace Kreta\TaskManager\Domain\Model\Project\Task;
16
17
use Kreta\SharedKernel\Domain\Model\AggregateRoot;
18
use Kreta\TaskManager\Domain\Model\Organization\Participant;
19
20
class Task extends AggregateRoot
21
{
22
    private $id;
23
    private $title;
24
    private $description;
25
    private $creator;
26
    private $assignee;
27
    private $priority;
28
    private $progress;
29
    private $parentId;
30
    private $createdOn;
31
    private $updatedOn;
32
33
    public function __construct(TaskId $id,
34
                                TaskTitle $title,
35
                                string $description,
36
                                Participant $creator,
37
                                Participant $assignee,
38
                                TaskPriority $priority,
39
                                TaskId $parentId = null)
40
    {
41
        $this->id = $id;
42
        $this->title = $title;
43
        $this->description = $description;
44
        $this->creator = $creator;
45
        $this->assignee = $assignee;
46
        $this->priority = $priority;
47
        $this->progress = TaskProgress::todo();
48
        $this->parentId = $parentId;
49
50
        $this->createdOn = new \DateTimeImmutable();
51
        $this->updatedOn = new \DateTimeImmutable();
52
53
        $this->publish(
54
            new TaskCreated($id, $title, $description, $creator, $assignee, $priority, $parentId)
55
        );
56
    }
57
58
    public function edit(TaskTitle $title, string $description)
59
    {
60
        $this->title = $title;
61
        $this->description = $description;
62
        $this->updatedOn = new \DateTimeImmutable();
63
64
        $this->publish(
65
            new TaskEdited($this->id, $title, $description)
66
        );
67
    }
68
69
    public function reassign(Participant $newAssignee)
70
    {
71
        $this->assignee = $newAssignee;
72
        $this->updatedOn = new \DateTimeImmutable();
73
74
        $this->publish(
75
            new TaskReassigned($this->id, $newAssignee)
76
        );
77
    }
78
79
    public function changePriority(TaskPriority $priority)
80
    {
81
        $this->priority = $priority;
82
        $this->updatedOn = new \DateTimeImmutable();
83
84
        $this->publish(
85
            new TaskPriorityChanged($this->id, $priority)
86
        );
87
    }
88
89
    public function changeProgress(TaskProgress $progress)
90
    {
91
        $this->progress = $progress;
92
        $this->updatedOn = new \DateTimeImmutable();
93
94
        $this->publish(
95
            new TaskProgressChanged($this->id, $progress)
96
        );
97
    }
98
99
    public function id() : TaskId
100
    {
101
        return $this->id;
102
    }
103
104
    public function title() : TaskTitle
105
    {
106
        return $this->title;
107
    }
108
109
    public function description() : string
110
    {
111
        return $this->description;
112
    }
113
114
    public function creator() : Participant
115
    {
116
        return $this->creator;
117
    }
118
119
    public function assignee() : Participant
120
    {
121
        return $this->assignee;
122
    }
123
124
    public function priority() : TaskPriority
125
    {
126
        return $this->priority;
127
    }
128
129
    public function progress() : TaskProgress
130
    {
131
        return $this->progress;
132
    }
133
134
    public function createdOn() : \DateTimeImmutable
135
    {
136
        return $this->createdOn;
137
    }
138
139
    public function updatedOn() : \DateTimeImmutable
140
    {
141
        return $this->updatedOn;
142
    }
143
144
    public function parentId()
145
    {
146
        return $this->parentId;
147
    }
148
149
    public function __toString() : string
150
    {
151
        return (string) $this->id->id();
152
    }
153
}
154