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 | class Z1700 extends Element implements ElementInterface |
||
| 10 | { |
||
| 11 | const REG = '1700'; |
||
| 12 | const LEVEL = 2; |
||
| 13 | const PARENT = '1001'; |
||
| 14 | |||
| 15 | protected $parameters = [ |
||
| 16 | 'IND_NAT_RET' => [ |
||
| 17 | 'type' => 'numeric', |
||
| 18 | 'regex' => '^(01|02|03|04|05|09)$', |
||
| 19 | 'required' => false, |
||
| 20 | 'info' => 'Indicador de Natureza da Retenção na Fonte até 2013 ' . |
||
| 21 | ' 01 - Retenção por Órgãos, Autarquias e Fundações Federais 02 - Retenção por ' . |
||
| 22 | 'outras Entidades da Administração Pública Federal 03 - Retenção por Pessoas ' . |
||
| 23 | 'Jurídicas de Direito Privado 04 - Recolhimento por Sociedade Cooperativa 05 - Retenção ' . |
||
| 24 | 'por Fabricante de Máquinas e Veículos 99 - Outras Retenções ', |
||
| 25 | 'format' => '' |
||
| 26 | ], |
||
| 27 | 'PR_REC_RET' => [ |
||
| 28 | 'type' => 'numeric', |
||
| 29 | 'regex' => '^(\d{6})$', |
||
| 30 | 'required' => false, |
||
| 31 | 'info' => 'Período do Recebimento e da Retenção (MM/AAAA) ', |
||
| 32 | 'format' => '' |
||
| 33 | ], |
||
| 34 | 'VL_RET_APU' => [ |
||
| 35 | 'type' => 'numeric', |
||
| 36 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
| 37 | 'required' => false, |
||
| 38 | 'info' => 'Valor Total da Retenção ', |
||
| 39 | 'format' => '15v2' |
||
| 40 | ], |
||
| 41 | 'VL_RET_DED' => [ |
||
| 42 | 'type' => 'numeric', |
||
| 43 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
| 44 | 'required' => false, |
||
| 45 | 'info' => 'Valor da Retenção deduzida da Contribuição devida no período da escrituração e em ' . |
||
| 46 | 'períodos anteriores. ', |
||
| 47 | 'format' => '15v2' |
||
| 48 | ], |
||
| 49 | 'VL_RET_PER' => [ |
||
| 50 | 'type' => 'numeric', |
||
| 51 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
| 52 | 'required' => false, |
||
| 53 | 'info' => 'Valor da Retenção utilizada mediante Pedido de Restituição. ', |
||
| 54 | 'format' => '15v2' |
||
| 55 | ], |
||
| 56 | 'VL_RET_DCOMP' => [ |
||
| 57 | 'type' => 'numeric', |
||
| 58 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
| 59 | 'required' => false, |
||
| 60 | 'info' => 'Valor da Retenção utilizada mediante Declaração de Compensação. ', |
||
| 61 | 'format' => '15v2' |
||
| 62 | ], |
||
| 63 | 'SLD_RET' => [ |
||
| 64 | 'type' => 'numeric', |
||
| 65 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
| 66 | 'required' => false, |
||
| 67 | 'info' => 'Saldo de Retenção a utilizar em períodos de apuração futuros (04 - 05 - 06 - 07). ', |
||
| 68 | 'format' => '15v2' |
||
| 69 | ], |
||
| 70 | |||
| 71 | ]; |
||
| 72 | |||
| 73 | /** |
||
| 74 | * Constructor |
||
| 75 | * @param \stdClass $std |
||
| 76 | */ |
||
| 77 | public function __construct(\stdClass $std) |
||
| 83 | |||
| 84 | View Code Duplication | public function postValidation() |
|
| 96 | } |
||
| 97 |
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.