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

Task::edit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 2
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(
34
        TaskId $id,
35
        TaskTitle $title,
36
        string $description,
37
        Participant $creator,
38
        Participant $assignee,
39
        TaskPriority $priority,
40
        TaskId $parentId = null)
41
    {
42
        $this->id = $id;
43
        $this->title = $title;
44
        $this->description = $description;
45
        $this->creator = $creator;
46
        $this->assignee = $assignee;
47
        $this->priority = $priority;
48
        $this->progress = TaskProgress::todo();
49
        $this->parentId = $parentId;
50
51
        $this->createdOn = new \DateTimeImmutable();
52
        $this->updatedOn = new \DateTimeImmutable();
53
54
        $this->publish(
55
            new TaskCreated($id, $title, $description, $creator, $assignee, $priority, $parentId)
56
        );
57
    }
58
59
    public function edit(TaskTitle $title, string $description)
60
    {
61
        $this->title = $title;
62
        $this->description = $description;
63
        $this->updatedOn = new \DateTimeImmutable();
64
65
        $this->publish(
66
            new TaskEdited($this->id, $title, $description)
67
        );
68
    }
69
70
    public function reassign(Participant $newAssignee)
71
    {
72
        $this->assignee = $newAssignee;
73
        $this->updatedOn = new \DateTimeImmutable();
74
75
        $this->publish(
76
            new TaskReassigned($this->id, $newAssignee)
77
        );
78
    }
79
80
    public function changePriority(TaskPriority $priority)
81
    {
82
        $this->priority = $priority;
83
        $this->updatedOn = new \DateTimeImmutable();
84
85
        $this->publish(
86
            new TaskPriorityChanged($this->id, $priority)
87
        );
88
    }
89
90
    public function changeProgress(TaskProgress $progress)
91
    {
92
        $this->progress = $progress;
93
        $this->updatedOn = new \DateTimeImmutable();
94
95
        $this->publish(
96
            new TaskProgressChanged($this->id, $progress)
97
        );
98
    }
99
100
    public function id() : TaskId
101
    {
102
        return $this->id;
103
    }
104
105
    public function title() : TaskTitle
106
    {
107
        return $this->title;
108
    }
109
110
    public function description() : string
111
    {
112
        return $this->description;
113
    }
114
115
    public function creator() : Participant
116
    {
117
        return $this->creator;
118
    }
119
120
    public function assignee() : Participant
121
    {
122
        return $this->assignee;
123
    }
124
125
    public function priority() : TaskPriority
126
    {
127
        return $this->priority;
128
    }
129
130
    public function progress() : TaskProgress
131
    {
132
        return $this->progress;
133
    }
134
135
    public function createdOn() : \DateTimeImmutable
136
    {
137
        return $this->createdOn;
138
    }
139
140
    public function updatedOn() : \DateTimeImmutable
141
    {
142
        return $this->updatedOn;
143
    }
144
145
    public function parentId()
146
    {
147
        return $this->parentId;
148
    }
149
150
    public function __toString() : string
151
    {
152
        return (string) $this->id->id();
153
    }
154
}
155