Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
11 | class PaginatedKnpLabsRepoFacade implements RepoFacade |
||
12 | { |
||
13 | private $client; |
||
14 | private $githubRepo; |
||
15 | |||
16 | private $paginator; |
||
17 | |||
18 | /** |
||
19 | * PaginatedKnpLabsRepoFacade constructor. |
||
20 | * |
||
21 | * @param $client |
||
22 | * @param $githubRepo |
||
23 | */ |
||
24 | public function __construct(Client $client, GithubRepo $githubRepo) |
||
31 | |||
32 | /** |
||
33 | * Fetches GithubRepo details. |
||
34 | * |
||
35 | * @return array |
||
36 | */ |
||
37 | public function fetchDetails() |
||
45 | |||
46 | /** |
||
47 | * Fetches GithubBranch details. |
||
48 | * |
||
49 | * @param $branchName |
||
50 | * |
||
51 | * @return array |
||
52 | */ |
||
53 | public function fetchBranch($branchName) |
||
62 | |||
63 | /** |
||
64 | * @return array |
||
65 | */ |
||
66 | public function fetchAllBranches() |
||
76 | |||
77 | /** |
||
78 | * @return array |
||
79 | */ |
||
80 | View Code Duplication | public function fetchAllBranchNames() |
|
89 | |||
90 | /** |
||
91 | * @return array |
||
92 | */ |
||
93 | public function fetchAllTags() |
||
104 | |||
105 | /** |
||
106 | * @return array |
||
107 | */ |
||
108 | View Code Duplication | public function fetchAllTagNames() |
|
117 | |||
118 | /** |
||
119 | * Fetches GithubCommit details. |
||
120 | * |
||
121 | * @param $commitSha |
||
122 | * |
||
123 | * @return array |
||
124 | */ |
||
125 | public function fetchCommit($commitSha) |
||
134 | |||
135 | /** |
||
136 | * Fetches GithubCommit status. |
||
137 | * |
||
138 | * @param $commitSha |
||
139 | * |
||
140 | * @return array |
||
141 | */ |
||
142 | public function fetchCommitStatus($commitSha) |
||
151 | |||
152 | /** |
||
153 | * Fetches list of GithubCommit statuses. |
||
154 | * |
||
155 | * @param $commitSha |
||
156 | * |
||
157 | * @return array |
||
158 | */ |
||
159 | public function fetchCommitStatuses($commitSha) |
||
168 | |||
169 | /** |
||
170 | * @return array |
||
171 | */ |
||
172 | View Code Duplication | public function fetchAllPullRequests() |
|
182 | |||
183 | /** |
||
184 | * @return array |
||
185 | */ |
||
186 | View Code Duplication | public function fetchAllMilestones() |
|
196 | |||
197 | /** |
||
198 | * Returns all issues. |
||
199 | * |
||
200 | * IMPORTANT: |
||
201 | * - GitHub API v3 returns both issues and pullRequests together so filtering needs to be done |
||
202 | * - Pull requests have 'pull_request' key. |
||
203 | * |
||
204 | * @return array |
||
205 | */ |
||
206 | public function fetchAllIssues() |
||
218 | |||
219 | /** |
||
220 | * @return array |
||
221 | */ |
||
222 | View Code Duplication | public function fetchAllIssuesAndPullRequests() |
|
232 | |||
233 | /** |
||
234 | * @return \Github\Api\ApiInterface |
||
235 | */ |
||
236 | private function getRepoApi() |
||
240 | |||
241 | /** |
||
242 | * @return \Github\Api\ApiInterface |
||
243 | */ |
||
244 | private function getIssueApi() |
||
248 | |||
249 | /** |
||
250 | * @return \Github\Api\Issue\Milestones |
||
251 | */ |
||
252 | private function getMilestonesApi() |
||
256 | |||
257 | /** |
||
258 | * @return \Github\Api\PullRequest |
||
259 | */ |
||
260 | private function getPullRequestApi() |
||
264 | } |
||
265 |
This check looks for function calls that miss required arguments.