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