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 | View Code Duplication | public function fetchAllTagNames() |
|
102 | |||
103 | /** |
||
104 | * Fetches GithubCommit details. |
||
105 | * |
||
106 | * @param $commitSha |
||
107 | * |
||
108 | * @return array |
||
109 | */ |
||
110 | public function fetchCommit($commitSha) |
||
119 | |||
120 | /** |
||
121 | * Fetches GithubCommit status. |
||
122 | * |
||
123 | * @param $commitSha |
||
124 | * |
||
125 | * @return array |
||
126 | */ |
||
127 | public function fetchCommitStatus($commitSha) |
||
136 | |||
137 | /** |
||
138 | * Fetches list of GithubCommit statuses. |
||
139 | * |
||
140 | * @param $commitSha |
||
141 | * |
||
142 | * @return array |
||
143 | */ |
||
144 | public function fetchCommitStatuses($commitSha) |
||
153 | |||
154 | /** |
||
155 | * @return array |
||
156 | */ |
||
157 | View Code Duplication | public function fetchAllPullRequests() |
|
167 | |||
168 | /** |
||
169 | * @return array |
||
170 | */ |
||
171 | View Code Duplication | public function fetchAllMilestones() |
|
181 | |||
182 | /** |
||
183 | * Returns all issues. |
||
184 | * |
||
185 | * IMPORTANT: |
||
186 | * - GitHub API v3 returns both issues and pullRequests together so filtering needs to be done |
||
187 | * - Pull requests have 'pull_request' key. |
||
188 | * |
||
189 | * @return array |
||
190 | */ |
||
191 | public function fetchAllIssues() |
||
203 | |||
204 | /** |
||
205 | * @return array |
||
206 | */ |
||
207 | View Code Duplication | public function fetchAllIssuesAndPullRequests() |
|
217 | |||
218 | /** |
||
219 | * @return \Github\Api\ApiInterface |
||
220 | */ |
||
221 | private function getRepoApi() |
||
225 | |||
226 | /** |
||
227 | * @return \Github\Api\ApiInterface |
||
228 | */ |
||
229 | private function getIssueApi() |
||
233 | |||
234 | /** |
||
235 | * @return \Github\Api\Issue\Milestones |
||
236 | */ |
||
237 | private function getMilestonesApi() |
||
241 | |||
242 | /** |
||
243 | * @return \Github\Api\PullRequest |
||
244 | */ |
||
245 | private function getPullRequestApi() |
||
249 | } |
||
250 |
This check looks for function calls that miss required arguments.