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 B035 extends Element implements ElementInterface |
|
|
|||
10 | { |
||
11 | const REG = 'B035'; |
||
12 | const LEVEL = 3; |
||
13 | const PARENT = 'B030'; |
||
14 | |||
15 | protected $parameters = [ |
||
16 | 'VL_CONT_P' => [ |
||
17 | 'type' => 'numeric', |
||
18 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
19 | 'required' => true, |
||
20 | 'info' => 'Parcela correspondente ao "V alor Contábil" referente à combinação ' |
||
21 | .'da alíquota e item da lista', |
||
22 | 'format' => '15v2' |
||
23 | ], |
||
24 | 'VL_BC_ISS_P' => [ |
||
25 | 'type' => 'numeric', |
||
26 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
27 | 'required' => true, |
||
28 | 'info' => 'Parcela correspondente ao "Valor da base de cálculo do ISS" referente ' |
||
29 | .'à combinação da alíquota e item da lista', |
||
30 | 'format' => '15v2' |
||
31 | ], |
||
32 | 'ALIQ_ISS' => [ |
||
33 | 'type' => 'integer', |
||
34 | 'regex' => '^[0-5]{1}$', |
||
35 | 'required' => true, |
||
36 | 'info' => 'Alíquota do ISS', |
||
37 | 'format' => '' |
||
38 | ], |
||
39 | 'VL_ISS_P' => [ |
||
40 | 'type' => 'numeric', |
||
41 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
42 | 'required' => true, |
||
43 | 'info' => 'Parcela correspondente ao "Valor do ISS" referente à combinação da ' |
||
44 | .'alíquota e item da lista', |
||
45 | 'format' => '15v2' |
||
46 | ], |
||
47 | 'VL_ISNT_ISS_P' => [ |
||
48 | 'type' => 'numeric', |
||
49 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
50 | 'required' => true, |
||
51 | 'info' => 'Parcela correspondente ao "Valor das operações isentas ou não-tributadas ' |
||
52 | .'pelo ISS" referente à combinação da alíquota e item da lista', |
||
53 | 'format' => '15v2' |
||
54 | ], |
||
55 | 'COD_SERV' => [ |
||
56 | 'type' => 'string', |
||
57 | 'regex' => '^.{4}$', |
||
58 | 'required' => true, |
||
59 | 'info' => 'Item da lista de serviços, conforme Tabela 4.6.3.', |
||
60 | 'format' => '' |
||
61 | ] |
||
62 | ]; |
||
63 | |||
64 | /** |
||
65 | * Constructor |
||
66 | * @param \stdClass $std |
||
67 | */ |
||
68 | public function __construct(\stdClass $std) |
||
74 | |||
75 | public function postValidation() |
||
89 | } |
||
90 |
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.