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 J935 extends Element implements ElementInterface |
|
|
|||
16 | { |
||
17 | const REG = 'J935'; |
||
18 | const LEVEL = 3; |
||
19 | const PARENT = ''; |
||
20 | |||
21 | protected $parameters = [ |
||
22 | 'ni_cpf_cnpj' => [ |
||
23 | 'type' => 'numeric', |
||
24 | 'regex' => '^[0-9]$', |
||
25 | 'required' => true, |
||
26 | 'info' => 'CPF do auditor independente/CNPJ da pessoa jurídica de auditoria independente.', |
||
27 | 'format' => '' |
||
28 | ], |
||
29 | 'nome_auditor_firma' => [ |
||
30 | 'type' => 'string', |
||
31 | 'regex' => '^[A-Za-z]$', |
||
32 | 'required' => true, |
||
33 | 'info' => 'Nome do auditor independente ou pessoa jurídica de auditoria independente.', |
||
34 | 'format' => '' |
||
35 | ], |
||
36 | 'cod_assin_t' => [ |
||
37 | 'type' => 'string', |
||
38 | 'regex' => '^[A-Za-z0-9]{3}$', |
||
39 | 'required' => false, |
||
40 | 'info' => 'Registro do auditor independente na CVM.', |
||
41 | 'format' => '' |
||
42 | ] |
||
43 | ]; |
||
44 | |||
45 | /** |
||
46 | * Constructor |
||
47 | * @param \stdClass $std |
||
48 | */ |
||
49 | public function __construct(\stdClass $std) |
||
55 | } |
||
56 |
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.