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 |
||
26 | class NavigationService extends AbstractBrowserBindingService implements NavigationServiceInterface |
||
27 | { |
||
28 | /** |
||
29 | * Gets the list of documents that are checked out that the user has access to. |
||
30 | * |
||
31 | * @param string $repositoryId the identifier for the repository |
||
32 | * @param string $folderId the identifier for the folder |
||
33 | * @param string|null $filter a comma-separated list of query names that defines which properties must be |
||
34 | * returned by the repository (default is repository specific) |
||
35 | * @param string|null $orderBy a comma-separated list of query names that define the order of the result set. |
||
36 | * Each query name must be followed by the ascending modifier "ASC" or the descending modifier "DESC" |
||
37 | * (default is repository specific) |
||
38 | * @param boolean $includeAllowableActions if <code>true</code>, then the repository must return the available |
||
39 | * actions for each object in the result set (default is <code>false</code>) |
||
40 | * @param IncludeRelationships|null $includeRelationships indicates what relationships in which the objects |
||
41 | * participate must be returned (default is <code>IncludeRelationships::NONE</code>) |
||
42 | * @param string $renditionFilter indicates what set of renditions the repository must return whose kind |
||
43 | * matches this filter (default is "cmis:none") |
||
44 | * @param integer|null $maxItems the maximum number of items to return in a response |
||
45 | * (default is repository specific) |
||
46 | * @param integer $skipCount number of potential results that the repository MUST skip/page over before |
||
47 | * returning any results (default is 0) |
||
48 | * @param ExtensionDataInterface|null $extension |
||
49 | * @return ObjectListInterface |
||
50 | */ |
||
51 | 2 | public function getCheckedOutDocs( |
|
95 | |||
96 | /** |
||
97 | * Gets the list of child objects contained in the specified folder. |
||
98 | * |
||
99 | * @param string $repositoryId the identifier for the repository |
||
100 | * @param string $folderId the identifier for the folder |
||
101 | * @param string|null $filter a comma-separated list of query names that defines which properties must be |
||
102 | * returned by the repository (default is repository specific) |
||
103 | * @param string|null $orderBy a comma-separated list of query names that define the order of the result set. |
||
104 | * Each query name must be followed by the ascending modifier "ASC" or the descending modifier "DESC" |
||
105 | * (default is repository specific) |
||
106 | * @param boolean $includeAllowableActions if <code>true</code>, then the repository must return the available |
||
107 | * actions for each object in the result set (default is <code>false</code>) |
||
108 | * @param IncludeRelationships|null $includeRelationships indicates what relationships in which the objects |
||
109 | * participate must be returned (default is <code>IncludeRelationships::NONE</code>) |
||
110 | * @param string $renditionFilter indicates what set of renditions the repository must return whose kind |
||
111 | * matches this filter (default is "cmis:none") |
||
112 | * @param boolean $includePathSegment if <code>true</code>, returns a path segment for each child object for use in |
||
113 | * constructing that object's path (default is <code>false</code>) |
||
114 | * @param integer|null $maxItems the maximum number of items to return in a response |
||
115 | * (default is repository specific) |
||
116 | * @param integer $skipCount number of potential results that the repository MUST skip/page over before |
||
117 | * returning any results (default is 0) |
||
118 | * @param ExtensionDataInterface|null $extension |
||
119 | * @return ObjectInFolderListInterface |
||
120 | */ |
||
121 | 3 | public function getChildren( |
|
167 | |||
168 | /** |
||
169 | * Gets the set of descendant objects contained in the specified folder or any of its child folders. |
||
170 | * |
||
171 | * @param string $repositoryId the identifier for the repository |
||
172 | * @param string $folderId the identifier for the folder |
||
173 | * @param integer $depth the number of levels of depth in the folder hierarchy from which to return results |
||
174 | * @param string|null $filter a comma-separated list of query names that defines which properties must be |
||
175 | * returned by the repository (default is repository specific) |
||
176 | * @param boolean $includeAllowableActions if <code>true</code>, then the repository must return the available |
||
177 | * actions for each object in the result set (default is <code>false</code>) |
||
178 | * @param IncludeRelationships|null $includeRelationships indicates what relationships in which the objects |
||
179 | * participate must be returned (default is <code>IncludeRelationships::NONE</code>) |
||
180 | * @param string $renditionFilter indicates what set of renditions the repository must return whose kind |
||
181 | * matches this filter (default is "cmis:none") |
||
182 | * @param boolean $includePathSegment if <code>true</code>, returns a path segment for each child object for use in |
||
183 | * constructing that object's path (default is <code>false</code>) |
||
184 | * @param ExtensionDataInterface|null $extension |
||
185 | * @return ObjectInFolderContainerInterface[] |
||
186 | */ |
||
187 | 3 | View Code Duplication | public function getDescendants( |
223 | |||
224 | /** |
||
225 | * Gets the parent folder object for the specified folder object. |
||
226 | * |
||
227 | * @param string $repositoryId the identifier for the repository |
||
228 | * @param string $folderId the identifier for the folder |
||
229 | * @param string|null $filter a comma-separated list of query names that defines which properties must be |
||
230 | * returned by the repository (default is repository specific) |
||
231 | * @param ExtensionDataInterface|null $extension |
||
232 | * @return ObjectDataInterface |
||
233 | */ |
||
234 | 2 | public function getFolderParent( |
|
257 | |||
258 | /** |
||
259 | * Gets the set of descendant folder objects contained in the specified folder. |
||
260 | * |
||
261 | * @param string $repositoryId the identifier for the repository |
||
262 | * @param string $folderId the identifier for the folder |
||
263 | * @param integer $depth the number of levels of depth in the folder hierarchy from which to return results |
||
264 | * @param string|null $filter a comma-separated list of query names that defines which properties must be |
||
265 | * returned by the repository (default is repository specific) |
||
266 | * @param boolean $includeAllowableActions if <code>true</code>, then the repository must return the available |
||
267 | * actions for each object in the result set (default is <code>false</code>) |
||
268 | * @param IncludeRelationships|null $includeRelationships indicates what relationships in which the objects |
||
269 | * participate must be returned (default is <code>IncludeRelationships::NONE</code>) |
||
270 | * @param string $renditionFilter indicates what set of renditions the repository must return whose kind |
||
271 | * matches this filter (default is "cmis:none") |
||
272 | * @param boolean $includePathSegment if <code>true</code>, returns a path segment for each child object for use in |
||
273 | * constructing that object's path (default is <code>false</code>) |
||
274 | * @param ExtensionDataInterface|null $extension |
||
275 | * @return ObjectInFolderContainerInterface[] |
||
276 | */ |
||
277 | 2 | View Code Duplication | public function getFolderTree( |
313 | |||
314 | /** |
||
315 | * Gets the parent folder(s) for the specified non-folder, fileable object |
||
316 | * |
||
317 | * @param string $repositoryId the identifier for the repository |
||
318 | * @param string $objectId the identifier for the object |
||
319 | * @param string|null $filter a comma-separated list of query names that defines which properties must be |
||
320 | * returned by the repository (default is repository specific) |
||
321 | * @param boolean $includeAllowableActions if <code>true</code>, then the repository must return the available |
||
322 | * actions for each object in the result set (default is <code>false</code>) |
||
323 | * @param IncludeRelationships|null $includeRelationships indicates what relationships in which the objects |
||
324 | * participate must be returned (default is <code>IncludeRelationships::NONE</code>) |
||
325 | * @param string $renditionFilter indicates what set of renditions the repository must return whose kind |
||
326 | * matches this filter (default is "cmis:none") |
||
327 | * @param boolean $includeRelativePathSegment if <code>true</code>, returns a relative path segment for each parent |
||
328 | * object for use in constructing that object's path (default is <code>false</code>) |
||
329 | * @param ExtensionDataInterface|null $extension |
||
330 | * @return ObjectParentDataInterface[] |
||
331 | */ |
||
332 | 2 | View Code Duplication | public function getObjectParents( |
366 | } |
||
367 |
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.