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 C420 extends Element implements ElementInterface |
|
|
|||
10 | { |
||
11 | const REG = 'C420'; |
||
12 | const LEVEL = 4; |
||
13 | const PARENT = 'C400'; |
||
14 | |||
15 | protected $parameters = [ |
||
16 | 'COD_TOT_PAR' => [ |
||
17 | 'type' => 'string', |
||
18 | 'regex' => '^.{1,7}$', |
||
19 | 'required' => true, |
||
20 | 'info' => 'Código do totalizador, conforme Tabela 4.4.6', |
||
21 | 'format' => '' |
||
22 | ], |
||
23 | 'VLR_ACUM_TOT' => [ |
||
24 | 'type' => 'numeric', |
||
25 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
26 | 'required' => true, |
||
27 | 'info' => 'Valor acumulado no respectiva Redução Z.', |
||
28 | 'format' => '15v2' |
||
29 | ], |
||
30 | 'NR_TOT' => [ |
||
31 | 'type' => 'numeric', |
||
32 | 'regex' => '^(\d{0,2})$', |
||
33 | 'required' => false, |
||
34 | 'info' => 'Número do totalizador quando ocorrer mais de uma situação com a mesma carga tributária efetiva.', |
||
35 | 'format' => '' |
||
36 | ], |
||
37 | 'DESCR_NR_TOT' => [ |
||
38 | 'type' => 'string', |
||
39 | 'regex' => '^(.*)$', |
||
40 | 'required' => false, |
||
41 | 'info' => 'Descrição da situação tributária relativa ao totalizador parcial, quando houver |
||
42 | mais de um com a mesma carga tributária efetiva.', |
||
43 | 'format' => '' |
||
44 | ], |
||
45 | ]; |
||
46 | |||
47 | /** |
||
48 | * Constructor |
||
49 | * @param \stdClass $std |
||
50 | */ |
||
51 | public function __construct(\stdClass $std) |
||
56 | } |
||
57 |
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.