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 C175 extends Element implements ElementInterface |
||
10 | { |
||
11 | const REG = 'C175'; |
||
12 | const LEVEL = 4; |
||
13 | const PARENT = 'C170'; |
||
14 | |||
15 | protected $parameters = [ |
||
16 | 'CFOP' => [ |
||
17 | 'type' => 'numeric', |
||
18 | 'regex' => '^(\d{4})$', |
||
19 | 'required' => false, |
||
20 | 'info' => 'Código fiscal de operação e prestação', |
||
21 | 'format' => '' |
||
22 | ], |
||
23 | 'VL_OPR' => [ |
||
24 | 'type' => 'numeric', |
||
25 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
26 | 'required' => false, |
||
27 | 'info' => 'Valor da operação na combinação de CFOP, CST e alíquotas, |
||
28 | correspondente ao somatório do valor das mercadorias e produtos |
||
29 | constantes no documento.', |
||
30 | 'format' => '15v2' |
||
31 | ], |
||
32 | 'VL_DESC' => [ |
||
33 | 'type' => 'numeric', |
||
34 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
35 | 'required' => false, |
||
36 | 'info' => 'Valor do desconto comercial / exclusão da base de cálculo do PIS/PASEP e da COFINS', |
||
37 | 'format' => '15v2' |
||
38 | ], |
||
39 | 'CST_PIS' => [ |
||
40 | 'type' => 'numeric', |
||
41 | 'regex' => '^((0[1-9])|49|99)$', |
||
42 | 'required' => false, |
||
43 | 'info' => 'Código da Situação Tributária referente ao PIS/PASEP, conforme a Tabela indicada no item 4.3.3.', |
||
44 | 'format' => '' |
||
45 | ], |
||
46 | 'VL_BC_PIS' => [ |
||
47 | 'type' => 'numeric', |
||
48 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
49 | 'required' => false, |
||
50 | 'info' => 'Valor da base de cálculo do PIS/PASEP (em valor)', |
||
51 | 'format' => '15v2' |
||
52 | ], |
||
53 | 'ALIQ_PIS' => [ |
||
54 | 'type' => 'numeric', |
||
55 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
56 | 'required' => false, |
||
57 | 'info' => 'Alíquota do PIS/PASEP (em percentual)', |
||
58 | 'format' => '8v4' |
||
59 | ], |
||
60 | 'QUANT_BC_PIS' => [ |
||
61 | 'type' => 'numeric', |
||
62 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
63 | 'required' => false, |
||
64 | 'info' => 'Base de cálculo PIS/PASEP (em quantidade)', |
||
65 | 'format' => '15v3' |
||
66 | ], |
||
67 | 'ALIQ_PIS_QUANT' => [ |
||
68 | 'type' => 'numeric', |
||
69 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
70 | 'required' => false, |
||
71 | 'info' => 'Alíquota do PIS (em reais)', |
||
72 | 'format' => '15v4' |
||
73 | ], |
||
74 | 'VL_PIS' => [ |
||
75 | 'type' => 'numeric', |
||
76 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
77 | 'required' => false, |
||
78 | 'info' => 'Valor do PIS/PASEP', |
||
79 | 'format' => '15v2' |
||
80 | ], |
||
81 | 'CST_COFINS' => [ |
||
82 | 'type' => 'numeric', |
||
83 | 'regex' => '^(\d{2})$', |
||
84 | 'required' => false, |
||
85 | 'info' => 'Código da Situação Tributária referente a Cofins, conforme a Tabela indicada no item 4.3.4.', |
||
86 | 'format' => '' |
||
87 | ], |
||
88 | 'VL_BC_COFINS' => [ |
||
89 | 'type' => 'numeric', |
||
90 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
91 | 'required' => false, |
||
92 | 'info' => 'Valor da base de cálculo da Cofins', |
||
93 | 'format' => '15v2' |
||
94 | ], |
||
95 | 'ALIQ_COFINS' => [ |
||
96 | 'type' => 'numeric', |
||
97 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
98 | 'required' => false, |
||
99 | 'info' => 'Alíquota da Cofins (em percentual)', |
||
100 | 'format' => '8v4' |
||
101 | ], |
||
102 | 'QUANT_BC_COFINS' => [ |
||
103 | 'type' => 'numeric', |
||
104 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
105 | 'required' => false, |
||
106 | 'info' => 'Base de cálculo COFINS (em quantidade)', |
||
107 | 'format' => '15v3' |
||
108 | ], |
||
109 | 'ALIQ_COFINS_QUANT' => [ |
||
110 | 'type' => 'numeric', |
||
111 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
112 | 'required' => false, |
||
113 | 'info' => 'Alíquota da COFINS (em reais)', |
||
114 | 'format' => '15v4' |
||
115 | ], |
||
116 | 'VL_COFINS' => [ |
||
117 | 'type' => 'numeric', |
||
118 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
119 | 'required' => false, |
||
120 | 'info' => 'Valor da Cofins', |
||
121 | 'format' => '15v2' |
||
122 | ], |
||
123 | 'COD_CTA' => [ |
||
124 | 'type' => 'string', |
||
125 | 'regex' => '^.{0,255}$', |
||
126 | 'required' => false, |
||
127 | 'info' => 'Código da conta analítica contábil debitada/creditada', |
||
128 | 'format' => '' |
||
129 | ], |
||
130 | 'INFO_COMPL' => [ |
||
131 | 'type' => 'string', |
||
132 | 'regex' => '^(.*)$', |
||
133 | 'required' => false, |
||
134 | 'info' => 'Informação complementar', |
||
135 | 'format' => '' |
||
136 | ], |
||
137 | |||
138 | ]; |
||
139 | |||
140 | /** |
||
141 | * Constructor |
||
142 | * @param \stdClass $std |
||
143 | */ |
||
144 | public function __construct(\stdClass $std) |
||
150 | |||
151 | public function postValidation() |
||
172 | } |
||
173 |
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.