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 |
||
8 | class SampleDataProvider |
||
9 | { |
||
10 | const DEFAULT_REPO = 'devboard/test-hitman'; |
||
11 | const DEFAULT_BRANCH = 'master'; |
||
12 | const DEFAULT_COMMIT_SHA = 'db911bd3a3dd8bb2ad9eccbcb0a396595a51491d'; |
||
13 | |||
14 | /** |
||
15 | * @return array |
||
16 | */ |
||
17 | public function getRepos() |
||
21 | |||
22 | /** |
||
23 | * @return mixed |
||
24 | */ |
||
25 | public function getRepoDetails($fullName = self::DEFAULT_REPO) |
||
31 | |||
32 | /** |
||
33 | * @return mixed |
||
34 | */ |
||
35 | public function getBranch($fullName = self::DEFAULT_REPO, $branchName = self::DEFAULT_BRANCH) |
||
41 | |||
42 | /** |
||
43 | * @return mixed |
||
44 | */ |
||
45 | public function getAllBranches($fullName = self::DEFAULT_REPO) |
||
51 | |||
52 | /** |
||
53 | * @return mixed |
||
54 | */ |
||
55 | public function getAllBranchNames($fullName = self::DEFAULT_REPO) |
||
61 | |||
62 | /** |
||
63 | * @return mixed |
||
64 | */ |
||
65 | public function getAllTagNames($fullName = self::DEFAULT_REPO) |
||
71 | |||
72 | /** |
||
73 | * @return mixed |
||
74 | */ |
||
75 | View Code Duplication | public function getCommit($fullName = self::DEFAULT_REPO, $commitSha = self::DEFAULT_COMMIT_SHA) |
|
83 | |||
84 | /** |
||
85 | * @return mixed |
||
86 | */ |
||
87 | View Code Duplication | public function getCommitStatus($fullName = self::DEFAULT_REPO, $commitSha = self::DEFAULT_COMMIT_SHA) |
|
95 | |||
96 | /** |
||
97 | * @return mixed |
||
98 | */ |
||
99 | View Code Duplication | public function getCommitStatuses($fullName = self::DEFAULT_REPO, $commitSha = self::DEFAULT_COMMIT_SHA) |
|
107 | |||
108 | /** |
||
109 | * @return mixed |
||
110 | */ |
||
111 | public function getAllPullRequests($fullName = self::DEFAULT_REPO) |
||
117 | |||
118 | /** |
||
119 | * @return mixed |
||
120 | */ |
||
121 | public function getAllMilestones($fullName = self::DEFAULT_REPO) |
||
127 | |||
128 | /** |
||
129 | * @return mixed |
||
130 | */ |
||
131 | public function getAllIssues($fullName = self::DEFAULT_REPO) |
||
137 | |||
138 | /** |
||
139 | * @return mixed |
||
140 | */ |
||
141 | public function getMyRepositoriesAll() |
||
147 | } |
||
148 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.