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 |
||
| 15 | class comment extends helper |
||
| 16 | { |
||
| 17 | /** @var \phpbb\db\driver\driver_interface $db */ |
||
| 18 | protected $db; |
||
| 19 | |||
| 20 | /** @var \phpbb\language\language */ |
||
| 21 | protected $language; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * Constructor |
||
| 25 | * |
||
| 26 | * @param \phpbb\db\driver\driver_interface $db Database object |
||
| 27 | * @param \phpbb\language\language $language Language object |
||
| 28 | */ |
||
| 29 | public function __construct(\phpbb\db\driver\driver_interface $db, \phpbb\language\language $language) |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Add a comment |
||
| 37 | * |
||
| 38 | * @param array $data Link's data from db |
||
| 39 | * @return null |
||
| 40 | */ |
||
| 41 | public function add($data) |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Edit a comment |
||
| 58 | * |
||
| 59 | * @param array $data Data to edit |
||
| 60 | * @param int $comment_id The comment ID |
||
| 61 | * @return null |
||
| 62 | */ |
||
| 63 | public function edit($data, $comment_id) |
||
| 70 | |||
| 71 | /** |
||
| 72 | * Delete a comment |
||
| 73 | * |
||
| 74 | * @param string $link_id The link ID |
||
| 75 | * @param string $comment_id The comment ID |
||
| 76 | * @return null |
||
| 77 | */ |
||
| 78 | public function del($link_id, $comment_id) |
||
| 114 | } |
||
| 115 |