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 m2_acp_module extends \phpbb\db\migration\migration |
||
14 | { |
||
15 | /** |
||
16 | * {@inheritDoc} |
||
17 | */ |
||
18 | View Code Duplication | public function effectively_installed() |
|
1 ignored issue
–
show
|
|||
19 | { |
||
20 | $sql = 'SELECT module_id |
||
21 | FROM ' . $this->table_prefix . "modules |
||
22 | WHERE module_class = 'acp' |
||
23 | AND module_langname = 'ACP_ADMANAGEMENT_TITLE'"; |
||
24 | $result = $this->db->sql_query($sql); |
||
25 | $module_id = (int) $this->db->sql_fetchfield('module_id'); |
||
26 | $this->db->sql_freeresult($result); |
||
27 | |||
28 | return $module_id; |
||
29 | } |
||
30 | |||
31 | /** |
||
32 | * {@inheritDoc} |
||
33 | */ |
||
34 | static public function depends_on() |
||
38 | |||
39 | /** |
||
40 | * Add the ACP module |
||
41 | * |
||
42 | * @return array Array of data update instructions |
||
43 | */ |
||
44 | public function update_data() |
||
62 | } |
||
63 |
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.