SimpleRepoFacade::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 2
Metric Value
c 2
b 0
f 2
dl 0
loc 21
rs 9.3142
cc 1
eloc 19
nc 1
nop 9

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
3
namespace DevBoardLib\GithubObjectApiFacade\Repo;
4
5
use DevBoardLib\GithubApiFacade\Repo\RepoFacade;
6
use DevBoardLib\GithubObjectApiFacade\Repo\Branch\Converter\GithubBranchConverter;
7
use DevBoardLib\GithubObjectApiFacade\Repo\Commit\Converter\GithubCommitConverter;
8
use DevBoardLib\GithubObjectApiFacade\Repo\CommitStatus\Converter\GithubCommitStatusConverter;
9
use DevBoardLib\GithubObjectApiFacade\Repo\Issue\Converter\GithubIssueConverter;
10
use DevBoardLib\GithubObjectApiFacade\Repo\Milestone\Converter\GithubMilestoneConverter;
11
use DevBoardLib\GithubObjectApiFacade\Repo\PullRequest\Converter\GithubPullRequestConverter;
12
use DevBoardLib\GithubObjectApiFacade\Repo\Repo\Converter\GithubRepoConverter;
13
use DevBoardLib\GithubObjectApiFacade\Repo\Tag\Converter\GithubTagConverter;
14
15
/**
16
 * Class SimpleRepoFacade.
17
 */
