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 Z0007 extends Element implements ElementInterface |
|
|
|||
14 | { |
||
15 | const REG = '0007'; |
||
16 | const LEVEL = 2; |
||
17 | const PARENT = '0001'; |
||
18 | |||
19 | protected $parameters = [ |
||
20 | 'cod_ent_ref' => [ |
||
21 | 'type' => 'string', |
||
22 | 'regex' => '^[A-Za-z0-9]{2}$', |
||
23 | 'required' => false, |
||
24 | 'info' => 'Código da instituição responsável pela administração docadastro.', |
||
25 | 'format' => '' |
||
26 | ], |
||
27 | 'cod_inscr' => [ |
||
28 | 'type' => 'string', |
||
29 | 'regex' => '^.{1,25}$', |
||
30 | 'required' => false, |
||
31 | 'info' => 'Código cadastral da pessoa jurídica na instituição identificada no campo COD_ENT_REF.', |
||
32 | 'format' => '' |
||
33 | ], |
||
34 | ]; |
||
35 | |||
36 | /** |
||
37 | * Constructor |
||
38 | * @param \stdClass $std |
||
39 | */ |
||
40 | public function __construct(\stdClass $std) |
||
46 | } |
||
47 |
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.