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 |
||
14 | View Code Duplication | class H030 extends Element implements ElementInterface |
|
|
|||
15 | { |
||
16 | const REG = 'H030'; |
||
17 | const LEVEL = 4; |
||
18 | const PARENT = 'H010'; |
||
19 | |||
20 | protected $parameters = [ |
||
21 | 'VL_ICMS_OP' => [ |
||
22 | 'type' => 'numeric', |
||
23 | 'regex' => '', |
||
24 | 'required' => true, |
||
25 | 'info' => 'Valor médio unitário do ICMS OP', |
||
26 | 'format' => '15v6' |
||
27 | ], |
||
28 | 'VL_BC_ICMS_ST' => [ |
||
29 | 'type' => 'numeric', |
||
30 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
31 | 'required' => true, |
||
32 | 'info' => 'Valor médio unitário da base de cálculo do ICMS ST', |
||
33 | 'format' => '15v6' |
||
34 | ], |
||
35 | 'VL_ICMS_ST' => [ |
||
36 | 'type' => 'numeric', |
||
37 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
38 | 'required' => true, |
||
39 | 'info' => 'Valor médio unitário do ICMS ST', |
||
40 | 'format' => '15v6' |
||
41 | ], |
||
42 | 'VL_FCP' => [ |
||
43 | 'type' => 'numeric', |
||
44 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
45 | 'required' => true, |
||
46 | 'info' => 'Valor médio unitário do FCP', |
||
47 | 'format' => '15v6' |
||
48 | ], |
||
49 | ]; |
||
50 | |||
51 | /** |
||
52 | * Constructor |
||
53 | * @param \stdClass $std |
||
54 | */ |
||
55 | public function __construct(\stdClass $std) |
||
60 | } |
||
61 |
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.