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 |
||
7 | class CommentsInSession extends \Phpmvc\Comment\CommentsInSession |
||
|
|||
8 | { |
||
9 | |||
10 | View Code Duplication | private function humanTiming($time) |
|
33 | |||
34 | /** |
||
35 | * Get either a Gravatar URL or complete image tag for a specified email address. |
||
36 | * |
||
37 | * @param string $email The email address |
||
38 | * @param string $s Size in pixels, defaults to 80px [ 1 - 2048 ] |
||
39 | * @param string $d Default imageset to use [ 404 | mm | identicon | monsterid | wavatar ] |
||
40 | * @param string $r Maximum rating (inclusive) [ g | pg | r | x ] |
||
41 | * @param boole $img True to return a complete IMG tag False for just the URL |
||
42 | * @param array $atts Optional, additional key/value attributes to include in the IMG tag |
||
43 | * @return String containing either just a URL or a complete image tag |
||
44 | * @source http://gravatar.com/site/implement/images/php/ |
||
45 | */ |
||
46 | View Code Duplication | private function getGravatar($email, $s = 80, $d = 'mm', $r = 'g', $img = false, $atts = array()) |
|
60 | |||
61 | /** |
||
62 | * Find and return all comments within the page comment flow. |
||
63 | * |
||
64 | * @return array with all comments. |
||
65 | */ |
||
66 | public function findAll() |
||
82 | |||
83 | /** |
||
84 | * Update a comment. |
||
85 | * |
||
86 | * @param array $comment with all details. |
||
87 | * @param integer $id of comment to be updated |
||
88 | * |
||
89 | * @return void |
||
90 | */ |
||
91 | public function update($comment, $id) |
||
97 | |||
98 | /** |
||
99 | * Delete a comment. |
||
100 | * |
||
101 | * @param $id of post to delete. |
||
102 | * |
||
103 | * @return void |
||
104 | */ |
||
105 | public function delete($id) |
||
111 | } |
||
112 |