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 Z1320 extends Element implements ElementInterface |
||
10 | { |
||
11 | const REG = '1320'; |
||
12 | const LEVEL = 4; |
||
13 | const PARENT = '1310'; |
||
14 | |||
15 | protected $parameters = [ |
||
16 | 'NUM_BICO' => [ |
||
17 | 'type' => 'integer', |
||
18 | 'regex' => '^\d+$', |
||
19 | 'required' => true, |
||
20 | 'info' => 'Bico Ligado à Bomba', |
||
21 | 'format' => '' |
||
22 | ], |
||
23 | 'NR_INTERV' => [ |
||
24 | 'type' => 'integer', |
||
25 | 'regex' => '^\d+$', |
||
26 | 'required' => false, |
||
27 | 'info' => 'Número da intervenção', |
||
28 | 'format' => '' |
||
29 | ], |
||
30 | 'MOT_INTERV' => [ |
||
31 | 'type' => 'string', |
||
32 | 'regex' => '^.{1,50}$', |
||
33 | 'required' => false, |
||
34 | 'info' => 'Motivo da Intervenção', |
||
35 | 'format' => '' |
||
36 | ], |
||
37 | 'NOM_INTERV' => [ |
||
38 | 'type' => 'string', |
||
39 | 'regex' => '^.{1,30}$', |
||
40 | 'required' => false, |
||
41 | 'info' => 'Nome do Interventor', |
||
42 | 'format' => '' |
||
43 | ], |
||
44 | 'CNPJ_INTERV' => [ |
||
45 | 'type' => 'integer', |
||
46 | 'regex' => '^[0-9]{14}$', |
||
47 | 'required' => false, |
||
48 | 'info' => 'CNPJ da empresa responsável pela intervenção', |
||
49 | 'format' => '' |
||
50 | ], |
||
51 | 'CPF_INTERV' => [ |
||
52 | 'type' => 'integer', |
||
53 | 'regex' => '^[0-9]{11}$', |
||
54 | 'required' => false, |
||
55 | 'info' => 'CPF do técnico responsável pela intervenção', |
||
56 | 'format' => '' |
||
57 | ], |
||
58 | 'VAL_FECHA' => [ |
||
59 | 'type' => 'numeric', |
||
60 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
61 | 'required' => true, |
||
62 | 'info' => 'Valor da leitura final do contador, no fechamento do bico.', |
||
63 | 'format' => '15v3' |
||
64 | ], |
||
65 | 'VAL_ABERT' => [ |
||
66 | 'type' => 'numeric', |
||
67 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
68 | 'required' => true, |
||
69 | 'info' => 'Valor da leitura inicial do contador, na abertura do bico.', |
||
70 | 'format' => '15v3' |
||
71 | ], |
||
72 | 'VOL_AFERI' => [ |
||
73 | 'type' => 'numeric', |
||
74 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
75 | 'required' => false, |
||
76 | 'info' => 'Aferições da Bomba, em litros', |
||
77 | 'format' => '15v3' |
||
78 | ], |
||
79 | 'VOL_VENDAS' => [ |
||
80 | 'type' => 'numeric', |
||
81 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
82 | 'required' => true, |
||
83 | 'info' => 'Vendas (08 – 09 - 10 ) do bico , em litros', |
||
84 | 'format' => '15v3' |
||
85 | ] |
||
86 | ]; |
||
87 | |||
88 | /** |
||
89 | * Constructor |
||
90 | * @param \stdClass $std |
||
91 | */ |
||
92 | public function __construct(\stdClass $std) |
||
98 | |||
99 | View Code Duplication | public function postValidation() |
|
113 | } |
||
114 |
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.