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 E110 extends Element implements ElementInterface |
||
10 | { |
||
11 | const REG = 'E110'; |
||
12 | const LEVEL = 3; |
||
13 | const PARENT = 'E100'; |
||
14 | |||
15 | protected $parameters = [ |
||
16 | 'VL_TOT_DEBITOS' => [ |
||
17 | 'type' => 'numeric', |
||
18 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
19 | 'required' => true, |
||
20 | 'info' => 'Valor total dos débitos por "Saídas e prestações com débito do imposto"', |
||
21 | 'format' => '15v2' |
||
22 | ], |
||
23 | 'VL_AJ_DEBITOS' => [ |
||
24 | 'type' => 'numeric', |
||
25 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
26 | 'required' => true, |
||
27 | 'info' => 'Valor total dos ajustes a débito decorrentes do documento fiscal.', |
||
28 | 'format' => '15v2' |
||
29 | ], |
||
30 | 'VL_TOT_AJ_DEBITOS' => [ |
||
31 | 'type' => 'numeric', |
||
32 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
33 | 'required' => true, |
||
34 | 'info' => 'Valor total de "Ajustes a débito"', |
||
35 | 'format' => '15v2' |
||
36 | ], |
||
37 | 'VL_ESTORNOS_CRED' => [ |
||
38 | 'type' => 'numeric', |
||
39 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
40 | 'required' => true, |
||
41 | 'info' => 'Valor total de Ajustes “Estornos de créditos”', |
||
42 | 'format' => '15v2' |
||
43 | ], |
||
44 | 'VL_TOT_CREDITOS' => [ |
||
45 | 'type' => 'numeric', |
||
46 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
47 | 'required' => true, |
||
48 | 'info' => 'Valor total dos créditos por "Entradas e aquisições com crédito do imposto"', |
||
49 | 'format' => '15v2' |
||
50 | ], |
||
51 | 'VL_AJ_CREDITOS' => [ |
||
52 | 'type' => 'numeric', |
||
53 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
54 | 'required' => true, |
||
55 | 'info' => 'Valor total dos ajustes a crédito decorrentes do documento fiscal.', |
||
56 | 'format' => '15v2' |
||
57 | ], |
||
58 | 'VL_TOT_AJ_CREDITOS' => [ |
||
59 | 'type' => 'numeric', |
||
60 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
61 | 'required' => true, |
||
62 | 'info' => 'Valor total de "Ajustes a crédito"', |
||
63 | 'format' => '15v2' |
||
64 | ], |
||
65 | 'VL_ESTORNOS_DEB' => [ |
||
66 | 'type' => 'numeric', |
||
67 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
68 | 'required' => true, |
||
69 | 'info' => 'Valor total de Ajustes “Estornos de Débitos”', |
||
70 | 'format' => '15v2' |
||
71 | ], |
||
72 | 'VL_SLD_CREDOR_ANT' => [ |
||
73 | 'type' => 'numeric', |
||
74 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
75 | 'required' => true, |
||
76 | 'info' => 'Valor total de "Saldo credor do período anterior"', |
||
77 | 'format' => '15v2' |
||
78 | ], |
||
79 | 'VL_SLD_APURADO' => [ |
||
80 | 'type' => 'numeric', |
||
81 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
82 | 'required' => true, |
||
83 | 'info' => 'Valor do saldo devedor apurado', |
||
84 | 'format' => '15v2' |
||
85 | ], |
||
86 | 'VL_TOT_DED' => [ |
||
87 | 'type' => 'numeric', |
||
88 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
89 | 'required' => true, |
||
90 | 'info' => 'Valor total de "Deduções"', |
||
91 | 'format' => '15v2' |
||
92 | ], |
||
93 | 'VL_ICMS_RECOLHER' => [ |
||
94 | 'type' => 'numeric', |
||
95 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
96 | 'required' => true, |
||
97 | 'info' => 'Valor total de "ICMS a recolher (11-12)', |
||
98 | 'format' => '15v2' |
||
99 | ], |
||
100 | 'VL_SLD_CREDOR_TRANSPORTAR' => [ |
||
101 | 'type' => 'numeric', |
||
102 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
103 | 'required' => true, |
||
104 | 'info' => 'Valor total de "Saldo credor a transportar para o período seguinte”', |
||
105 | 'format' => '15v2' |
||
106 | ], |
||
107 | 'DEB_ESP' => [ |
||
108 | 'type' => 'numeric', |
||
109 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
110 | 'required' => true, |
||
111 | 'info' => 'Valores recolhidos ou a recolher, extra apuração.', |
||
112 | 'format' => '15v2' |
||
113 | ] |
||
114 | ]; |
||
115 | |||
116 | /** |
||
117 | * Constructor |
||
118 | * @param \stdClass $std |
||
119 | */ |
||
120 | public function __construct(\stdClass $std) |
||
126 | |||
127 | public function postValidation() |
||
178 | } |
||
179 |
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.