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 JsonSampleDataProvider |
||
9 | { |
||
10 | /** Full name of default repo */ |
||
11 | const DEFAULT_REPO = 'devboard/test-hitman'; |
||
12 | /** Branch name of default branch*/ |
||
13 | const DEFAULT_BRANCH = 'master'; |
||
14 | /** Sha for default commit*/ |
||
15 | const DEFAULT_COMMIT_SHA = 'db911bd3a3dd8bb2ad9eccbcb0a396595a51491d'; |
||
16 | |||
17 | /** |
||
18 | * @return array |
||
19 | */ |
||
20 | public function getRepos() |
||
24 | |||
25 | /** |
||
26 | * @param string $fullName |
||
27 | * |
||
28 | * @return mixed |
||
29 | */ |
||
30 | public function getRepoDetails(string $fullName = self::DEFAULT_REPO) |
||
36 | |||
37 | /** |
||
38 | * @param string $fullName |
||
39 | * @param string $branchName |
||
40 | * |
||
41 | * @return mixed |
||
42 | */ |
||
43 | public function getBranch(string $fullName = self::DEFAULT_REPO, string $branchName = self::DEFAULT_BRANCH) |
||
49 | |||
50 | /** |
||
51 | * @param string $fullName |
||
52 | * |
||
53 | * @return mixed |
||
54 | */ |
||
55 | public function getAllBranches(string $fullName = self::DEFAULT_REPO) |
||
61 | |||
62 | /** |
||
63 | * @param string $fullName |
||
64 | * |
||
65 | * @return mixed |
||
66 | */ |
||
67 | public function getAllBranchNames(string $fullName = self::DEFAULT_REPO) |
||
73 | |||
74 | /** |
||
75 | * @param string $fullName |
||
76 | * |
||
77 | * @return mixed |
||
78 | */ |
||
79 | public function getAllTagNames(string $fullName = self::DEFAULT_REPO) |
||
85 | |||
86 | /** |
||
87 | * @param string $fullName |
||
88 | * @param string $sha |
||
89 | * |
||
90 | * @return mixed |
||
91 | */ |
||
92 | View Code Duplication | public function getCommit(string $fullName = self::DEFAULT_REPO, string $sha = self::DEFAULT_COMMIT_SHA) |
|
100 | |||
101 | /** |
||
102 | * @param string $fullName |
||
103 | * @param string $sha |
||
104 | * |
||
105 | * @return mixed |
||
106 | */ |
||
107 | View Code Duplication | public function getCommitStatus(string $fullName = self::DEFAULT_REPO, string $sha = self::DEFAULT_COMMIT_SHA) |
|
115 | |||
116 | /** |
||
117 | * @param string $fullName |
||
118 | * @param string $sha |
||
119 | * |
||
120 | * @return mixed |
||
121 | */ |
||
122 | View Code Duplication | public function getCommitStatuses(string $fullName = self::DEFAULT_REPO, string $sha = self::DEFAULT_COMMIT_SHA) |
|
130 | |||
131 | /** |
||
132 | * @param string $fullName |
||
133 | * |
||
134 | * @return mixed |
||
135 | */ |
||
136 | public function getAllPullRequests(string $fullName = self::DEFAULT_REPO) |
||
142 | |||
143 | /** |
||
144 | * @param string $fullName |
||
145 | * |
||
146 | * @return mixed |
||
147 | */ |
||
148 | public function getAllMilestones(string $fullName = self::DEFAULT_REPO) |
||
154 | |||
155 | /** |
||
156 | * @param string $fullName |
||
157 | * |
||
158 | * @return mixed |
||
159 | */ |
||
160 | public function getAllIssues(string $fullName = self::DEFAULT_REPO) |
||
166 | |||
167 | /** |
||
168 | * @return mixed |
||
169 | */ |
||
170 | public function getMyRepositoriesAll() |
||
176 | } |
||
177 |
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.