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 | View Code Duplication | class Z1960 extends Element implements ElementInterface |
|
|
|||
10 | { |
||
11 | const REG = '1960'; |
||
12 | const LEVEL = 2; |
||
13 | const PARENT = '1001'; |
||
14 | |||
15 | protected $parameters = [ |
||
16 | 'IND_AP' => [ |
||
17 | 'type' => 'integer', |
||
18 | 'regex' => '^\d{2}$', |
||
19 | 'required' => true, |
||
20 | 'info' => 'Indicador da sub-apuração por tipo de benefício (conforme tabela 4.7.1)', |
||
21 | 'format' => '' |
||
22 | ], |
||
23 | 'G1_01' => [ |
||
24 | 'type' => 'numeric', |
||
25 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
26 | 'required' => true, |
||
27 | 'info' => 'Percentual de crédito presumido', |
||
28 | 'format' => '15v2' |
||
29 | ], |
||
30 | 'G1_02' => [ |
||
31 | 'type' => 'numeric', |
||
32 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
33 | 'required' => true, |
||
34 | 'info' => 'Saídas não incentivadas de PI', |
||
35 | 'format' => '15v2' |
||
36 | ], |
||
37 | 'G1_03' => [ |
||
38 | 'type' => 'numeric', |
||
39 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
40 | 'required' => true, |
||
41 | 'info' => 'Saídas incentivadas de PI', |
||
42 | 'format' => '15v2' |
||
43 | ], |
||
44 | 'G1_04' => [ |
||
45 | 'type' => 'numeric', |
||
46 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
47 | 'required' => true, |
||
48 | 'info' => 'Saídas incentivadas de PI para fora do Nordeste', |
||
49 | 'format' => '15v2' |
||
50 | ], |
||
51 | 'G1_05' => [ |
||
52 | 'type' => 'numeric', |
||
53 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
54 | 'required' => true, |
||
55 | 'info' => 'Saldo devedor do ICMS antes das deduções do incentivo', |
||
56 | 'format' => '15v2' |
||
57 | ], |
||
58 | 'G1_06' => [ |
||
59 | 'type' => 'numeric', |
||
60 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
61 | 'required' => true, |
||
62 | 'info' => 'Saldo devedor do ICMS relativo à faixa incentivada de PI', |
||
63 | 'format' => '15v2' |
||
64 | ], |
||
65 | 'G1_07' => [ |
||
66 | 'type' => 'numeric', |
||
67 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
68 | 'required' => true, |
||
69 | 'info' => 'Crédito presumido nas saídas incentivadas de PI para fora do Nordeste', |
||
70 | 'format' => '15v2' |
||
71 | ], |
||
72 | 'G1_08' => [ |
||
73 | 'type' => 'numeric', |
||
74 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
75 | 'required' => true, |
||
76 | 'info' => 'Saldo devedor relativo à faixa incentivada de PI após o ' |
||
77 | .'crédito presumido nas saídas para fora do Nordeste', |
||
78 | 'format' => '15v2' |
||
79 | ], |
||
80 | 'G1_09' => [ |
||
81 | 'type' => 'numeric', |
||
82 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
83 | 'required' => true, |
||
84 | 'info' => 'Crédito presumido', |
||
85 | 'format' => '15v2' |
||
86 | ], |
||
87 | 'G1_10' => [ |
||
88 | 'type' => 'numeric', |
||
89 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
90 | 'required' => true, |
||
91 | 'info' => 'Dedução de incentivo da Indústria (crédito presumido)', |
||
92 | 'format' => '15v2' |
||
93 | ], |
||
94 | 'G1_11' => [ |
||
95 | 'type' => 'numeric', |
||
96 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
97 | 'required' => true, |
||
98 | 'info' => 'Saldo devedor do ICMS após deduções', |
||
99 | 'format' => '15v2' |
||
100 | ] |
||
101 | ]; |
||
102 | |||
103 | /** |
||
104 | * Constructor |
||
105 | * @param \stdClass $std |
||
106 | */ |
||
107 | public function __construct(\stdClass $std) |
||
112 | } |
||
113 |
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.