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 E520 extends Element implements ElementInterface |
||
10 | { |
||
11 | const REG = 'E520'; |
||
12 | const LEVEL = 3; |
||
13 | const PARENT = 'E500'; |
||
14 | |||
15 | protected $parameters = [ |
||
16 | 'VL_SD_ANT_IPI' => [ |
||
17 | 'type' => 'numeric', |
||
18 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
19 | 'required' => true, |
||
20 | 'info' => 'Saldo credor do IPI transferido do período anterior', |
||
21 | 'format' => '15v2' |
||
22 | ], |
||
23 | 'VL_DEB_IPI' => [ |
||
24 | 'type' => 'numeric', |
||
25 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
26 | 'required' => true, |
||
27 | 'info' => 'Valor total dos débitos por "Saídas com débito do imposto"', |
||
28 | 'format' => '15v2' |
||
29 | ], |
||
30 | 'VL_CRED_IPI' => [ |
||
31 | 'type' => 'numeric', |
||
32 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
33 | 'required' => true, |
||
34 | 'info' => 'Valor total dos créditos por "Entradas e aquisições com crédito do imposto"', |
||
35 | 'format' => '15v2' |
||
36 | ], |
||
37 | 'VL_OD_IPI' => [ |
||
38 | 'type' => 'numeric', |
||
39 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
40 | 'required' => true, |
||
41 | 'info' => 'Valor de "Outros débitos" do IPI (inclusive estornos de crédito)', |
||
42 | 'format' => '15v2' |
||
43 | ], |
||
44 | 'VL_OC_IPI' => [ |
||
45 | 'type' => 'numeric', |
||
46 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
47 | 'required' => true, |
||
48 | 'info' => 'Valor de "Outros créditos" do IPI (inclusive estornos de débitos)', |
||
49 | 'format' => '15v2' |
||
50 | ], |
||
51 | 'VL_SC_IPI' => [ |
||
52 | 'type' => 'numeric', |
||
53 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
54 | 'required' => true, |
||
55 | 'info' => 'Valor do saldo credor do IPI a transportar para o período seguinte', |
||
56 | 'format' => '15v2' |
||
57 | ], |
||
58 | 'VL_SD_IPI' => [ |
||
59 | 'type' => 'numeric', |
||
60 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
61 | 'required' => true, |
||
62 | 'info' => 'Valor do saldo devedor do IPI a recolher', |
||
63 | 'format' => '15v2' |
||
64 | ] |
||
65 | ]; |
||
66 | |||
67 | /** |
||
68 | * Constructor |
||
69 | * @param \stdClass $std |
||
70 | */ |
||
71 | public function __construct(\stdClass $std) |
||
77 | |||
78 | public function postValidation() |
||
114 | } |
||
115 |
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.