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 G140 extends Element implements ElementInterface |
|
|
|
|||
| 10 | { |
||
| 11 | const REG = 'G140'; |
||
| 12 | const LEVEL = 5; |
||
| 13 | const PARENT = 'G100'; |
||
| 14 | |||
| 15 | protected $parameters = [ |
||
| 16 | 'NUM_ITEM' => [ |
||
| 17 | 'type' => 'numeric', |
||
| 18 | 'regex' => '^(\d{1,3})$', |
||
| 19 | 'required' => true, |
||
| 20 | 'info' => 'Número sequencial do item no documento fiscal ', |
||
| 21 | 'format' => '' |
||
| 22 | ], |
||
| 23 | 'COD_ITEM' => [ |
||
| 24 | 'type' => 'string', |
||
| 25 | 'regex' => '^.{1,60}$', |
||
| 26 | 'required' => true, |
||
| 27 | 'info' => 'Código correspondente do bem no documento fiscal (campo 02 do registro 0200) ', |
||
| 28 | 'format' => '' |
||
| 29 | ], |
||
| 30 | 'QTDE' => [ |
||
| 31 | 'type' => 'numeric', |
||
| 32 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
| 33 | 'required' => true, |
||
| 34 | 'info' => 'Quantidade, deste item da nota fiscal, que foi aplicada neste bem, expressa na mesma ' |
||
| 35 | .'unidade constante no documento fiscal de entrada', |
||
| 36 | 'format' => '15v5' |
||
| 37 | ], |
||
| 38 | 'UNID' => [ |
||
| 39 | 'type' => 'string', |
||
| 40 | 'regex' => '^[0-9]{6}$', |
||
| 41 | 'required' => true, |
||
| 42 | 'info' => 'Unidade do item constante no documento fiscal de entrada', |
||
| 43 | 'format' => '' |
||
| 44 | ], |
||
| 45 | 'VL_ICMS_OP_APLICADO' => [ |
||
| 46 | 'type' => 'numeric', |
||
| 47 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
| 48 | 'required' => true, |
||
| 49 | 'info' => 'Valor do ICMS da Operação Própria na entrada do item, proporcional à quantidade aplicada ' |
||
| 50 | .'no bem ou componente.', |
||
| 51 | 'format' => '15v2' |
||
| 52 | ], |
||
| 53 | 'VL_ICMS_ST_APLICADO' => [ |
||
| 54 | 'type' => 'numeric', |
||
| 55 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
| 56 | 'required' => true, |
||
| 57 | 'info' => 'Valor do ICMS ST na entrada do item, proporcional à quantidade aplicada no bem ou ' |
||
| 58 | .'componente.', |
||
| 59 | 'format' => '15v2' |
||
| 60 | ], |
||
| 61 | 'VL_ICMS_FRT_APLICADO' => [ |
||
| 62 | 'type' => 'numeric', |
||
| 63 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
| 64 | 'required' => true, |
||
| 65 | 'info' => 'Valor do ICMS sobre Frete do Conhecimento de Transporte na entrada do item, ' |
||
| 66 | .'proporcional à quantidade aplicada no bem ou componente.', |
||
| 67 | 'format' => '15v2' |
||
| 68 | ], |
||
| 69 | 'VL_ICMS_DIF_APLICADO' => [ |
||
| 70 | 'type' => 'numeric', |
||
| 71 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
| 72 | 'required' => true, |
||
| 73 | 'info' => 'Valor do ICMS Diferencial de Alíquota, na entrada do item, proporcional à quantidade ' |
||
| 74 | .'aplicada no bem ou componente.', |
||
| 75 | 'format' => '15v2' |
||
| 76 | ] |
||
| 77 | ]; |
||
| 78 | |||
| 79 | /** |
||
| 80 | * Constructor |
||
| 81 | * @param \stdClass $std |
||
| 82 | */ |
||
| 83 | public function __construct(\stdClass $std) |
||
| 88 | } |
||
| 89 |
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.