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 K115 extends Element implements ElementInterface |
|
|
|||
14 | { |
||
15 | const REG = 'K115'; |
||
16 | const LEVEL = 5; |
||
17 | const PARENT = ''; |
||
18 | |||
19 | protected $parameters = [ |
||
20 | 'emp_cod_part' => [ |
||
21 | 'type' => 'numeric', |
||
22 | 'regex' => '^[0-9]{4}$', |
||
23 | 'required' => true, |
||
24 | 'info' => 'Código da empresa envolvida na operação.', |
||
25 | 'format' => '' |
||
26 | ], |
||
27 | 'evento' => [ |
||
28 | 'type' => 'numeric', |
||
29 | 'regex' => '^(1|2|3)$', |
||
30 | 'required' => true, |
||
31 | 'info' => 'Condição da empresa relacionada à operação:' |
||
32 | .' 1 – Sucessora;' |
||
33 | .' 2 – Adquirente;' |
||
34 | .' 3 – Alienante.', |
||
35 | 'format' => '' |
||
36 | ], |
||
37 | 'per_evt' => [ |
||
38 | 'type' => 'numeric', |
||
39 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
40 | 'required' => true, |
||
41 | 'info' => 'Percentual da empresa participante envolvida na operação.', |
||
42 | 'format' => '8v4' |
||
43 | ] |
||
44 | ]; |
||
45 | |||
46 | /** |
||
47 | * Constructor |
||
48 | * @param \stdClass $std |
||
49 | */ |
||
50 | 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.