Completed
Pull Request — master (#143)
by Beñat
03:47 queued 46s
created

Task   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 143
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 0
Metric Value
wmc 17
lcom 1
cbo 8
dl 0
loc 143
rs 10
c 0
b 0
f 0

17 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 27 1
A edit() 0 10 1
A reassign() 0 9 1
A changePriority() 0 9 1
A changeProgress() 0 9 1
A id() 0 4 1
A title() 0 4 1
A description() 0 4 1
A creatorId() 0 4 1
A assigneeId() 0 4 1
A priority() 0 4 1
A progress() 0 4 1
A createdOn() 0 4 1
A updatedOn() 0 4 1
A projectId() 0 4 1
A parentId() 0 4 1
A __toString() 0 4 1
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\MemberId;
19
use Kreta\TaskManager\Domain\Model\Project\ProjectId;
20
21
class Task extends AggregateRoot
22
{
23
    private $id;
24
    private $title;
25
    private $description;
26
    private $creatorId;
27
    private $assigneeId;
28
    private $priority;
29
    private $progress;
30
    private $projectId;
31
    private $parentId;
32
    private $createdOn;
33
    private $updatedOn;
34
35
    public function __construct(
36
        TaskId $id,
37
        TaskTitle $title,
38
        string $description,
39
        MemberId $creatorId,
40
        MemberId $assigneeId,
41
        TaskPriority $priority,
42
        ProjectId $projectId,
43
        TaskId $parentId = null
44
    ) {
45
        $this->id = $id;
46
        $this->title = $title;
47
        $this->description = $description;
48
        $this->creatorId = $creatorId;
49
        $this->assigneeId = $assigneeId;
50
        $this->priority = $priority;
51
        $this->progress = TaskProgress::todo();
52
        $this->projectId = $projectId;
53
        $this->parentId = $parentId;
54
55
        $this->createdOn = new \DateTimeImmutable();
56
        $this->updatedOn = new \DateTimeImmutable();
57
58
        $this->publish(
59
            new TaskCreated($id, $title, $description, $creatorId, $assigneeId, $priority, $projectId, $parentId)
60
        );
61
    }
62
63
    public function edit(TaskTitle $title, string $description)
64
    {
65
        $this->title = $title;
66
        $this->description = $description;
67
        $this->updatedOn = new \DateTimeImmutable();
68
69
        $this->publish(
70
            new TaskEdited($this->id, $title, $description)
71
        );
72
    }
73
74
    public function reassign(MemberId $newAssigneeId)
75
    {
76
        $this->assignee = $newAssigneeId;
0 ignored issues
show
Bug introduced by
The property assignee does not seem to exist. Did you mean assigneeId?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
77
        $this->updatedOn = new \DateTimeImmutable();
78
79
        $this->publish(
80
            new TaskReassigned($this->id, $newAssigneeId)
81
        );
82
    }
83
84
    public function changePriority(TaskPriority $priority)
85
    {
86
        $this->priority = $priority;
87
        $this->updatedOn = new \DateTimeImmutable();
88
89
        $this->publish(
90
            new TaskPriorityChanged($this->id, $priority)
91
        );
92
    }
93
94
    public function changeProgress(TaskProgress $progress)
95
    {
96
        $this->progress = $progress;
97
        $this->updatedOn = new \DateTimeImmutable();
98
99
        $this->publish(
100
            new TaskProgressChanged($this->id, $progress)
101
        );
102
    }
103
104
    public function id() : TaskId
105
    {
106
        return $this->id;
107
    }
108
109
    public function title() : TaskTitle
110
    {
111
        return $this->title;
112
    }
113
114
    public function description() : string
115
    {
116
        return $this->description;
117
    }
118
119
    public function creatorId() : MemberId
120
    {
121
        return $this->creatorId;
122
    }
123
124
    public function assigneeId() : MemberId
125
    {
126
        return $this->assigneeId;
127
    }
128
129
    public function priority() : TaskPriority
130
    {
131
        return $this->priority;
132
    }
133
134
    public function progress() : TaskProgress
135
    {
136
        return $this->progress;
137
    }
138
139
    public function createdOn() : \DateTimeImmutable
140
    {
141
        return $this->createdOn;
142
    }
143
144
    public function updatedOn() : \DateTimeImmutable
145
    {
146
        return $this->updatedOn;
147
    }
148
149
    public function projectId() : ProjectId
150
    {
151
        return $this->projectId;
152
    }
153
154
    public function parentId()
155
    {
156
        return $this->parentId;
157
    }
158
159
    public function __toString() : string
160
    {
161
        return (string) $this->id->id();
162
    }
163
}
164