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 Comments extends AbstractPackage |
||
21 | { |
||
22 | /** |
||
23 | * Create a comment. |
||
24 | * |
||
25 | * @param integer $gistId The gist number. |
||
26 | * @param string $body The comment body text. |
||
27 | * |
||
28 | * @return object |
||
29 | * |
||
30 | * @since 1.0 |
||
31 | * @throws \DomainException |
||
32 | */ |
||
33 | public function create($gistId, $body) |
||
48 | |||
49 | /** |
||
50 | * Delete a comment. |
||
51 | * |
||
52 | * @param integer $commentId The id of the comment to delete. |
||
53 | * |
||
54 | * @return void |
||
55 | * |
||
56 | * @since 1.0 |
||
57 | * @throws \DomainException |
||
58 | */ |
||
59 | public function delete($commentId) |
||
67 | |||
68 | /** |
||
69 | * Edit a comment. |
||
70 | * |
||
71 | * @param integer $commentId The id of the comment to update. |
||
72 | * @param string $body The new body text for the comment. |
||
73 | * |
||
74 | * @return object |
||
75 | * |
||
76 | * @since 1.0 |
||
77 | * @throws \DomainException |
||
78 | */ |
||
79 | View Code Duplication | public function edit($commentId, $body) |
|
94 | |||
95 | /** |
||
96 | * Get a single comment. |
||
97 | * |
||
98 | * @param integer $commentId The comment id to get. |
||
99 | * |
||
100 | * @return object |
||
101 | * |
||
102 | * @since 1.0 |
||
103 | * @throws \DomainException |
||
104 | */ |
||
105 | public function get($commentId) |
||
113 | |||
114 | /** |
||
115 | * List comments on a gist. |
||
116 | * |
||
117 | * @param integer $gistId The gist number. |
||
118 | * @param integer $page The page number from which to get items. |
||
119 | * @param integer $limit The number of items on a page. |
||
120 | * |
||
121 | * @return object |
||
122 | * |
||
123 | * @since 1.0 |
||
124 | * @throws \DomainException |
||
125 | */ |
||
126 | public function getList($gistId, $page = 0, $limit = 0) |
||
134 | } |
||
135 |
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.