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 |
||
20 | class Refs extends AbstractPackage |
||
21 | { |
||
22 | /** |
||
23 | * Get a Reference. |
||
24 | * |
||
25 | * @param string $user The name of the owner of the GitHub repository. |
||
26 | * @param string $repo The name of the GitHub repository. |
||
27 | * @param string $ref The reference to get. |
||
28 | * |
||
29 | * @return object |
||
30 | * |
||
31 | * @since 1.0 |
||
32 | * @throws \DomainException |
||
33 | */ |
||
34 | public function get($user, $repo, $ref) |
||
42 | |||
43 | /** |
||
44 | * Get all References. |
||
45 | * |
||
46 | * @param string $user The name of the owner of the GitHub repository. |
||
47 | * @param string $repo The name of the GitHub repository. |
||
48 | * @param string $namespace Optional sub-namespace to limit the returned references. |
||
49 | * @param integer $page Page to request |
||
50 | * @param integer $limit Number of results to return per page |
||
51 | * |
||
52 | * @return object |
||
53 | * |
||
54 | * @since 1.0 |
||
55 | * @throws \DomainException |
||
56 | */ |
||
57 | public function getList($user, $repo, $namespace = '', $page = 0, $limit = 0) |
||
70 | |||
71 | /** |
||
72 | * Create a Reference. |
||
73 | * |
||
74 | * @param string $user The name of the owner of the GitHub repository. |
||
75 | * @param string $repo The name of the GitHub repository. |
||
76 | * @param string $ref The name of the fully qualified reference. |
||
77 | * @param string $sha The SHA1 value to set this reference to. |
||
78 | * |
||
79 | * @return object |
||
80 | * |
||
81 | * @since 1.0 |
||
82 | * @throws \DomainException |
||
83 | */ |
||
84 | public function create($user, $repo, $ref, $sha) |
||
100 | |||
101 | /** |
||
102 | * Update a Reference. |
||
103 | * |
||
104 | * @param string $user The name of the owner of the GitHub repository. |
||
105 | * @param string $repo The name of the GitHub repository. |
||
106 | * @param string $ref The reference to update. |
||
107 | * @param string $sha The SHA1 value to set the reference to. |
||
108 | * @param boolean $force Whether the update should be forced. Default to false. |
||
109 | * |
||
110 | * @return object |
||
111 | * |
||
112 | * @since 1.0 |
||
113 | * @throws DomainException |
||
114 | */ |
||
115 | public function edit($user, $repo, $ref, $sha, $force = false) |
||
137 | |||
138 | /** |
||
139 | * Delete a Reference |
||
140 | * |
||
141 | * @param string $owner The name of the owner of the GitHub repository. |
||
142 | * @param string $repo The name of the GitHub repository. |
||
143 | * @param string $ref The reference to update. |
||
144 | * |
||
145 | * @return object |
||
146 | * |
||
147 | * @since 1.0 |
||
148 | */ |
||
149 | View Code Duplication | public function delete($owner, $repo, $ref) |
|
159 | } |
||
160 |
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.