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 M300 extends Element implements ElementInterface |
|
|
|||
10 | { |
||
11 | const REG = 'M300'; |
||
12 | const LEVEL = 2; |
||
13 | const PARENT = 'M001'; |
||
14 | |||
15 | protected $parameters = [ |
||
16 | 'COD_CONT' => [ |
||
17 | 'type' => 'string', |
||
18 | 'regex' => '^.{0,2}$', |
||
19 | 'required' => false, |
||
20 | 'info' => 'Código da contribuição social diferida em períodos anteriores, conforme a Tabela ' . |
||
21 | '4.3.5. ', |
||
22 | 'format' => '' |
||
23 | ], |
||
24 | 'VL_CONT_APUR_DIFER' => [ |
||
25 | 'type' => 'numeric', |
||
26 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
27 | 'required' => false, |
||
28 | 'info' => 'Valor da Contribuição Apurada, diferida em períodos anteriores. ', |
||
29 | 'format' => '15v2' |
||
30 | ], |
||
31 | 'NAT_CRED_DESC' => [ |
||
32 | 'type' => 'string', |
||
33 | 'regex' => '^(1|2|3|4)$', |
||
34 | 'required' => false, |
||
35 | 'info' => 'Natureza do Crédito Diferido, vinculado à receita tributada no mercado interno, a ' . |
||
36 | 'descontar ' . |
||
37 | ' 01 – Crédito a Alíquota Básica ' . |
||
38 | ' 02 – Crédito a Alíquota Diferenciada ' . |
||
39 | ' 03 – Crédito a Alíquota por Unidade de Produto ' . |
||
40 | ' 04 – Crédito Presumido da Agroindústria. ', |
||
41 | 'format' => '' |
||
42 | ], |
||
43 | 'VL_CRED_DESC_DIFER' => [ |
||
44 | 'type' => 'numeric', |
||
45 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
46 | 'required' => false, |
||
47 | 'info' => 'Valor do Crédito a Descontar vinculado à contribuição diferida. ', |
||
48 | 'format' => '15v2' |
||
49 | ], |
||
50 | 'VL_CONT_DIFER_ANT' => [ |
||
51 | 'type' => 'numeric', |
||
52 | 'regex' => '^(3)$', |
||
53 | 'required' => false, |
||
54 | 'info' => 'Valor da Contribuição a Recolher, diferida em períodos anteriores (Campo 03 – Campo ' . |
||
55 | '05) ', |
||
56 | 'format' => '15v2' |
||
57 | ], |
||
58 | 'PER_APUR' => [ |
||
59 | 'type' => 'numeric', |
||
60 | 'regex' => '^(\d{6})$', |
||
61 | 'required' => false, |
||
62 | 'info' => 'Período de apuração da contribuição social e dos créditos diferidos (MMAAAA) ', |
||
63 | 'format' => '' |
||
64 | ], |
||
65 | 'DT_RECEB' => [ |
||
66 | 'type' => 'string', |
||
67 | 'regex' => '^(0[1-9]|[1-2][0-9]|31(?!(?:0[2469]|11))|30(?!02))(0[1-9]|1[0-2])([12]\d{3})$', |
||
68 | 'required' => false, |
||
69 | 'info' => 'Data de recebimento da receita, objeto de diferimento ', |
||
70 | 'format' => '' |
||
71 | ], |
||
72 | |||
73 | ]; |
||
74 | |||
75 | /** |
||
76 | * Constructor |
||
77 | * @param \stdClass $std |
||
78 | */ |
||
79 | public function __construct(\stdClass $std) |
||
84 | } |
||
85 |
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.