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 |
||
9 | class E210 extends Element implements ElementInterface |
||
10 | { |
||
11 | const REG = 'E210'; |
||
12 | const LEVEL = 3; |
||
13 | const PARENT = 'E200'; |
||
14 | |||
15 | protected $parameters = [ |
||
16 | 'IND_MOV_ST' => [ |
||
17 | 'type' => 'integer', |
||
18 | 'regex' => '^[0-1]{1}$', |
||
19 | 'required' => true, |
||
20 | 'info' => 'Indicador de movimento: 0 – Sem operações com ST 1 – Com operações de ST', |
||
21 | 'format' => '' |
||
22 | ], |
||
23 | 'VL_SLD_CRED_ANT_ST' => [ |
||
24 | 'type' => 'numeric', |
||
25 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
26 | 'required' => true, |
||
27 | 'info' => 'Valor do "Saldo credor de período anterior – Substituição Tributária"', |
||
28 | 'format' => '15v2' |
||
29 | ], |
||
30 | 'VL_DEVOL_ST' => [ |
||
31 | 'type' => 'numeric', |
||
32 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
33 | 'required' => true, |
||
34 | 'info' => 'Valor total do ICMS ST de devolução de mercadorias', |
||
35 | 'format' => '15v2' |
||
36 | ], |
||
37 | 'VL_RESSARC_ST' => [ |
||
38 | 'type' => 'numeric', |
||
39 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
40 | 'required' => true, |
||
41 | 'info' => 'Valor total do ICMS ST de ressarcimentos', |
||
42 | 'format' => '15v2' |
||
43 | ], |
||
44 | 'VL_OUT_CRED_ST' => [ |
||
45 | 'type' => 'numeric', |
||
46 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
47 | 'required' => true, |
||
48 | 'info' => 'Valor total de Ajustes "Outros créditos ST" e “Estorno de débitos ST”', |
||
49 | 'format' => '15v2' |
||
50 | ], |
||
51 | 'VL_AJ_CREDITOS_ST' => [ |
||
52 | 'type' => 'numeric', |
||
53 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
54 | 'required' => true, |
||
55 | 'info' => 'Valor total dos ajustes a crédito de ICMS ST, provenientes de ajustes do documento fiscal.', |
||
56 | 'format' => '15v2' |
||
57 | ], |
||
58 | 'VL_RETENCAO_ST' => [ |
||
59 | 'type' => 'numeric', |
||
60 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
61 | 'required' => true, |
||
62 | 'info' => 'Valor Total do ICMS retido por Substituição Tributária', |
||
63 | 'format' => '15v2' |
||
64 | ], |
||
65 | 'VL_OUT_DEB_ST' => [ |
||
66 | 'type' => 'numeric', |
||
67 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
68 | 'required' => true, |
||
69 | 'info' => 'Valor Total dos ajustes "Outros débitos ST" " e “Estorno de créditos ST”', |
||
70 | 'format' => '15v2' |
||
71 | ], |
||
72 | 'VL_AJ_DEBITOS_ST' => [ |
||
73 | 'type' => 'numeric', |
||
74 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
75 | 'required' => true, |
||
76 | 'info' => 'Valor total dos ajustes a débito de ICMS ST, provenientes de ajustes do documento fiscal.', |
||
77 | 'format' => '15v2' |
||
78 | ], |
||
79 | 'VL_SLD_DEV_ANT_ST' => [ |
||
80 | 'type' => 'numeric', |
||
81 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
82 | 'required' => true, |
||
83 | 'info' => 'Valor total de Saldo devedor antes das deduções', |
||
84 | 'format' => '15v2' |
||
85 | ], |
||
86 | 'VL_DEDUCOES_ST' => [ |
||
87 | 'type' => 'numeric', |
||
88 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
89 | 'required' => true, |
||
90 | 'info' => 'Valor total dos ajustes "Deduções ST"', |
||
91 | 'format' => '15v2' |
||
92 | ], |
||
93 | 'VL_ICMS_RECOL_ST' => [ |
||
94 | 'type' => 'numeric', |
||
95 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
96 | 'required' => true, |
||
97 | 'info' => 'Imposto a recolher ST (11-12)', |
||
98 | 'format' => '15v2' |
||
99 | ], |
||
100 | 'VL_SLD_CRED_ST_TRANSPORTAR' => [ |
||
101 | 'type' => 'numeric', |
||
102 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
103 | 'required' => true, |
||
104 | 'info' => 'Saldo credor de ST a transportar para o período ' |
||
105 | .'seguinte [(03+04+05+06+07+12)– (08+09+10)].', |
||
106 | 'format' => '15v2' |
||
107 | ], |
||
108 | 'DEB_ESP_ST' => [ |
||
109 | 'type' => 'numeric', |
||
110 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
111 | 'required' => true, |
||
112 | 'info' => 'Valores recolhidos ou a recolher, extra- apuração.', |
||
113 | 'format' => '15v2' |
||
114 | ] |
||
115 | ]; |
||
116 | |||
117 | /** |
||
118 | * Constructor |
||
119 | * @param \stdClass $std |
||
120 | */ |
||
121 | public function __construct(\stdClass $std) |
||
128 | |||
129 | public function postValidation() |
||
209 | } |
||
210 |
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.