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 | /** @return array */ |
||
| 64 | public function fetchAllBranches() |
||
| 74 | |||
| 75 | /** @return array */ |
||
| 76 | View Code Duplication | public function fetchAllBranchNames() |
|
| 85 | |||
| 86 | /** @return array */ |
||
| 87 | public function fetchAllTags() |
||
| 98 | |||
| 99 | /** @return array */ |
||
| 100 | View Code Duplication | public function fetchAllTagNames() |
|
| 109 | |||
| 110 | /** |
||
| 111 | * Fetches GithubCommit details. |
||
| 112 | * |
||
| 113 | * @param $commitSha |
||
| 114 | * |
||
| 115 | * @return array |
||
| 116 | */ |
||
| 117 | public function fetchCommit($commitSha) |
||
| 126 | |||
| 127 | /** |
||
| 128 | * Fetches GithubCommit status. |
||
| 129 | * |
||
| 130 | * @param $commitSha |
||
| 131 | * |
||
| 132 | * @return array |
||
| 133 | */ |
||
| 134 | public function fetchCommitStatus($commitSha) |
||
| 143 | |||
| 144 | /** |
||
| 145 | * Fetches list of GithubCommit statuses. |
||
| 146 | * |
||
| 147 | * @param $commitSha |
||
| 148 | * |
||
| 149 | * @return array |
||
| 150 | */ |
||
| 151 | public function fetchCommitStatuses($commitSha) |
||
| 160 | |||
| 161 | /** @return array */ |
||
| 162 | View Code Duplication | public function fetchAllPullRequests() |
|
| 172 | |||
| 173 | /** @return array */ |
||
| 174 | View Code Duplication | public function fetchAllMilestones() |
|
| 184 | |||
| 185 | /** |
||
| 186 | * Returns all issues. |
||
| 187 | * |
||
| 188 | * IMPORTANT: |
||
| 189 | * - GitHub API v3 returns both issues and pullRequests together so filtering needs to be done |
||
| 190 | * - Pull requests have 'pull_request' key. |
||
| 191 | * |
||
| 192 | * @return array |
||
| 193 | */ |
||
| 194 | public function fetchAllIssues() |
||
| 206 | |||
| 207 | /** @return array */ |
||
| 208 | View Code Duplication | public function fetchAllIssuesAndPullRequests() |
|
| 218 | |||
| 219 | /** |
||
| 220 | * @return \Github\Api\ApiInterface |
||
| 221 | */ |
||
| 222 | private function getRepoApi() |
||
| 226 | |||
| 227 | /** |
||
| 228 | * @return \Github\Api\ApiInterface |
||
| 229 | */ |
||
| 230 | private function getIssueApi() |
||
| 234 | |||
| 235 | /** |
||
| 236 | * @return \Github\Api\Issue\Milestones |
||
| 237 | */ |
||
| 238 | private function getMilestonesApi() |
||
| 242 | |||
| 243 | /** |
||
| 244 | * @return \Github\Api\PullRequest |
||
| 245 | */ |
||
| 246 | private function getPullRequestApi() |
||
| 250 | } |
||
| 251 |
This check looks for function calls that miss required arguments.