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 C381 extends Element implements ElementInterface |
|
|
|||
10 | { |
||
11 | const REG = 'C381'; |
||
12 | const LEVEL = 4; |
||
13 | const PARENT = 'C380'; |
||
14 | |||
15 | protected $parameters = [ |
||
16 | 'CST_PIS' => [ |
||
17 | 'type' => 'numeric', |
||
18 | 'regex' => '^(\d{2})$', |
||
19 | 'required' => false, |
||
20 | 'info' => 'Código da Situação Tributária referente ao PIS/PASEP', |
||
21 | 'format' => '' |
||
22 | ], |
||
23 | 'COD_ITEM' => [ |
||
24 | 'type' => 'string', |
||
25 | 'regex' => '^.{0,60}$', |
||
26 | 'required' => false, |
||
27 | 'info' => 'Código do item (campo 02 do Registro 0200)', |
||
28 | 'format' => '' |
||
29 | ], |
||
30 | 'VL_ITEM' => [ |
||
31 | 'type' => 'numeric', |
||
32 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
33 | 'required' => false, |
||
34 | 'info' => 'Valor total dos itens', |
||
35 | 'format' => '15v2' |
||
36 | ], |
||
37 | 'VL_BC_PIS' => [ |
||
38 | 'type' => 'numeric', |
||
39 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
40 | 'required' => false, |
||
41 | 'info' => 'Valor da base de cálculo do PIS/PASEP', |
||
42 | 'format' => '15v2' |
||
43 | ], |
||
44 | 'ALIQ_PIS' => [ |
||
45 | 'type' => 'numeric', |
||
46 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
47 | 'required' => false, |
||
48 | 'info' => 'Alíquota do PIS/PASEP (em percentual)', |
||
49 | 'format' => '8v4' |
||
50 | ], |
||
51 | 'QUANT_BC_PIS' => [ |
||
52 | 'type' => 'numeric', |
||
53 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
54 | 'required' => false, |
||
55 | 'info' => 'Quantidade – Base de cálculo do PIS/PASEP', |
||
56 | 'format' => '15v3' |
||
57 | ], |
||
58 | 'ALIQ_PIS_QUANT' => [ |
||
59 | 'type' => 'numeric', |
||
60 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
61 | 'required' => false, |
||
62 | 'info' => 'Alíquota do PIS/PASEP (em reais)', |
||
63 | 'format' => '15v4' |
||
64 | ], |
||
65 | 'VL_PIS' => [ |
||
66 | 'type' => 'numeric', |
||
67 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
68 | 'required' => false, |
||
69 | 'info' => 'Valor do PIS/PASEP', |
||
70 | 'format' => '15v2' |
||
71 | ], |
||
72 | 'COD_CTA' => [ |
||
73 | 'type' => 'string', |
||
74 | 'regex' => '^.{0,255}$', |
||
75 | 'required' => false, |
||
76 | 'info' => 'Código da conta analítica contábil debitada/creditada', |
||
77 | 'format' => '' |
||
78 | ], |
||
79 | |||
80 | ]; |
||
81 | |||
82 | /** |
||
83 | * Constructor |
||
84 | * @param \stdClass $std |
||
85 | */ |
||
86 | public function __construct(\stdClass $std) |
||
91 | } |
||
92 |
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.