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 M600 extends Element implements ElementInterface |
|
|
|
|||
| 10 | { |
||
| 11 | const REG = 'M600'; |
||
| 12 | const LEVEL = 2; |
||
| 13 | const PARENT = 'M001'; |
||
| 14 | |||
| 15 | protected $parameters = [ |
||
| 16 | 'VL_TOT_CONT_NC_PER' => [ |
||
| 17 | 'type' => 'numeric', |
||
| 18 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
| 19 | 'required' => false, |
||
| 20 | 'info' => 'Valor Total da Contribuição Não Cumulativa do Período (recuperado do campo 13 do ' . |
||
| 21 | 'Registro M610, quando o campo “COD_CONT” = 01, 02, 03, 04, 32 e 71) ', |
||
| 22 | 'format' => '15v2' |
||
| 23 | ], |
||
| 24 | 'VL_TOT_CRED_DESC' => [ |
||
| 25 | 'type' => 'numeric', |
||
| 26 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
| 27 | 'required' => false, |
||
| 28 | 'info' => 'Valor do Crédito Descontado, Apurado no Próprio Período da Escrituração (recuperado ' . |
||
| 29 | 'do campo 14 do Registro M500) ', |
||
| 30 | 'format' => '15v2' |
||
| 31 | ], |
||
| 32 | 'VL_TOT_CRED_DESC_ANT' => [ |
||
| 33 | 'type' => 'numeric', |
||
| 34 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
| 35 | 'required' => false, |
||
| 36 | 'info' => 'Valor do Crédito Descontado, Apurado em Período de Apuração Anterior (recuperado do ' . |
||
| 37 | 'campo 13 do Registro 1500) ', |
||
| 38 | 'format' => '15v2' |
||
| 39 | ], |
||
| 40 | 'VL_TOT_CONT_NC_DEV' => [ |
||
| 41 | 'type' => 'numeric', |
||
| 42 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
| 43 | 'required' => false, |
||
| 44 | 'info' => 'Valor Total da Contribuição Não Cumulativa Devida (02 - 03 - 04) ', |
||
| 45 | 'format' => '15v2' |
||
| 46 | ], |
||
| 47 | 'VL_RET_NC' => [ |
||
| 48 | 'type' => 'numeric', |
||
| 49 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
| 50 | 'required' => false, |
||
| 51 | 'info' => 'Valor Retido na Fonte Deduzido no Período ', |
||
| 52 | 'format' => '15v2' |
||
| 53 | ], |
||
| 54 | 'VL_OUT_DED_NC' => [ |
||
| 55 | 'type' => 'numeric', |
||
| 56 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
| 57 | 'required' => false, |
||
| 58 | 'info' => 'Outras Deduções no Período ', |
||
| 59 | 'format' => '15v2' |
||
| 60 | ], |
||
| 61 | 'VL_CONT_NC_REC' => [ |
||
| 62 | 'type' => 'numeric', |
||
| 63 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
| 64 | 'required' => false, |
||
| 65 | 'info' => 'Valor da Contribuição Não Cumulativa a Recolher/Pagar (05 - 06 - 07) ', |
||
| 66 | 'format' => '15v2' |
||
| 67 | ], |
||
| 68 | 'VL_TOT_CONT_CUM_PER' => [ |
||
| 69 | 'type' => 'numeric', |
||
| 70 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
| 71 | 'required' => false, |
||
| 72 | 'info' => 'Valor Total da Contribuição Cumulativa do Período (recuperado do campo 13 do Registro ' . |
||
| 73 | 'M610, quando o campo “COD_CONT” = 31, 32, 51, 52, 53, 54 e 72) ', |
||
| 74 | 'format' => '15v2' |
||
| 75 | ], |
||
| 76 | 'VL_RET_CUM' => [ |
||
| 77 | 'type' => 'numeric', |
||
| 78 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
| 79 | 'required' => false, |
||
| 80 | 'info' => 'Valor Retido na Fonte Deduzido no Período ', |
||
| 81 | 'format' => '15v2' |
||
| 82 | ], |
||
| 83 | 'VL_OUT_DED_CUM' => [ |
||
| 84 | 'type' => 'numeric', |
||
| 85 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
| 86 | 'required' => false, |
||
| 87 | 'info' => 'Outras Deduções no Período ', |
||
| 88 | 'format' => '15v2' |
||
| 89 | ], |
||
| 90 | 'VL_CONT_CUM_REC' => [ |
||
| 91 | 'type' => 'numeric', |
||
| 92 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
| 93 | 'required' => false, |
||
| 94 | 'info' => 'Valor da Contribuição Cumulativa a Recolher/Pagar (09 - 10 - 11) ', |
||
| 95 | 'format' => '15v2' |
||
| 96 | ], |
||
| 97 | 'VL_TOT_CONT_REC' => [ |
||
| 98 | 'type' => 'numeric', |
||
| 99 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
| 100 | 'required' => false, |
||
| 101 | 'info' => 'Valor Total da Contribuição a Recolher/Pagar no Período (08 + 12) ', |
||
| 102 | 'format' => '15v2' |
||
| 103 | ], |
||
| 104 | |||
| 105 | ]; |
||
| 106 | |||
| 107 | /** |
||
| 108 | * Constructor |
||
| 109 | * @param \stdClass $std |
||
| 110 | */ |
||
| 111 | public function __construct(\stdClass $std) |
||
| 116 | } |
||
| 117 |
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.