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 |
||
16 | class ucp_controller |
||
17 | { |
||
18 | /** @var \phpbb\ads\ad\manager */ |
||
19 | protected $manager; |
||
20 | |||
21 | /** @var \phpbb\ads\controller\helper */ |
||
22 | protected $helper; |
||
23 | |||
24 | /** @var \phpbb\user */ |
||
25 | protected $user; |
||
26 | |||
27 | /** @var \phpbb\language\language */ |
||
28 | protected $language; |
||
29 | |||
30 | /** @var \phpbb\template\template */ |
||
31 | protected $template; |
||
32 | |||
33 | /** @var \phpbb\config\config */ |
||
34 | protected $config; |
||
35 | |||
36 | /** @var string Custom form action */ |
||
37 | protected $u_action; |
||
38 | |||
39 | /** |
||
40 | * Constructor |
||
41 | * |
||
42 | * @param \phpbb\ads\ad\manager $manager Advertisement manager object |
||
43 | * @param \phpbb\ads\controller\helper $helper Helper object |
||
44 | * @param \phpbb\user $user User object |
||
45 | * @param \phpbb\language\language $language Language object |
||
46 | * @param \phpbb\template\template $template Template object |
||
47 | * @param \phpbb\config\config $config Config object |
||
48 | */ |
||
49 | 5 | public function __construct(\phpbb\ads\ad\manager $manager, \phpbb\ads\controller\helper $helper, \phpbb\user $user, \phpbb\language\language $language, \phpbb\template\template $template, \phpbb\config\config $config) |
|
58 | |||
59 | /** |
||
60 | * @param string $u_action Action URL |
||
61 | */ |
||
62 | 5 | public function set_page_url($u_action) |
|
66 | |||
67 | /** |
||
68 | * @return string Module language string |
||
69 | */ |
||
70 | 1 | public function get_page_title() |
|
74 | |||
75 | /** |
||
76 | * Display UCP ads module |
||
77 | */ |
||
78 | 4 | public function main() |
|
110 | } |
||
111 |
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.