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 |
||
| 9 | class Comment { |
||
| 10 | private $required_connection; |
||
| 11 | private $check_comment; |
||
| 12 | private $table; |
||
| 13 | private $id_in_table; |
||
| 14 | |||
| 15 | |||
| 16 | |||
| 17 | //-------------------------- BUILDER ----------------------------------------------------------------------------// |
||
| 18 | public function __construct() { |
||
| 34 | //-------------------------- END BUILDER ----------------------------------------------------------------------------// |
||
| 35 | |||
| 36 | |||
| 37 | |||
| 38 | //-------------------------- GETTER ----------------------------------------------------------------------------// |
||
| 39 | public function getRequiredConnection() { |
||
| 45 | |||
| 46 | /** |
||
| 47 | * function to display message after comment creation in bdd |
||
| 48 | */ |
||
| 49 | private function getSuccessMessagePublish() { |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @return int |
||
| 60 | * if check_comment unable return 1 to automaticly check a comment |
||
| 61 | */ |
||
| 62 | private function getCheckPublishComment() { |
||
| 69 | |||
| 70 | /** |
||
| 71 | * @param $values |
||
| 72 | * @return string |
||
| 73 | * this function will get the view of list comments and form to write a comment |
||
| 74 | */ |
||
| 75 | private function getRender($values) { |
||
| 85 | |||
| 86 | /** |
||
| 87 | * @param $table |
||
| 88 | * @param $id_in_table |
||
| 89 | * function wich get all comments of an other module like a article of a blog |
||
| 90 | * after all coments was getted it will call getRender to use twig to render them |
||
| 91 | */ |
||
| 92 | public function getComments($table, $id_in_table) { |
||
| 115 | //-------------------------- END GETTER ----------------------------------------------------------------------------// |
||
| 116 | |||
| 117 | |||
| 118 | |||
| 119 | //-------------------------- SETTER ----------------------------------------------------------------------------// |
||
| 120 | /** |
||
| 121 | * @param $table |
||
| 122 | * @param $id_in_table |
||
| 123 | * @param $comment |
||
| 124 | * @param $pseudo |
||
| 125 | * @return bool |
||
| 126 | * function to add a comment if pseudo and comment != "" |
||
| 127 | */ |
||
| 128 | public function setComment($table, $id_in_table, $comment, $pseudo) { |
||
| 148 | //-------------------------- END SETTER ----------------------------------------------------------------------------// |
||
| 149 | |||
| 150 | } |