Test Failed
Push — master ( 5a7453...e9bda3 )
by Daniel
04:29
created

MergeRequest::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 1
eloc 9
c 3
b 0
f 0
nc 1
nop 9
dl 0
loc 20
ccs 0
cts 10
cp 0
crap 2
rs 9.9666

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 $webUrl;
26
27
    /** @var bool */
28
    private $isWorkInProgress;
29
30
    /** @var Project */
31
    private $project;
32
33
    /** @var User */
34
    private $author;
35
36
    /** @var User */
37
    private $assignee;
38
39
    /**
40
     * Project constructor.
41
     * @param int $id
42
     * @param int $iid
43
     * @param string $title
44
     * @param string $description
45
     * @param string $webUrl
46
     * @param bool $isWorkInProgress
47
     * @param Project $project
48
     * @param User $author
49
     * @param User $assignee
50
     *
51
     * @SuppressWarnings(PHPMD.ExcessiveParameterList)
52
     */
53
    public function __construct(
54
        int $id,
55
        int $iid,
56
        string $title,
57
        string $description,
58
        string $webUrl,
59
        bool $isWorkInProgress,
60
        Project $project,
61
        User $author,
62
        ?User $assignee = null
63
    ) {
64
        $this->id = $id;
65
        $this->iid = $iid;
66
        $this->title = $title;
67
        $this->description = $description;
68
        $this->webUrl = $webUrl;
69
        $this->isWorkInProgress = $isWorkInProgress;
70
        $this->project = $project;
71
        $this->author = $author;
72
        $this->assignee = $assignee;
73
    }
74
75
    /**
76
     * @param array $mergeRequest
77
     * @return MergeRequest
78
     */
79
    public static function fromArray(array $mergeRequest): self
80
    {
81
        return new self(
82
            (int)$mergeRequest['id'],
83
            (int)$mergeRequest['iid'],
84
            (string)$mergeRequest['title'],
85
            (string)$mergeRequest['description'],
86
            (string)$mergeRequest['web_url'],
87
            (bool)$mergeRequest['work_in_progress'],
88
            $mergeRequest['project'],
89
            $mergeRequest['author'],
90
            $mergeRequest['assignee']
91
        );
92
    }
93
94
    /**
95
     * @return int
96
     */
97
    public function getIid(): int
98
    {
99
        return $this->iid;
100
    }
101
102
    /**
103
     * @return int
104
     */
105
    public function getId(): int
106
    {
107
        return $this->id;
108
    }
109
110
    /**
111
     * @return string
112
     */
113
    public function getTitle(): string
114
    {
115
        return $this->title;
116
    }
117
118
    /**
119
     * @return string
120
     */
121
    public function getDescription(): string
122
    {
123
        return $this->description;
124
    }
125
126
    /**
127
     * @return string
128
     */
129
    public function getWebUrl(): string
130
    {
131
        return $this->webUrl;
132
    }
133
134
    /**
135
     * @return Project
136
     */
137
    public function getProject(): Project
138
    {
139
        return $this->project;
140
    }
141
142
    /**
143
     * @return User
144
     */
145
    public function getAuthor(): User
146
    {
147
        return $this->author;
148
    }
149
150
    /**
151
     * @return User|null
152
     */
153
    public function getAssignee(): ?User
154
    {
155
        return $this->assignee;
156
    }
157
158
    /**
159
     * @return bool
160
     */
161
    public function isWorkInProgress(): bool
162
    {
163
        return $this->isWorkInProgress;
164
    }
165
}
166