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 E310 extends Element implements ElementInterface |
||
10 | { |
||
11 | const REG = 'E310'; |
||
12 | const LEVEL = 3; |
||
13 | const PARENT = 'E300'; |
||
14 | |||
15 | protected $parameters = [ |
||
16 | 'IND_MOV_FCP_DIFAL' => [ |
||
17 | 'type' => 'string', |
||
18 | 'regex' => '^[0|1]$', |
||
19 | 'required' => true, |
||
20 | 'info' => 'Indicador de movimento: ' |
||
21 | .'0 – Sem operações ' |
||
22 | .'1 – Com operações', |
||
23 | 'format' => '' |
||
24 | ], |
||
25 | 'VL_SLD_CRED_ANT_DIFAL' => [ |
||
26 | 'type' => 'numeric', |
||
27 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
28 | 'required' => true, |
||
29 | 'info' => 'Valor do "Saldo credor de período anterior – ICMS Diferencial de ' |
||
30 | .'Alíquota da UF de Origem/Destino"', |
||
31 | 'format' => '15v2' |
||
32 | ], |
||
33 | 'VL_TOT_DEBITOS_DIFAL' => [ |
||
34 | 'type' => 'numeric', |
||
35 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
36 | 'required' => true, |
||
37 | 'info' => 'Valor total dos débitos por "Saídas e prestações com débito do ICMS ' |
||
38 | .'referente ao diferencial de alíquota devido à UF de Origem/Destino"', |
||
39 | 'format' => '15v2' |
||
40 | ], |
||
41 | 'VL_OUT_DEB_DIFAL' => [ |
||
42 | 'type' => 'numeric', |
||
43 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
44 | 'required' => true, |
||
45 | 'info' => 'Valor Total dos ajustes "Outros débitos ICMS Diferencial de Alíquota da UF de ' |
||
46 | .'Origem/Destino" e “Estorno de créditos ICMS Diferencial de Alíquota da UF de Origem/Destino', |
||
47 | 'format' => '15v2' |
||
48 | ], |
||
49 | 'VL_TOT_CREDITOS_DIFAL' => [ |
||
50 | 'type' => 'numeric', |
||
51 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
52 | 'required' => true, |
||
53 | 'info' => 'Valor total dos créditos do ICMS referente ao diferencial de alíquota ' |
||
54 | .'devido à UF de Origem/Destino', |
||
55 | 'format' => '15v2' |
||
56 | ], |
||
57 | 'VL_OUT_CRED_DIFAL' => [ |
||
58 | 'type' => 'numeric', |
||
59 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
60 | 'required' => true, |
||
61 | 'info' => 'Valor total de Ajustes "Outros créditos ICMS Diferencial de Alíquota da UF de ' |
||
62 | .'Origem/Destino" e “Estorno de débitos ICMS Diferencial de Alíquota da UF de Origem/Destino”', |
||
63 | 'format' => '15v2' |
||
64 | ], |
||
65 | 'VL_SLD_DEV_ANT_DIFAL' => [ |
||
66 | 'type' => 'numeric', |
||
67 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
68 | 'required' => true, |
||
69 | 'info' => 'Valor total de Saldo devedor ICMS Diferencial de Alíquota da UF de ' |
||
70 | .'Origem/Destino antes das deduções', |
||
71 | 'format' => '15v2' |
||
72 | ], |
||
73 | 'VL_DEDUCOES_DIFAL' => [ |
||
74 | 'type' => 'numeric', |
||
75 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
76 | 'required' => true, |
||
77 | 'info' => 'Valor total dos ajustes "Deduções ICMS Diferencial de Alíquota da UF de Origem/Destino"', |
||
78 | 'format' => '15v2' |
||
79 | ], |
||
80 | 'VL_RECOL_DIFAL' => [ |
||
81 | 'type' => 'numeric', |
||
82 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
83 | 'required' => true, |
||
84 | 'info' => 'Valor recolhido ou a recolher referente ao ICMS Diferencial de Alíquota ' |
||
85 | .'da UF de Origem/Destino (08-09)', |
||
86 | 'format' => '15v2' |
||
87 | ], |
||
88 | 'VL_SLD_CRED_TRANSPORTAR_DIFAL' => [ |
||
89 | 'type' => 'numeric', |
||
90 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
91 | 'required' => true, |
||
92 | 'info' => 'Saldo credor a transportar para o período seguinte referente ao ICMS Diferencial ' |
||
93 | .'de Alíquota da UF de Origem/Destino', |
||
94 | 'format' => '15v2' |
||
95 | ], |
||
96 | 'DEB_ESP_DIFAL' => [ |
||
97 | 'type' => 'numeric', |
||
98 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
99 | 'required' => true, |
||
100 | 'info' => 'Valores recolhidos ou a recolher, extra- apuração - ICMS Diferencial de Alíquota ' |
||
101 | .'da UF de Origem/Destino.', |
||
102 | 'format' => '15v2' |
||
103 | ], |
||
104 | 'VL_SLD_CRED_ANT_FCP' => [ |
||
105 | 'type' => 'numeric', |
||
106 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
107 | 'required' => true, |
||
108 | 'info' => 'Valor do "Saldo credor de período anterior – FCP"', |
||
109 | 'format' => '15v2' |
||
110 | ], |
||
111 | 'VL_TOT_DEB_FCP' => [ |
||
112 | 'type' => 'numeric', |
||
113 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
114 | 'required' => true, |
||
115 | 'info' => 'Valor total dos débitos FCP por "Saídas e prestações”', |
||
116 | 'format' => '15v2' |
||
117 | ], |
||
118 | 'VL_OUT_DEB_FCP' => [ |
||
119 | 'type' => 'numeric', |
||
120 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
121 | 'required' => true, |
||
122 | 'info' => 'Valor total dos ajustes "Outros débitos FCP" e “Estorno de créditos FCP”', |
||
123 | 'format' => '15v2' |
||
124 | ], |
||
125 | 'VL_TOT_CRED_FCP' => [ |
||
126 | 'type' => 'numeric', |
||
127 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
128 | 'required' => true, |
||
129 | 'info' => 'Valor total dos créditos FCP por Entradas', |
||
130 | 'format' => '15v2' |
||
131 | ], |
||
132 | 'VL_OUT_CRED_FCP' => [ |
||
133 | 'type' => 'numeric', |
||
134 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
135 | 'required' => true, |
||
136 | 'info' => 'Valor total de Ajustes "Outros créditos FCP" e “Estorno de débitos FCP”', |
||
137 | 'format' => '15v2' |
||
138 | ], |
||
139 | 'VL_SLD_DEV_ANT_FCP' => [ |
||
140 | 'type' => 'numeric', |
||
141 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
142 | 'required' => true, |
||
143 | 'info' => 'Valor total de Saldo devedor FCP antes das deduções', |
||
144 | 'format' => '15v2' |
||
145 | ], |
||
146 | 'VL_DEDUCOES_FCP' => [ |
||
147 | 'type' => 'numeric', |
||
148 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
149 | 'required' => true, |
||
150 | 'info' => 'Valor total das deduções "FCP"', |
||
151 | 'format' => '15v2' |
||
152 | ], |
||
153 | 'VL_RECOL_FCP' => [ |
||
154 | 'type' => 'numeric', |
||
155 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
156 | 'required' => true, |
||
157 | 'info' => 'Valor recolhido ou a recolher referente ao FCP (18–19)', |
||
158 | 'format' => '15v2' |
||
159 | ], |
||
160 | 'VL_SLD_CRED_TRANSPORTAR_FCP' => [ |
||
161 | 'type' => 'numeric', |
||
162 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
163 | 'required' => true, |
||
164 | 'info' => 'Saldo credor a transportar para o período seguinte referente ao FCP', |
||
165 | 'format' => '15v2' |
||
166 | ], |
||
167 | 'DEB_ESP_FCP' => [ |
||
168 | 'type' => 'numeric', |
||
169 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
170 | 'required' => true, |
||
171 | 'info' => 'Valores recolhidos ou a recolher, extra- apuração - FCP', |
||
172 | 'format' => '15v2' |
||
173 | ] |
||
174 | ]; |
||
175 | |||
176 | /** |
||
177 | * Constructor |
||
178 | * @param \stdClass $std |
||
179 | */ |
||
180 | public function __construct(\stdClass $std) |
||
186 | |||
187 | public function postValidation() |
||
276 | } |
||
277 |
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.