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 D695 extends Element implements ElementInterface |
|
|
|||
10 | { |
||
11 | const REG = 'D695'; |
||
12 | const LEVEL = 2; |
||
13 | const PARENT = ''; |
||
14 | |||
15 | protected $parameters = [ |
||
16 | 'COD_MOD' => [ |
||
17 | 'type' => 'string', |
||
18 | 'regex' => '^.{2}$', |
||
19 | 'required' => true, |
||
20 | 'info' => 'Código do modelo do documento fiscal, conforme a Tabela 4.1.1.', |
||
21 | 'format' => '' |
||
22 | ], |
||
23 | 'SER' => [ |
||
24 | 'type' => 'string', |
||
25 | 'regex' => '^.{1,4}$', |
||
26 | 'required' => true, |
||
27 | 'info' => 'Série do documento fiscal ', |
||
28 | 'format' => '' |
||
29 | ], |
||
30 | 'NRO_ORD_INI' => [ |
||
31 | 'type' => 'numeric', |
||
32 | 'regex' => '^(\d{9})$', |
||
33 | 'required' => true, |
||
34 | 'info' => 'Número de ordem inicial ', |
||
35 | 'format' => '' |
||
36 | ], |
||
37 | 'NRO_ORD_FIN' => [ |
||
38 | 'type' => 'numeric', |
||
39 | 'regex' => '^(\d{9})$', |
||
40 | 'required' => true, |
||
41 | 'info' => 'Número de ordem final ', |
||
42 | 'format' => '' |
||
43 | ], |
||
44 | 'DT_DOC_INI' => [ |
||
45 | 'type' => 'numeric', |
||
46 | 'regex' => '^(\d{8})$', |
||
47 | 'required' => true, |
||
48 | 'info' => 'Data de emissão inicial dos documentos ', |
||
49 | 'format' => '' |
||
50 | ], |
||
51 | 'DT_DOC_FIN' => [ |
||
52 | 'type' => 'numeric', |
||
53 | 'regex' => '^(\d{8})$', |
||
54 | 'required' => true, |
||
55 | 'info' => 'Data de emissão final dos documentos ', |
||
56 | 'format' => '' |
||
57 | ], |
||
58 | 'NOM_MEST' => [ |
||
59 | 'type' => 'string', |
||
60 | 'regex' => '^.{1,33}$', |
||
61 | 'required' => true, |
||
62 | 'info' => 'Nome do arquivo Mestre de Documento Fiscal', |
||
63 | 'format' => '' |
||
64 | ], |
||
65 | 'CHV_COD_DIG' => [ |
||
66 | 'type' => 'string', |
||
67 | 'regex' => '^.{1,32}$', |
||
68 | 'required' => true, |
||
69 | 'info' => 'Chave de codificação digital do arquivo Mestre de Documento Fiscal', |
||
70 | 'format' => '' |
||
71 | ], |
||
72 | ]; |
||
73 | |||
74 | /** |
||
75 | * Constructor |
||
76 | * @param \stdClass $std |
||
77 | */ |
||
78 | public function __construct(\stdClass $std) |
||
83 | } |
||
84 |
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.