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 |
||
13 | View Code Duplication | class K200 extends Element implements ElementInterface |
|
|
|||
14 | { |
||
15 | const REG = 'K200'; |
||
16 | const LEVEL = 3; |
||
17 | const PARENT = ''; |
||
18 | |||
19 | protected $parameters = [ |
||
20 | 'cod_nat' => [ |
||
21 | 'type' => 'string', |
||
22 | 'regex' => '^[A-Za-z0-9]{2}$', |
||
23 | 'required' => true, |
||
24 | 'info' => 'Código da natureza da conta/grupo de contas, conforme tabela publicada pelo Sped.', |
||
25 | 'format' => '' |
||
26 | ], |
||
27 | 'ind_cta' => [ |
||
28 | 'type' => 'string', |
||
29 | 'regex' => '^(S|A)$', |
||
30 | 'required' => true, |
||
31 | 'info' => 'Indicador do tipo de conta:' |
||
32 | . ' S - Sintética (grupo de contas);' |
||
33 | . ' A - Analítica (conta).', |
||
34 | 'format' => '' |
||
35 | ], |
||
36 | 'nivel' => [ |
||
37 | 'type' => 'numeric', |
||
38 | 'regex' => '^[0-9]$', |
||
39 | 'required' => true, |
||
40 | 'info' => 'Nível da conta.', |
||
41 | 'format' => '' |
||
42 | ], |
||
43 | 'cod_cta' => [ |
||
44 | 'type' => 'string', |
||
45 | 'regex' => '^[A-Za-z0-9]$', |
||
46 | 'required' => true, |
||
47 | 'info' => 'Código da conta.', |
||
48 | 'format' => '' |
||
49 | ], |
||
50 | 'cod_cta_sup' => [ |
||
51 | 'type' => 'string', |
||
52 | 'regex' => '^[A-Za-z0-9]$', |
||
53 | 'required' => false, |
||
54 | 'info' => 'Código da conta superior', |
||
55 | 'format' => '' |
||
56 | ], |
||
57 | 'cta' => [ |
||
58 | 'type' => 'string', |
||
59 | 'regex' => '^[A-Za-z0-9]$', |
||
60 | 'required' => true, |
||
61 | 'info' => 'Nome da conta.', |
||
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.