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 Z1110 extends Element implements ElementInterface |
|
|
|||
10 | { |
||
11 | const REG = '1110'; |
||
12 | const LEVEL = 4; |
||
13 | const PARENT = '1105'; |
||
14 | |||
15 | protected $parameters = [ |
||
16 | 'COD_PART' => [ |
||
17 | 'type' => 'string', |
||
18 | 'regex' => '^.{1,60}$', |
||
19 | 'required' => true, |
||
20 | 'info' => 'Código do participante-Fornecedor da Mercadoria destinada ' |
||
21 | .'à exportação (campo 02 do Registro 0150)', |
||
22 | 'format' => '' |
||
23 | ], |
||
24 | 'COD_MOD' => [ |
||
25 | 'type' => 'string', |
||
26 | 'regex' => '^[0][1|4]|[1][B]|[5][5]$', |
||
27 | 'required' => true, |
||
28 | 'info' => 'Código do documento fiscal, conforme a Tabela 4.1.1', |
||
29 | 'format' => '' |
||
30 | ], |
||
31 | 'SER' => [ |
||
32 | 'type' => 'string', |
||
33 | 'regex' => '^.{1,4}$', |
||
34 | 'required' => false, |
||
35 | 'info' => 'Série do documento fiscal recebido com fins específicos de exportação.', |
||
36 | 'format' => '' |
||
37 | ], |
||
38 | 'NUM_DOC' => [ |
||
39 | 'type' => 'integer', |
||
40 | 'regex' => '^[1-9]\d{0,8}$', |
||
41 | 'required' => true, |
||
42 | 'info' => 'Número do documento fiscal recebido com fins específicos de exportação.', |
||
43 | 'format' => '' |
||
44 | ], |
||
45 | 'DT_DOC' => [ |
||
46 | 'type' => 'integer', |
||
47 | 'regex' => '^(0[1-9]|[1-2][0-9]|31(?!(?:0[2469]|11))|30(?!02))(0[1-9]|1[0-2])([12]\d{3})$', |
||
48 | 'required' => true, |
||
49 | 'info' => 'Data da emissão do documento fiscal recebido com fins específicos de exportação', |
||
50 | 'format' => '' |
||
51 | ], |
||
52 | 'CHV_NFE' => [ |
||
53 | 'type' => 'numeric', |
||
54 | 'regex' => '^([0-9]{44})?$', |
||
55 | 'required' => false, |
||
56 | 'info' => 'Chave da Nota Fiscal Eletrônica', |
||
57 | 'format' => '' |
||
58 | ], |
||
59 | 'NR_MEMO' => [ |
||
60 | 'type' => 'integer', |
||
61 | 'regex' => '^\d+$', |
||
62 | 'required' => false, |
||
63 | 'info' => 'Número do Memorando de Exportação', |
||
64 | 'format' => '' |
||
65 | ], |
||
66 | 'QTD' => [ |
||
67 | 'type' => 'integer', |
||
68 | 'regex' => '^[1-9](\d?)+$', |
||
69 | 'required' => true, |
||
70 | 'info' => 'Quantidade do item efetivamente exportado.', |
||
71 | 'format' => '' |
||
72 | ], |
||
73 | 'UNID' => [ |
||
74 | 'type' => 'string', |
||
75 | 'regex' => '^.{1,6}$', |
||
76 | 'required' => true, |
||
77 | 'info' => 'Unidade do item (Campo 02 do registro 0190)', |
||
78 | 'format' => '' |
||
79 | ] |
||
80 | ]; |
||
81 | |||
82 | /** |
||
83 | * Constructor |
||
84 | * @param \stdClass $std |
||
85 | */ |
||
86 | public function __construct(\stdClass $std) |
||
91 | } |
||
92 |
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.