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 |
||
| 14 | abstract class abstract_module implements module_interface |
||
| 15 | { |
||
| 16 | /** |
||
| 17 | * @var \phpbb\db\driver\driver_interface |
||
| 18 | */ |
||
| 19 | protected $db; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @var \phpbb\user |
||
| 23 | */ |
||
| 24 | protected $user; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @var \phpbb\template\template |
||
| 28 | */ |
||
| 29 | protected $template; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * This method is called to show the UCP page. |
||
| 33 | * You can assign template variables to the template, or do anything else here. |
||
| 34 | * |
||
| 35 | * @param string $table |
||
| 36 | */ |
||
| 37 | protected function show_ucp_complete($table) |
||
| 58 | |||
| 59 | /** |
||
| 60 | * Check if the provided user as a specific key in the table provided |
||
| 61 | * |
||
| 62 | * @param string $table Table to check in |
||
| 63 | * @param int $user_id The specific user |
||
| 64 | * |
||
| 65 | * @return bool |
||
| 66 | */ |
||
| 67 | View Code Duplication | protected function check_table_for_user($table, $user_id) |
|
| 79 | } |
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.