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 I355 extends Element implements ElementInterface |
|
|
|||
16 | { |
||
17 | const REG = 'I355'; |
||
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 de resultado.', |
||
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 | 'vl_cta' => [ |
||
37 | 'type' => 'string', |
||
38 | 'regex' => '^[0-9]{19}$', |
||
39 | 'required' => true, |
||
40 | 'info' => 'Valor do saldo final antes do lançamento de encerramento.', |
||
41 | 'format' => '' |
||
42 | ], |
||
43 | 'ind_dc' => [ |
||
44 | 'type' => 'string', |
||
45 | 'regex' => '^(D|C)$', |
||
46 | 'required' => true, |
||
47 | 'info' => 'Indicador da situação do saldo final: D - Devedor; C - Credor.', |
||
48 | 'format' => '' |
||
49 | ], |
||
50 | 'vl_cta_mf' => [ |
||
51 | 'type' => 'string', |
||
52 | 'regex' => '^[0-9]{19}$', |
||
53 | 'required' => false, |
||
54 | 'info' => 'Valor do saldo final antes do lançamento de encerramento em moeda funcional,' |
||
55 | . ' convertido para reais.', |
||
56 | 'format' => '' |
||
57 | ], |
||
58 | 'ind_dc_mf' => [ |
||
59 | 'type' => 'string', |
||
60 | 'regex' => '^(D|C)$', |
||
61 | 'required' => false, |
||
62 | 'info' => 'Indicador da situação do saldo final em moeda funcional: D - Devedor; C - Credor.', |
||
63 | 'format' => '' |
||
64 | ] |
||
65 | ]; |
||
66 | |||
67 | /** |
||
68 | * Constructor |
||
69 | * @param \stdClass $std |
||
70 | */ |
||
71 | 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.