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 |
||
13 | class clean_old_ideas extends \phpbb\textreparser\row_based_plugin |
||
14 | { |
||
15 | /** @var \phpbb\textformatter\s9e\utils */ |
||
16 | protected $text_formatter_utils; |
||
17 | |||
18 | /** @var string */ |
||
19 | protected $ideas_table; |
||
20 | |||
21 | /** @var string */ |
||
22 | protected $topics_table; |
||
23 | |||
24 | /** |
||
25 | * Constructor |
||
26 | * |
||
27 | * @param \phpbb\db\driver\driver_interface $db Database connection |
||
28 | * @param \phpbb\textformatter\s9e\utils $text_formatter_utils Text formatter utilities object |
||
29 | * @param string $table Posts Table |
||
30 | * @param string $topics_table Topics Table |
||
31 | * @param string $ideas_table Ideas Table |
||
32 | */ |
||
33 | public function __construct(\phpbb\db\driver\driver_interface $db, \phpbb\textformatter\s9e\utils $text_formatter_utils, $table, $topics_table, $ideas_table) |
||
41 | |||
42 | /** |
||
43 | * {@inheritdoc} |
||
44 | */ |
||
45 | public function get_columns() |
||
52 | |||
53 | /** |
||
54 | * {@inheritdoc} |
||
55 | */ |
||
56 | View Code Duplication | public function get_max_id() |
|
65 | |||
66 | /** |
||
67 | * {@inheritdoc} |
||
68 | */ |
||
69 | protected function get_records_by_range_query($min_id, $max_id) |
||
89 | |||
90 | /** |
||
91 | * {@inheritdoc} |
||
92 | */ |
||
93 | protected function reparse_record(array $record) |
||
117 | } |
||
118 |
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.