Completed
Pull Request — master (#20)
by Miro
02:16
created

GithubPullRequestSource::__construct()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 33
Code Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
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 GithubCommitId */
37
    private $lastCommitId;
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 GithubCommitId         $lastCommitId
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
        GithubCommitId $lastCommitId,
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->lastCommitId    = $lastCommitId;
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->lastCommitId;
164
    }
165
166
    /** @return GithubUserId */
167
    public function getCreatedByUserId()
168
    {
169
        return $this->createdByUser->getGithubUserId();
170
    }
171
172
    /** @return GithubUser */
173
    public function getCreatedByUser()
174
    {
175
        return $this->createdByUser;
176
    }
177
178
    /** @return GithubUserId */
179
    public function getAssignedToUserId()
180
    {
181
        if (null !== $this->assignedToUser) {
182
            return $this->assignedToUser->getGithubUserId();
183
        }
184
185
        return null;
186
    }
187
188
    /** @return GithubUser */
189
    public function getAssignedToUser()
190
    {
191
        return $this->assignedToUser;
192
    }
193
194
    /** @return GithubMilestoneId */
195
    public function getMilestoneId()
196
    {
197
        if (null !== $this->milestone) {
198
            return $this->milestone->getId();
199
        }
200
201
        return null;
202
    }
203
204
    /** @return GithubMilestone */
205
    public function getMilestone()
206
    {
207
        return $this->milestone;
208
    }
209
210
    /** @return DateTime */
211
    public function getGithubCreatedAt()
212
    {
213
        return $this->githubCreatedAt;
214
    }
215
216
    /** @return DateTime */
217
    public function getGithubUpdatedAt()
218
    {
219
        return $this->githubUpdatedAt;
220
    }
221
222
    /** @return DateTime */
223
    public function getGithubClosedAt()
224
    {
225
        return $this->githubClosedAt;
226
    }
227
}
228