Completed
Push — master ( 706672...0f2117 )
by Daniel
02:07
created

MergeRequest::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 10
nc 1
nop 10
dl 0
loc 22
ccs 11
cts 11
cp 1
crap 1
rs 9.9332
c 0
b 0
f 0

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 declare(strict_types=1);
2
3
namespace DanielPieper\MergeReminder\ValueObject;
4
5
class MergeRequest
6
{
7
    public const STATE_OPENED = 'opened';
8
    public const STATE_CLOSED = 'closed';
9
    public const STATE_LOCKED = 'locked';
10
    public const STATE_MERGED = 'merged';
11
12
    /** @var int */
13
    private $id;
14
15
    /** @var int */
16
    private $iid;
17
18
    /** @var string */
19
    private $title;
20
21
    /** @var string */
22
    private $description;
23
24
    /** @var string */
25
    private $state;
26
27
    /** @var string */
28
    private $webUrl;
29
30
    /** @var bool */
31
    private $isWorkInProgress;
32
33
    /** @var Project */
34
    private $project;
35
36
    /** @var User */
37
    private $author;
38
39
    /** @var User */
40
    private $assignee;
41
42
    /**
43
     * Project constructor.
44
     * @param int $id
45
     * @param int $iid
46
     * @param string $title
47
     * @param string $description
48
     * @param string $state
49
     * @param string $webUrl
50
     * @param bool $isWorkInProgress
51
     * @param Project $project
52
     * @param User $author
53
     * @param User $assignee
54
     *
55
     * @SuppressWarnings(PHPMD.ExcessiveParameterList)
56
     */
57 16
    public function __construct(
58
        int $id,
59
        int $iid,
60
        string $title,
61
        string $description,
62
        string $state,
63
        string $webUrl,
64
        bool $isWorkInProgress,
65
        Project $project,
66
        User $author,
67
        ?User $assignee = null
68
    ) {
69 16
        $this->id = $id;
70 16
        $this->iid = $iid;
71 16
        $this->title = $title;
72 16
        $this->description = $description;
73 16
        $this->state = $state;
74 16
        $this->webUrl = $webUrl;
75 16
        $this->isWorkInProgress = $isWorkInProgress;
76 16
        $this->project = $project;
77 16
        $this->author = $author;
78 16
        $this->assignee = $assignee;
79 16
    }
80
81
    /**
82
     * @param array $mergeRequest
83
     * @return MergeRequest
84
     */
85 16
    public static function fromArray(array $mergeRequest): self
86
    {
87 16
        return new self(
88 16
            (int)$mergeRequest['id'],
89 16
            (int)$mergeRequest['iid'],
90 16
            (string)$mergeRequest['title'],
91 16
            (string)$mergeRequest['description'],
92 16
            (string)$mergeRequest['state'],
93 16
            (string)$mergeRequest['web_url'],
94 16
            (bool)$mergeRequest['work_in_progress'],
95 16
            $mergeRequest['project'],
96 16
            $mergeRequest['author'],
97 16
            $mergeRequest['assignee']
98
        );
99
    }
100
101
    /**
102
     * @return int
103
     */
104 5
    public function getIid(): int
105
    {
106 5
        return $this->iid;
107
    }
108
109
    /**
110
     * @return int
111
     */
112 1
    public function getId(): int
113
    {
114 1
        return $this->id;
115
    }
116
117
    /**
118
     * @return string
119
     */
120 2
    public function getTitle(): string
121
    {
122 2
        return $this->title;
123
    }
124
125
    /**
126
     * @return string
127
     */
128 2
    public function getDescription(): string
129
    {
130 2
        return $this->description;
131
    }
132
133
    /**
134
     * @return string
135
     */
136
    public function getState(): string
137
    {
138
        return $this->state;
139
    }
140
141
    /**
142
     * @return bool
143
     */
144
    public function isOpened(): bool
145
    {
146
        return $this->state === self::STATE_OPENED;
147
    }
148
149
    /**
150
     * @return bool
151
     */
152
    public function isClosed(): bool
153
    {
154
        return $this->state === self::STATE_CLOSED;
155
    }
156
157
    /**
158
     * @return bool
159
     */
160
    public function isLocked(): bool
161
    {
162
        return $this->state === self::STATE_LOCKED;
163
    }
164
165
    /**
166
     * @return bool
167
     */
168
    public function isMerged(): bool
169
    {
170
        return $this->state === self::STATE_MERGED;
171
    }
172
173
    /**
174
     * @return string
175
     */
176 2
    public function getWebUrl(): string
177
    {
178 2
        return $this->webUrl;
179
    }
180
181
    /**
182
     * @return Project
183
     */
184 8
    public function getProject(): Project
185
    {
186 8
        return $this->project;
187
    }
188
189
    /**
190
     * @return User
191
     */
192 2
    public function getAuthor(): User
193
    {
194 2
        return $this->author;
195
    }
196
197
    /**
198
     * @return User|null
199
     */
200
    public function getAssignee(): ?User
201
    {
202
        return $this->assignee;
203
    }
204
205
    /**
206
     * @return bool
207
     */
208
    public function isWorkInProgress(): bool
209
    {
210
        return $this->isWorkInProgress;
211
    }
212
}
213