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 Z1300 extends Element implements ElementInterface |
||
| 10 | { |
||
| 11 | const REG = '1300'; |
||
| 12 | const LEVEL = 2; |
||
| 13 | const PARENT = '1001'; |
||
| 14 | |||
| 15 | protected $parameters = [ |
||
| 16 | 'IND_NAT_RET' => [ |
||
| 17 | 'type' => 'numeric', |
||
| 18 | 'regex' => '^(1|2|3|4|5|9|1|2|3|4|5|9|1|2|3|4|5|9)$', |
||
| 19 | 'required' => false, |
||
| 20 | 'info' => 'Indicador de Natureza da Retenção na Fonte', |
||
| 21 | 'format' => '' |
||
| 22 | ], |
||
| 23 | 'PR_REC_RET' => [ |
||
| 24 | 'type' => 'numeric', |
||
| 25 | 'regex' => '^(\d{0,6})$', |
||
| 26 | 'required' => false, |
||
| 27 | 'info' => 'Período do Recebimento e da Retenção (MM/AAAA) ', |
||
| 28 | 'format' => '' |
||
| 29 | ], |
||
| 30 | 'VL_RET_APU' => [ |
||
| 31 | 'type' => 'numeric', |
||
| 32 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
| 33 | 'required' => false, |
||
| 34 | 'info' => 'Valor Total da Retenção ', |
||
| 35 | 'format' => '15v2' |
||
| 36 | ], |
||
| 37 | 'VL_RET_DED' => [ |
||
| 38 | 'type' => 'numeric', |
||
| 39 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
| 40 | 'required' => false, |
||
| 41 | 'info' => 'Valor da Retenção deduzida da Contribuição devida no período da escrituração e em ' . |
||
| 42 | 'períodos anteriores. ', |
||
| 43 | 'format' => '15v2' |
||
| 44 | ], |
||
| 45 | 'VL_RET_PER' => [ |
||
| 46 | 'type' => 'numeric', |
||
| 47 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
| 48 | 'required' => false, |
||
| 49 | 'info' => 'Valor da Retenção utilizada mediante Pedido de Restituição. ', |
||
| 50 | 'format' => '15v2' |
||
| 51 | ], |
||
| 52 | 'VL_RET_DCOMP' => [ |
||
| 53 | 'type' => 'numeric', |
||
| 54 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
| 55 | 'required' => false, |
||
| 56 | 'info' => 'Valor da Retenção utilizada mediante Declaração de Compensação. ', |
||
| 57 | 'format' => '15v2' |
||
| 58 | ], |
||
| 59 | 'SLD_RET' => [ |
||
| 60 | 'type' => 'numeric', |
||
| 61 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
| 62 | 'required' => false, |
||
| 63 | 'info' => 'Saldo de Retenção a utilizar em períodos de apuração futuros (04 – 05 - 06 - 07). ', |
||
| 64 | 'format' => '15v2' |
||
| 65 | ], |
||
| 66 | |||
| 67 | ]; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * Constructor |
||
| 71 | * @param \stdClass $std |
||
| 72 | */ |
||
| 73 | public function __construct(\stdClass $std) |
||
| 79 | |||
| 80 | View Code Duplication | public function postValidation() |
|
| 92 | } |
||
| 93 |
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.