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 |
||
15 | View Code Duplication | class I310 extends Element implements ElementInterface |
|
|
|||
16 | { |
||
17 | const REG = 'I310'; |
||
18 | const LEVEL = 4; |
||
19 | const PARENT = ''; |
||
20 | |||
21 | protected $parameters = [ |
||
22 | 'cod_cta' => [ |
||
23 | 'type' => 'string', |
||
24 | 'regex' => '^[A-Za-z0-9]$', |
||
25 | 'required' => true, |
||
26 | 'info' => 'Código da conta analítica debitada/creditada.', |
||
27 | 'format' => '' |
||
28 | ], |
||
29 | 'cod_ccus' => [ |
||
30 | 'type' => 'string', |
||
31 | 'regex' => '^[A-Za-z0-9]$', |
||
32 | 'required' => false, |
||
33 | 'info' => 'Código do centro de custos.', |
||
34 | 'format' => '' |
||
35 | ], |
||
36 | 'val_debd' => [ |
||
37 | 'type' => 'string', |
||
38 | 'regex' => '^[0-9]{19}$', |
||
39 | 'required' => true, |
||
40 | 'info' => 'Total dos débitos do dia.', |
||
41 | 'format' => '' |
||
42 | ], |
||
43 | 'val_credd' => [ |
||
44 | 'type' => 'string', |
||
45 | 'regex' => '^[0-9]{19}$', |
||
46 | 'required' => true, |
||
47 | 'info' => 'Total dos créditos do dia.', |
||
48 | 'format' => '' |
||
49 | ], |
||
50 | 'val_deb_mf' => [ |
||
51 | 'type' => 'string', |
||
52 | 'regex' => '^[0-9]{19}$', |
||
53 | 'required' => false, |
||
54 | 'info' => 'Total dos débitos do dia em moeda funcional, convertido para reais.', |
||
55 | 'format' => '' |
||
56 | ], |
||
57 | 'val_cred_mf' => [ |
||
58 | 'type' => 'string', |
||
59 | 'regex' => '^[0-9]{19}$', |
||
60 | 'required' => false, |
||
61 | 'info' => 'Total dos créditos do dia em moeda funcional, convertido para reais.', |
||
62 | 'format' => '' |
||
63 | ] |
||
64 | ]; |
||
65 | |||
66 | /** |
||
67 | * Constructor |
||
68 | * @param \stdClass $std |
||
69 | */ |
||
70 | public function __construct(\stdClass $std) |
||
76 | } |
||
77 |
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.