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 |
||
10 | View Code Duplication | class C490 extends Element implements ElementInterface |
|
|
|||
11 | { |
||
12 | const REG = 'C490'; |
||
13 | const LEVEL = 4; |
||
14 | const PARENT = 'C400'; |
||
15 | |||
16 | protected $parameters = [ |
||
17 | 'CST_ICMS' => [ |
||
18 | 'type' => 'numeric', |
||
19 | 'regex' => '^(\d{3})$', |
||
20 | 'required' => true, |
||
21 | 'info' => 'Código da Situação Tributária,', |
||
22 | 'format' => '' |
||
23 | ], |
||
24 | 'CFOP' => [ |
||
25 | 'type' => 'numeric', |
||
26 | 'regex' => '^(\d{4})$', |
||
27 | 'required' => true, |
||
28 | 'info' => 'Código Fiscal de Operação e Prestação', |
||
29 | 'format' => '' |
||
30 | ], |
||
31 | 'ALIQ_ICMS' => [ |
||
32 | 'type' => 'numeric', |
||
33 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
34 | 'required' => false, |
||
35 | 'info' => 'Alíquota do ICMS', |
||
36 | 'format' => '6v2' |
||
37 | ], |
||
38 | 'VL_OPR' => [ |
||
39 | 'type' => 'numeric', |
||
40 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
41 | 'required' => true, |
||
42 | 'info' => 'Valor da operação correspondente à combinação de CST_ICMS, CFOP, e alíquota do ICMS, |
||
43 | incluídas as despesas acessórias e acréscimos', |
||
44 | 'format' => '15v2' |
||
45 | ], |
||
46 | 'VL_BC_ICMS' => [ |
||
47 | 'type' => 'numeric', |
||
48 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
49 | 'required' => true, |
||
50 | 'info' => 'Valor acumulado da base de cálculo do ICMS, referente à combinação |
||
51 | de CST_ICMS, CFOP, e alíquota do ICMS.', |
||
52 | 'format' => '15v2' |
||
53 | ], |
||
54 | 'VL_ICMS' => [ |
||
55 | 'type' => 'numeric', |
||
56 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
57 | 'required' => true, |
||
58 | 'info' => 'Valor acumulado do ICMS, referente à combinação de CST_ICMS, CFOP e alíquota do ICMS.', |
||
59 | 'format' => '15v2' |
||
60 | ], |
||
61 | 'COD_OBS' => [ |
||
62 | 'type' => 'string', |
||
63 | 'regex' => '^.{0,6}$', |
||
64 | 'required' => false, |
||
65 | 'info' => 'Código da observação do lançamento fiscal (campo 02 do Registro 0460)', |
||
66 | 'format' => '' |
||
67 | ], |
||
68 | ]; |
||
69 | |||
70 | /** |
||
71 | * Constructor |
||
72 | * @param \stdClass $std |
||
73 | */ |
||
74 | public function __construct(\stdClass $std) |
||
80 | |||
81 | public function postValidation() |
||
113 | } |
||
114 |
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.