18
class SimpleRepoFacade implements ObjectRepoFacade
19
{
20
    /**
21
     * @var RepoFacade
22
     */
23
    private $repoFacade;
24
25
    /**
26
     * @var GithubRepoConverter
27
     */
28
    private $githubRepoConverter;
29
    /**
30
     * @var GithubBranchConverter
31
     */
32
    private $githubBranchConverter;
33
    /**
34
     * @var GithubTagConverter
35
     */
36
    private $githubTagConverter;
37
    /**
38
     * @var GithubPullRequestConverter
39
     */
40
    private $githubPullRequestConverter;
41
    /**
42
     * @var GithubCommitConverter
43
     */
44
    private $githubCommitConverter;
45
    /**
46
     * @var GithubCommitStatusConverter
47
     */
48
    private $githubCommitStatusConverter;
49
50
    /**
51
     * @var GithubIssueConverter
52
     */
53
    private $githubIssueConverter;
54
    /**
55
     * @var GithubMilestoneConverter
56
     */
57
    private $githubMilestoneConverter;
58
59
    /**
60
     * SimpleRepoFacade constructor.
61
     *
62
     * @param $repoFacade
63
     * @param $githubRepoConverter
64
     * @param $githubBranchConverter
65
     * @param $githubTagConverter
66
     * @param $githubPullRequestConverter
67
     * @param $githubCommitConverter
68
     * @param $githubCommitStatusConverter
69
     * @param $githubIssueConverter
70
     * @param $githubMilestoneConverter
71
     */
72
    public function __construct(
73
        RepoFacade $repoFacade,
74
        GithubRepoConverter $githubRepoConverter,
75
        GithubBranchConverter $githubBranchConverter,
76
        GithubTagConverter $githubTagConverter,
77
        GithubPullRequestConverter $githubPullRequestConverter,
78
        GithubCommitConverter $githubCommitConverter,
79
        GithubCommitStatusConverter $githubCommitStatusConverter,
80
        GithubIssueConverter $githubIssueConverter,
81
        GithubMilestoneConverter $githubMilestoneConverter
82
    ) {
83
        $this->repoFacade                  = $repoFacade;
84
        $this->githubRepoConverter         = $githubRepoConverter;
85
        $this->githubBranchConverter       = $githubBranchConverter;
86
        $this->githubTagConverter          = $githubTagConverter;
87
        $this->githubPullRequestConverter  = $githubPullRequestConverter;
88
        $this->githubCommitConverter       = $githubCommitConverter;
89
        $this->githubCommitStatusConverter = $githubCommitStatusConverter;
90
        $this->githubIssueConverter        = $githubIssueConverter;
91
        $this->githubMilestoneConverter    = $githubMilestoneConverter;
92
    }
93
94
    /**
95
     * Fetches GithubRepo details.
96
     *
97
     * @return array
98
     */
99
    public function fetchDetails()
100
    {
101
        $rawResult = $this->repoFacade->fetchDetails();
102
103
        return $this->githubRepoConverter->convert($rawResult);
104
    }
105
106
    /**
107
     * Fetches GithubBranch details.
108
     *
109
     * @param $branchName
110
     *
111
     * @return array
112
     */
113
    public function fetchBranch($branchName)
114
    {
115
        $rawResult = $this->repoFacade->fetchBranch($branchName);
116
117
        return $this->githubBranchConverter->convert($rawResult);
118
    }
119
120
    /**
121
     * @return array
122
     */
123
    public function fetchAllBranches()
124
    {
125
        $results    = [];
126
        $rawResults = $this->repoFacade->fetchAllBranches();
127
128
        foreach ($rawResults as $rawResult) {
129
            $results[] = $this->githubBranchConverter->convert($rawResult);
130
        }
131
132
        return $results;
133
    }
134
135
    /**
136
     * @return array
137
     */
138
    public function fetchAllTags()
139
    {
140
        $results    = [];
141
        $rawResults = $this->repoFacade->fetchAllTags();
142
143
        foreach ($rawResults as $rawResult) {
144
            $results[] = $this->githubTagConverter->convert($rawResult);
145
        }
146
147
        return $results;
148
    }
149
150
    /**
151
     * Fetches GithubCommit details.
152
     *
153
     * @param $commitSha
154
     *
155
     * @return array
156
     */
157
    public function fetchCommit($commitSha)
158
    {
159
        $rawResult = $this->repoFacade->fetchCommit($commitSha);
160
161
        return $this->githubCommitConverter->convert($rawResult);
162
    }
163
164
    /**
165
     * Fetches GithubCommit status.
166
     *
167
     * @param $commitSha
168
     *
169
     * @return array
170
     */
171
    public function fetchCommitStatus($commitSha)
172
    {
173
        $results    = [];
174
        $rawResults = $this->repoFacade->fetchCommitStatus($commitSha);
175
176
        foreach ($rawResults['statuses'] as $rawResult) {
177
            $rawResult['sha'] = $commitSha;
178
            $results[]        = $this->githubCommitStatusConverter->convert($rawResult);
179
        }
180
181
        return $results;
182
    }
183
184
    /**
185
     * Fetches list of GithubCommit statuses.
186
     *
187
     * @param $commitSha
188
     *
189
     * @return array
190
     */
191
    public function fetchCommitStatuses($commitSha)
192
    {
193
        $results    = [];
194
        $rawResults = $this->repoFacade->fetchCommitStatuses($commitSha);
195
196
        foreach ($rawResults as $rawResult) {
197
            $rawResult['sha'] = $commitSha;
198
            $results[]        = $this->githubCommitStatusConverter->convert($rawResult);
199
        }
200
201
        return $results;
202
    }
203
204
    /**
205
     * @return array
206
     */
207
    public function fetchAllPullRequests()
208
    {
209
        $results    = [];
210
        $rawResults = $this->repoFacade->fetchAllPullRequests();
211
212
        foreach ($rawResults as $rawResult) {
213
            $results[] = $this->githubPullRequestConverter->convert($rawResult);
214
        }
215
216
        return $results;
217
    }
218
219
    /**
220
     * @return array
221
     */
222
    public function fetchAllMilestones()
223
    {
224
        $results    = [];
225
        $rawResults = $this->repoFacade->fetchAllMilestones();
226
227
        foreach ($rawResults as $rawResult) {
228
            $results[] = $this->githubMilestoneConverter->convert($rawResult);
229
        }
230
231
        return $results;
232
    }
233
234
    /**
235
     * @return array
236
     */
237
    public function fetchAllIssues()
238
    {
239
        $results    = [];
240
        $rawResults = $this->repoFacade->fetchAllIssues();
241
242
        foreach ($rawResults as $rawResult) {
243
            $results[] = $this->githubIssueConverter->convert($rawResult);
244
        }
245
246
        return $results;
247
    }
248
}
249