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 C395 extends Element implements ElementInterface |
|
|
|||
10 | { |
||
11 | const REG = 'C395'; |
||
12 | const LEVEL = 3; |
||
13 | const PARENT = 'C100'; |
||
14 | |||
15 | protected $parameters = [ |
||
16 | 'COD_MOD' => [ |
||
17 | 'type' => 'string', |
||
18 | 'regex' => '^(02|2D|2E|59|60|65)$', |
||
19 | 'required' => false, |
||
20 | 'info' => 'Código do modelo do documento fiscal, conforme a Tabela 4.1.1', |
||
21 | 'format' => '' |
||
22 | ], |
||
23 | 'COD_PART' => [ |
||
24 | 'type' => 'string', |
||
25 | 'regex' => '^.{0,60}$', |
||
26 | 'required' => false, |
||
27 | 'info' => 'Código do participante emitente do documento (campo 02 do Registro 0150).', |
||
28 | 'format' => '' |
||
29 | ], |
||
30 | 'SER' => [ |
||
31 | 'type' => 'string', |
||
32 | 'regex' => '^.{0,3}$', |
||
33 | 'required' => false, |
||
34 | 'info' => 'Série do documento fiscal', |
||
35 | 'format' => '' |
||
36 | ], |
||
37 | 'SUB_SER' => [ |
||
38 | 'type' => 'string', |
||
39 | 'regex' => '^.{0,3}$', |
||
40 | 'required' => false, |
||
41 | 'info' => 'Subsérie do documento fiscal', |
||
42 | 'format' => '' |
||
43 | ], |
||
44 | 'NUM_DOC' => [ |
||
45 | 'type' => 'string', |
||
46 | 'regex' => '^.{0,6}$', |
||
47 | 'required' => false, |
||
48 | 'info' => 'Número do documento fiscal', |
||
49 | 'format' => '' |
||
50 | ], |
||
51 | 'DT_DOC' => [ |
||
52 | 'type' => 'string', |
||
53 | 'regex' => '^(0[1-9]|[1-2][0-9]|31(?!(?:0[2469]|11))|30(?!02))(0[1-9]|1[0-2])([12]\d{3})$', |
||
54 | 'required' => false, |
||
55 | 'info' => 'Data da emissão do documento fiscal', |
||
56 | 'format' => '' |
||
57 | ], |
||
58 | 'VL_DOC' => [ |
||
59 | 'type' => 'numeric', |
||
60 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
61 | 'required' => false, |
||
62 | 'info' => 'Valor total do documento fiscal', |
||
63 | 'format' => '15v2' |
||
64 | ], |
||
65 | |||
66 | ]; |
||
67 | |||
68 | /** |
||
69 | * Constructor |
||
70 | * @param \stdClass $std |
||
71 | */ |
||
72 | public function __construct(\stdClass $std) |
||
77 | } |
||
78 |
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.