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 |
||
19 | class Resources extends TransifexObject |
||
20 | { |
||
21 | /** |
||
22 | * Method to create a resource. |
||
23 | * |
||
24 | * @param string $project The slug for the project |
||
25 | * @param string $name The name of the resource |
||
26 | * @param string $slug The slug for the resource |
||
27 | * @param string $fileType The file type of the resource |
||
28 | * @param array $options Optional additional params to send with the request |
||
29 | * |
||
30 | * @return \Joomla\Http\Response |
||
31 | */ |
||
32 | 3 | public function createResource($project, $name, $slug, $fileType, array $options = []) |
|
76 | |||
77 | /** |
||
78 | * Method to delete a resource within a project. |
||
79 | * |
||
80 | * @param string $project The project the resource is part of |
||
81 | * @param string $resource The resource slug within the project |
||
82 | * |
||
83 | * @return \Joomla\Http\Response |
||
84 | */ |
||
85 | 2 | View Code Duplication | public function deleteResource($project, $resource) |
93 | |||
94 | /** |
||
95 | * Method to get information about a resource within a project. |
||
96 | * |
||
97 | * @param string $project The project the resource is part of |
||
98 | * @param string $resource The resource slug within the project |
||
99 | * @param bool $details True to retrieve additional project details |
||
100 | * |
||
101 | * @return \Joomla\Http\Response |
||
102 | */ |
||
103 | 2 | View Code Duplication | public function getResource($project, $resource, $details = false) |
115 | |||
116 | /** |
||
117 | * Method to get the content of a resource within a project. |
||
118 | * |
||
119 | * @param string $project The project the resource is part of |
||
120 | * @param string $resource The resource slug within the project |
||
121 | * |
||
122 | * @return \Joomla\Http\Response |
||
123 | */ |
||
124 | 2 | View Code Duplication | public function getResourceContent($project, $resource) |
132 | |||
133 | /** |
||
134 | * Method to get information about a project's resources. |
||
135 | * |
||
136 | * @param string $project The project to retrieve details for |
||
137 | * |
||
138 | * @return \Joomla\Http\Response |
||
139 | */ |
||
140 | 2 | View Code Duplication | public function getResources($project) |
148 | |||
149 | /** |
||
150 | * Method to update the content of a resource within a project. |
||
151 | * |
||
152 | * @param string $project The project the resource is part of |
||
153 | * @param string $resource The resource slug within the project |
||
154 | * @param string $content The content of the resource. This can either be a string of data or a file path. |
||
155 | * @param string $type The type of content in the $content variable. This should be either string or file. |
||
156 | * |
||
157 | * @return \Joomla\Http\Response |
||
158 | */ |
||
159 | 4 | View Code Duplication | public function updateResourceContent($project, $resource, $content, $type = 'string') |
166 | } |
||
167 |
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.