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 |
||
| 12 | class PaginatedKnpLabsRepoFacade implements RepoFacade |
||
| 13 | { |
||
| 14 | private $client; |
||
| 15 | private $githubRepo; |
||
| 16 | |||
| 17 | private $paginator; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * PaginatedKnpLabsRepoFacade constructor. |
||
| 21 | * |
||
| 22 | * @param $client |
||
| 23 | * @param $githubRepo |
||
| 24 | */ |
||
| 25 | public function __construct(Client $client, GithubRepo $githubRepo) |
||
| 32 | |||
| 33 | /** |
||
| 34 | * Fetches GithubRepo details. |
||
| 35 | * |
||
| 36 | * @return array |
||
| 37 | */ |
||
| 38 | public function fetchDetails() |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Fetches GithubBranch details. |
||
| 49 | * |
||
| 50 | * @param $branchName |
||
| 51 | * |
||
| 52 | * @return array |
||
| 53 | */ |
||
| 54 | public function fetchBranch($branchName) |
||
| 63 | |||
| 64 | /** @return array */ |
||
| 65 | public function fetchAllBranches() |
||
| 75 | |||
| 76 | /** @return array */ |
||
| 77 | View Code Duplication | public function fetchAllBranchNames() |
|
| 86 | |||
| 87 | /** @return array */ |
||
| 88 | public function fetchAllTags() |
||
| 99 | |||
| 100 | /** @return array */ |
||
| 101 | View Code Duplication | public function fetchAllTagNames() |
|
| 110 | |||
| 111 | /** |
||
| 112 | * Fetches GithubCommit details. |
||
| 113 | * |
||
| 114 | * @param $commitSha |
||
| 115 | * |
||
| 116 | * @return array |
||
| 117 | */ |
||
| 118 | public function fetchCommit($commitSha) |
||
| 127 | |||
| 128 | /** |
||
| 129 | * Fetches GithubCommit status. |
||
| 130 | * |
||
| 131 | * @param $commitSha |
||
| 132 | * |
||
| 133 | * @return array |
||
| 134 | */ |
||
| 135 | public function fetchCommitStatus($commitSha) |
||
| 144 | |||
| 145 | /** |
||
| 146 | * Fetches list of GithubCommit statuses. |
||
| 147 | * |
||
| 148 | * @param $commitSha |
||
| 149 | * |
||
| 150 | * @return array |
||
| 151 | */ |
||
| 152 | public function fetchCommitStatuses($commitSha) |
||
| 161 | |||
| 162 | /** @return array */ |
||
| 163 | View Code Duplication | public function fetchAllPullRequests() |
|
| 173 | |||
| 174 | /** @return array */ |
||
| 175 | View Code Duplication | public function fetchAllMilestones() |
|
| 185 | |||
| 186 | /** |
||
| 187 | * Returns all issues. |
||
| 188 | * |
||
| 189 | * IMPORTANT: |
||
| 190 | * - GitHub API v3 returns both issues and pullRequests together so filtering needs to be done |
||
| 191 | * - Pull requests have 'pull_request' key. |
||
| 192 | * |
||
| 193 | * @return array |
||
| 194 | */ |
||
| 195 | public function fetchAllIssues() |
||
| 207 | |||
| 208 | /** @return array */ |
||
| 209 | View Code Duplication | public function fetchAllIssuesAndPullRequests() |
|
| 219 | |||
| 220 | /** |
||
| 221 | * @return \Github\Api\ApiInterface |
||
| 222 | */ |
||
| 223 | private function getRepoApi() |
||
| 227 | |||
| 228 | /** |
||
| 229 | * @return \Github\Api\ApiInterface |
||
| 230 | */ |
||
| 231 | private function getIssueApi() |
||
| 235 | |||
| 236 | /** |
||
| 237 | * @return \Github\Api\Issue\Milestones |
||
| 238 | */ |
||
| 239 | private function getMilestonesApi() |
||
| 243 | |||
| 244 | /** |
||
| 245 | * @return \Github\Api\PullRequest |
||
| 246 | */ |
||
| 247 | private function getPullRequestApi() |
||
| 251 | } |
||
| 252 |
This check looks for function calls that miss required arguments.