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 Z0145 extends Element implements ElementInterface |
|
|
|
|||
| 10 | { |
||
| 11 | const REG = '0145'; |
||
| 12 | const LEVEL = 3; |
||
| 13 | const PARENT = '0100'; |
||
| 14 | |||
| 15 | protected $parameters = [ |
||
| 16 | 'COD_INC_TRIB' => [ |
||
| 17 | 'type' => 'numeric', |
||
| 18 | 'regex' => '^(1|2)$', |
||
| 19 | 'required' => false, |
||
| 20 | 'info' => 'Código indicador da incidência tributária no período: |
||
| 21 | 1 – Contribuição Previdenciária apurada no período, exclusivamente com base na Receita Bruta; |
||
| 22 | 2 – Contribuição Previdenciária apurada no período, com base na Receita Bruta e com base nas |
||
| 23 | Remunerações pagas, na forma dos nos incisos I e III do art. 22 da Lei no 8.212, de 1991.', |
||
| 24 | 'format' => '' |
||
| 25 | ], |
||
| 26 | 'VL_REC_TOT' => [ |
||
| 27 | 'type' => 'numeric', |
||
| 28 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
| 29 | 'required' => false, |
||
| 30 | 'info' => 'Valor da Receita Bruta Total da Pessoa Jurídica no Período', |
||
| 31 | 'format' => '15v2' |
||
| 32 | ], |
||
| 33 | 'VL_REC_ATIV' => [ |
||
| 34 | 'type' => 'numeric', |
||
| 35 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
| 36 | 'required' => false, |
||
| 37 | 'info' => 'Valor da Receita Bruta da(s) Atividade(s) Sujeita(s) à |
||
| 38 | Contribuição Previdenciária sobre a Receita Bruta', |
||
| 39 | 'format' => '15v2' |
||
| 40 | ], |
||
| 41 | 'VL_REC_DEMAIS_ATIV' => [ |
||
| 42 | 'type' => 'numeric', |
||
| 43 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
| 44 | 'required' => false, |
||
| 45 | 'info' => 'Valor da Receita Bruta da(s) Atividade(s) não Sujeita(s) à |
||
| 46 | Contribuição Previdenciária sobre a Receita Bruta', |
||
| 47 | 'format' => '15v2' |
||
| 48 | ], |
||
| 49 | 'INFO_COMPL' => [ |
||
| 50 | 'type' => 'string', |
||
| 51 | 'regex' => '^(.*)$', |
||
| 52 | 'required' => false, |
||
| 53 | 'info' => 'Informação complementar', |
||
| 54 | 'format' => '' |
||
| 55 | ], |
||
| 56 | |||
| 57 | ]; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * Constructor |
||
| 61 | * @param \stdClass $std |
||
| 62 | */ |
||
| 63 | public function __construct(\stdClass $std) |
||
| 68 | } |
||
| 69 |
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.