Completed
Push — master ( 5da4b2...7163c3 )
by Miro
04:03 queued 01:19
created

GithubPullRequestSource::__construct()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 33
Code Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 33
rs 8.8571
cc 1
eloc 31
nc 1
nop 15

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
namespace DevBoardLib\GithubCore\PullRequest;
3
4
use DateTime;
5
use DevBoardLib\GithubCore\Commit\GithubCommitId;
6
use DevBoardLib\GithubCore\Milestone\GithubMilestone;
7
use DevBoardLib\GithubCore\Milestone\GithubMilestoneId;
8
use DevBoardLib\GithubCore\PullRequest\State\GithubPullRequestState;
9
use DevBoardLib\GithubCore\Repo\GithubRepo;
10
use DevBoardLib\GithubCore\Repo\GithubRepoId;
11
use DevBoardLib\GithubCore\User\GithubUser;
12
use DevBoardLib\GithubCore\User\GithubUserId;
13
14
/**
15
 * Class GithubPullRequestSource.
16
 */
17
class GithubPullRequestSource implements GithubPullRequest
18
{
19
    /** @var GithubPullRequestId */
20
    protected $id;
21
    /** @var GithubRepo */
22
    protected $repo;
23
    /** @var int */
24
    private $number;
25
    /** @var GithubPullRequestState */
26
    private $state;
27
    /** @var bool */
28
    private $locked;
29
    /** @var bool */
30
    private $merged;
31
    /** @var string */
32
    private $title;
33
    /** @var string */
34
    private $body;
35
    /** @var GithubCommitId */
36
    private $lastCommitId;
37
    /** @var GithubUser */
38
    private $createdByUser;
39
    /** @var GithubUser */
40
    private $assignedToUser;
41
    /** @var GithubMilestone */
42
    private $milestone;
43
    /** @var \DateTime */
44
    private $githubCreatedAt;
45
    /** @var \DateTime */
46
    private $githubUpdatedAt;
47
    /** @var \DateTime */
48
    private $githubClosedAt;
49
50
    /**
51
     * GithubPullRequestSource constructor.
52
     *
53
     * @param GithubPullRequestId    $id
54
     * @param GithubRepo             $repo
55
     * @param int                    $number
56
     * @param GithubPullRequestState $state
57
     * @param                        $locked
58
     * @param                        $merged
59
     * @param string                 $title
60
     * @param string                 $body
61
     * @param GithubCommitId         $lastCommitId
62
     * @param GithubUser             $createdByUser
63
     * @param GithubUser             $assignedToUser
64
     * @param GithubMilestone        $milestone
65
     * @param DateTime               $githubCreatedAt
66
     * @param DateTime               $githubUpdatedAt
67
     * @param DateTime               $githubClosedAt
68
     *
69
     * @SuppressWarnings(PHPMD.ExcessiveParameterList)
70
     */
71
    public function __construct(
72
        GithubPullRequestId $id,
73
        GithubRepo $repo,
74
        $number,
75
        GithubPullRequestState $state,
76
        $locked,
77
        $merged,
78
        $title,
79
        $body,
80
        GithubCommitId $lastCommitId,
81
        GithubUser $createdByUser,
82
        GithubUser $assignedToUser = null,
83
        GithubMilestone $milestone = null,
84
        DateTime $githubCreatedAt,
85
        DateTime $githubUpdatedAt,
86
        DateTime $githubClosedAt = null
87
    ) {
88
        $this->id              = $id;
89
        $this->repo            = $repo;
90
        $this->number          = $number;
91
        $this->state           = $state;
92
        $this->locked          = $locked;
93
        $this->merged          = $merged;
94
        $this->title           = $title;
95
        $this->body            = $body;
96
        $this->lastCommitId    = $lastCommitId;
97
        $this->createdByUser   = $createdByUser;
98
        $this->assignedToUser  = $assignedToUser;
99
        $this->milestone       = $milestone;
100
        $this->githubCreatedAt = $githubCreatedAt;
101
        $this->githubUpdatedAt = $githubUpdatedAt;
102
        $this->githubClosedAt  = $githubClosedAt;
103
    }
104
105
    /** @return GithubPullRequestId */
106
    public function getId()
107
    {
108
        return $this->id;
109
    }
110
111
    /** @return GithubRepoId */
112
    public function getRepoId()
113
    {
114
        return $this->repo->getId();
115
    }
116
117
    /** @return GithubRepo */
118
    public function getRepo()
119
    {
120
        return $this->repo;
121
    }
122
123
    /** @return int */
124
    public function getNumber()
125
    {
126
        return $this->number;
127
    }
128
129
    /** @return GithubPullRequestState */
130
    public function getState()
131
    {
132
        return $this->state;
133
    }
134
135
    /** @return bool */
136
    public function isLocked()
137
    {
138
        return $this->locked;
139
    }
140
141
    /** @return bool */
142
    public function isMerged()
143
    {
144
        return $this->merged;
145
    }
146
147
    /** @return string */
148
    public function getTitle()
149
    {
150
        return $this->title;
151
    }
152
153
    /** @return string */
154
    public function getBody()
155
    {
156
        return $this->body;
157
    }
158
159
    /** @return GithubCommitId */
160
    public function getLastCommitId()
161
    {
162
        return $this->lastCommitId;
163
    }
164
165
    /** @return GithubUserId */
166
    public function getCreatedByUserId()
167
    {
168
        return $this->createdByUser->getGithubUserId();
169
    }
170
171
    /** @return GithubUser */
172
    public function getCreatedByUser()
173
    {
174
        return $this->createdByUser;
175
    }
176
177
    /** @return GithubUserId */
178
    public function getAssignedToUserId()
179
    {
180
        if (null !== $this->assignedToUser) {
181
            return $this->assignedToUser->getGithubUserId();
182
        }
183
184
        return null;
185
    }
186
187
    /** @return GithubUser */
188
    public function getAssignedToUser()
189
    {
190
        return $this->assignedToUser;
191
    }
192
193
    /** @return GithubMilestoneId */
194
    public function getMilestoneId()
195
    {
196
        if (null !== $this->milestone) {
197
            return $this->milestone->getId();
198
        }
199
200
        return null;
201
    }
202
203
    /** @return GithubMilestone */
204
    public function getMilestone()
205
    {
206
        return $this->milestone;
207
    }
208
209
    /** @return DateTime */
210
    public function getGithubCreatedAt()
211
    {
212
        return $this->githubCreatedAt;
213
    }
214
215
    /** @return DateTime */
216
    public function getGithubUpdatedAt()
217
    {
218
        return $this->githubUpdatedAt;
219
    }
220
221
    /** @return DateTime */
222
    public function getGithubClosedAt()
223
    {
224
        return $this->githubClosedAt;
225
    }
226
}
227