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 | View Code Duplication | class view_controller |
|
|
|||
17 | { |
||
18 | /** @var \phpbb\ads\ad\manager */ |
||
19 | protected $manager; |
||
20 | |||
21 | /** @var \phpbb\request\request */ |
||
22 | protected $request; |
||
23 | |||
24 | /** |
||
25 | * Constructor |
||
26 | * |
||
27 | * @param \phpbb\ads\ad\manager $manager Advertisement manager object |
||
28 | * @param \phpbb\request\request $request Request object |
||
29 | */ |
||
30 | public function __construct(\phpbb\ads\ad\manager $manager, \phpbb\request\request $request) |
||
35 | |||
36 | /** |
||
37 | * Increment views for ads |
||
38 | * |
||
39 | * @param string $ad_ids Advertisement IDs |
||
40 | * @return \Symfony\Component\HttpFoundation\JsonResponse A Symfony JsonResponse object |
||
41 | */ |
||
42 | public function increment_views($ad_ids) |
||
55 | } |
||
56 |
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.