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

GithubCommitSource::__construct()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
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 GithubUser      $author
55
     * @param DateTime        $authorDate
56
     * @param GithubUser      $committer
57
     * @param DateTime        $committerDate
58
     * @param string          $message
59
     * @param string          $githubCommitState
60
     */
61
    public function __construct(
62
        GithubCommitId $id,
63
        GithubRepo $repo,
64
        GithubCommitSha $sha,
65
        $authorName,
66
        $authorEmail,
67
        GithubUser $author = null,
68
        DateTime $authorDate,
69
        GithubUser $committer,
70
        DateTime $committerDate,
71
        $message,
72
        $githubCommitState = null
73
    ) {
74
        $this->id                = $id;
75
        $this->repo              = $repo;
76
        $this->sha               = $sha;
77
        $this->authorName        = $authorName;
78
        $this->authorEmail       = $authorEmail;
79
        $this->author            = $author;
80
        $this->authorDate        = $authorDate;
81
        $this->committer         = $committer;
82
        $this->committerDate     = $committerDate;
83
        $this->message           = $message;
84
        $this->githubCommitState = $githubCommitState;
85
    }
86
87
    /** @return GithubCommitId */
88
    public function getId()
89
    {
90
        return $this->id;
91
    }
92
93
    /** @return GithubRepoId */
94
    public function getRepoId()
95
    {
96
        return $this->repo->getId();
97
    }
98
99
    /** @return GithubRepo */
100
    public function getRepo()
101
    {
102
        return $this->repo;
103
    }
104
105
    /** @return GithubCommitSha */
106
    public function getSha()
107
    {
108
        return $this->sha;
109
    }
110
111
    /**
112
     * @return string
113
     */
114
    public function getAuthorName()
115
    {
116
        return $this->authorName;
117
    }
118
119
    /**
120
     * @return string
121
     */
122
    public function getAuthorEmail()
123
    {
124
        return $this->authorEmail;
125
    }
126
127
    /** @return GithubUserId */
128
    public function getAuthorId()
129
    {
130
        return $this->author->getGithubUserId();
131
    }
132
133
    /** @return GithubUser */
134
    public function getAuthor()
135
    {
136
        return $this->author;
137
    }
138
139
    /** @return DateTime */
140
    public function getAuthorDate()
141
    {
142
        return $this->authorDate;
143
    }
144
145
    /** @return GithubUserId */
146
    public function getCommitterId()
147
    {
148
        return $this->committer->getGithubUserId();
149
    }
150
151
    /** @return GithubUser */
152
    public function getCommitter()
153
    {
154
        return $this->committer;
155
    }
156
157
    /** @return DateTime */
158
    public function getCommitterDate()
159
    {
160
        return $this->committerDate;
161
    }
162
163
    /** @return string */
164
    public function getMessage()
165
    {
166
        return $this->message;
167
    }
168
169
    /** @return string */
170
    public function getGithubCommitState()
171
    {
172
        return $this->githubCommitState;
173
    }
174
}
175