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

GithubCommitSource::__construct()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 25
rs 8.8571
cc 1
eloc 23
nc 1
nop 11

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\Commit;
3
4
use DateTime;
5
use DevBoardLib\GithubCore\Repo\GithubRepo;
6
use DevBoardLib\GithubCore\Repo\GithubRepoId;
7
use DevBoardLib\GithubCore\User\GithubUser;
8
use DevBoardLib\GithubCore\User\GithubUserId;
9
10
/**
11
 * Class GithubCommitSource.
12
 */
13
class GithubCommitSource implements GithubCommit
14
{
15
    /** @var GithubCommitId */
16
    protected $id;
17
18
    /** @var GithubRepo */
19
    protected $repo;
20
21
    /** @var GithubCommitSha */
22
    private $sha;
23
24
    /** @var string */
25
    private $authorName;
26
27
    /** @var string */
28
    private $authorEmail;
29
30
    /** @var GithubUser */
31
    private $author;
32
33
    /** @var DateTime */
34
    private $authorDate;
35
36
    /** @var GithubUser */
37
    private $committer;
38
39
    /** @var DateTime */
40
    private $committerDate;
41
42
    /** @var string */
43
    private $message;
44
45
    /** @var string */
46
    private $githubCommitState;
47
48
    /**
49
     * GithubCommitSource constructor.
50
     *
51
     * @param GithubCommitId  $id
52
     * @param GithubRepo      $repo
53
     * @param GithubCommitSha $sha
54
     * @param                 $authorName
55
     * @param                 $authorEmail
56
     * @param GithubUser      $author
57
     * @param DateTime        $authorDate
58
     * @param GithubUser      $committer
59
     * @param DateTime        $committerDate
60
     * @param string          $message
61
     * @param string          $githubCommitState
62
     *
63
     * @SuppressWarnings(PHPMD.ExcessiveParameterList)
64
     */
65
    public function __construct(
66
        GithubCommitId $id,
67
        GithubRepo $repo,
68
        GithubCommitSha $sha,
69
        $authorName,
70
        $authorEmail,
71
        GithubUser $author = null,
72
        DateTime $authorDate,
73
        GithubUser $committer,
74
        DateTime $committerDate,
75
        $message,
76
        $githubCommitState = null
77
    ) {
78
        $this->id                = $id;
79
        $this->repo              = $repo;
80
        $this->sha               = $sha;
81
        $this->authorName        = $authorName;
82
        $this->authorEmail       = $authorEmail;
83
        $this->author            = $author;
84
        $this->authorDate        = $authorDate;
85
        $this->committer         = $committer;
86
        $this->committerDate     = $committerDate;
87
        $this->message           = $message;
88
        $this->githubCommitState = $githubCommitState;
89
    }
90
91
    /** @return GithubCommitId */
92
    public function getId()
93
    {
94
        return $this->id;
95
    }
96
97
    /** @return GithubRepoId */
98
    public function getRepoId()
99
    {
100
        return $this->repo->getId();
101
    }
102
103
    /** @return GithubRepo */
104
    public function getRepo()
105
    {
106
        return $this->repo;
107
    }
108
109
    /** @return GithubCommitSha */
110
    public function getSha()
111
    {
112
        return $this->sha;
113
    }
114
115
    /**
116
     * @return string
117
     */
118
    public function getAuthorName()
119
    {
120
        return $this->authorName;
121
    }
122
123
    /**
124
     * @return string
125
     */
126
    public function getAuthorEmail()
127
    {
128
        return $this->authorEmail;
129
    }
130
131
    /** @return GithubUserId */
132
    public function getAuthorId()
133
    {
134
        return $this->author->getGithubUserId();
135
    }
136
137
    /** @return GithubUser */
138
    public function getAuthor()
139
    {
140
        return $this->author;
141
    }
142
143
    /** @return DateTime */
144
    public function getAuthorDate()
145
    {
146
        return $this->authorDate;
147
    }
148
149
    /** @return GithubUserId */
150
    public function getCommitterId()
151
    {
152
        return $this->committer->getGithubUserId();
153
    }
154
155
    /** @return GithubUser */
156
    public function getCommitter()
157
    {
158
        return $this->committer;
159
    }
160
161
    /** @return DateTime */
162
    public function getCommitterDate()
163
    {
164
        return $this->committerDate;
165
    }
166
167
    /** @return string */
168
    public function getMessage()
169
    {
170
        return $this->message;
171
    }
172
173
    /** @return string */
174
    public function getGithubCommitState()
175
    {
176
        return $this->githubCommitState;
177
    }
178
}
179