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 |
||
8 | View Code Duplication | class OnBeforeGroupDelete extends BaseHandler implements HandlerInterface |
|
|
|||
9 | { |
||
10 | /** |
||
11 | * Bitrix group id. |
||
12 | * |
||
13 | * @var int |
||
14 | */ |
||
15 | protected $id; |
||
16 | |||
17 | /** |
||
18 | * Constructor. |
||
19 | * |
||
20 | * @param array $params |
||
21 | * |
||
22 | * @throws StopHandlerException |
||
23 | */ |
||
24 | public function __construct($params) |
||
30 | |||
31 | /** |
||
32 | * Get migration name. |
||
33 | * |
||
34 | * @return string |
||
35 | */ |
||
36 | public function getName() |
||
40 | |||
41 | /** |
||
42 | * Get template name. |
||
43 | * |
||
44 | * @return string |
||
45 | */ |
||
46 | public function getTemplate() |
||
50 | |||
51 | /** |
||
52 | * Get array of placeholders to replace. |
||
53 | * |
||
54 | * @return array |
||
55 | */ |
||
56 | public function getReplace() |
||
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.