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

TaskCreated::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 18
nc 1
nop 8

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

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\DomainEvent;
18
use Kreta\TaskManager\Domain\Model\Organization\MemberId;
19
use Kreta\TaskManager\Domain\Model\Project\ProjectId;
20
21
class TaskCreated implements DomainEvent
22
{
23
    private $id;
24
    private $title;
25
    private $description;
26
    private $creatorId;
27
    private $assigneeId;
28
    private $priority;
29
    private $projectId;
30
    private $parentId;
31
    private $occurredOn;
32
33
    public function __construct(
34
        TaskId $id,
35
        TaskTitle $title,
36
        string $description,
37
        MemberId $creatorId,
38
        MemberId $assigneeId,
39
        TaskPriority $priority,
40
        ProjectId $projectId,
41
        TaskId $parentId = null
42
    ) {
43
        $this->id = $id;
44
        $this->title = $title;
45
        $this->description = $description;
46
        $this->creatorId = $creatorId;
47
        $this->assigneeId = $assigneeId;
48
        $this->projectId = $projectId;
49
        $this->priority = $priority;
50
        $this->parentId = $parentId;
51
        $this->occurredOn = new \DateTimeImmutable();
52
    }
53
54
    public function id() : TaskId
55
    {
56
        return $this->id;
57
    }
58
59
    public function title() : TaskTitle
60
    {
61
        return $this->title;
62
    }
63
64
    public function description() : string
65
    {
66
        return $this->description;
67
    }
68
69
    public function creatorId() : MemberId
70
    {
71
        return $this->creatorId;
72
    }
73
74
    public function assigneeId() : MemberId
75
    {
76
        return $this->assigneeId;
77
    }
78
79
    public function priority() : TaskPriority
80
    {
81
        return $this->priority;
82
    }
83
84
    public function projectId() : ProjectId
85
    {
86
        return $this->projectId;
87
    }
88
89
    public function parentId()
90
    {
91
        return $this->parentId;
92
    }
93
94
    public function occurredOn() : \DateTimeInterface
95
    {
96
        return $this->occurredOn;
97
    }
98
}
99