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 |
||
| 13 | View Code Duplication | class C180 extends Element implements ElementInterface |
|
|
|
|||
| 14 | { |
||
| 15 | const REG = 'C180'; |
||
| 16 | const LEVEL = 4; |
||
| 17 | const PARENT = 'C170'; |
||
| 18 | |||
| 19 | protected $parameters = [ |
||
| 20 | 'COD_RESP_RET' => [ |
||
| 21 | 'type' => 'numeric', |
||
| 22 | 'regex' => '', |
||
| 23 | 'required' => true, |
||
| 24 | 'info' => 'Código que indica o responsável pela retenção do ICMS-ST:' |
||
| 25 | . '1-Remetente Direto 2-Remetente Indireto' |
||
| 26 | . '3-Próprio declarante', |
||
| 27 | 'format' => '' |
||
| 28 | ], |
||
| 29 | 'QUANT_CONV' => [ |
||
| 30 | 'type' => 'numeric', |
||
| 31 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
| 32 | 'required' => true, |
||
| 33 | 'info' => 'Quantidade do item', |
||
| 34 | 'format' => '15v6' |
||
| 35 | ], |
||
| 36 | 'UNID' => [ |
||
| 37 | 'type' => 'string', |
||
| 38 | 'regex' => '^[0-9]{0}$', |
||
| 39 | 'required' => true, |
||
| 40 | 'info' => 'Unidade adotada para informar o campo QUANT_CONV.', |
||
| 41 | 'format' => '' |
||
| 42 | ], |
||
| 43 | 'VL_UNIT_ICMS_OP_CONV' => [ |
||
| 44 | 'type' => 'numeric', |
||
| 45 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
| 46 | 'required' => true, |
||
| 47 | 'info' => 'Valor unitário do ICMS operação própria que o informante teria direito ao crédito caso a mercadoria estivesse sob o regime comum de tributação, considerando unidade utilizada para informar o campo QUANT_CONV.', |
||
| 48 | 'format' => '15v6' |
||
| 49 | ], |
||
| 50 | 'VL_UNIT_BC_ICMS_ST_CONV' => [ |
||
| 51 | 'type' => 'numeric', |
||
| 52 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
| 53 | 'required' => true, |
||
| 54 | 'info' => 'Valor unitário da base de cálculo do imposto pago ou retido anteriormente por substituição, considerando a unidade utilizada para informar o campo QUANT_CONV, aplicando-se redução, se houver.', |
||
| 55 | 'format' => '15v6' |
||
| 56 | ], |
||
| 57 | 'VL_UNIT_ICMS_ST_CONV' => [ |
||
| 58 | 'type' => 'numeric', |
||
| 59 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
| 60 | 'required' => true, |
||
| 61 | 'info' => 'Valor unitário do imposto pago ou retido anteriormente por substituição, inclusive FCP se devido, considerando a unidade utilizada para informar o campo QUANT_CONV.', |
||
| 62 | 'format' => '15v6' |
||
| 63 | ], |
||
| 64 | 'VL_UNIT_FCP_ST_CONV' => [ |
||
| 65 | 'type' => 'numeric', |
||
| 66 | 'regex' => '', |
||
| 67 | 'required' => true, |
||
| 68 | 'info' => 'Valor unitário do FCP_ST agregado ao valor informado no campo VL_UNIT_ICMS_ST_CONV', |
||
| 69 | 'format' => '' |
||
| 70 | ], |
||
| 71 | 'COD_DA' => [ |
||
| 72 | 'type' => 'string', |
||
| 73 | 'regex' => '^[0-9]{0}$', |
||
| 74 | 'required' => true, |
||
| 75 | 'info' => 'Código do modelo do documento de arrecadação:' |
||
| 76 | . '0 - Documento estadual de arrecadação' |
||
| 77 | . '1 - GNRE', |
||
| 78 | 'format' => '' |
||
| 79 | ], |
||
| 80 | 'NUM_DA' => [ |
||
| 81 | 'type' => 'string', |
||
| 82 | 'regex' => '^[0-9]{0}$', |
||
| 83 | 'required' => true, |
||
| 84 | 'info' => 'Número do documento de arrecadação estadual, se houver', |
||
| 85 | 'format' => '' |
||
| 86 | ], |
||
| 87 | ]; |
||
| 88 | |||
| 89 | /** |
||
| 90 | * Constructor |
||
| 91 | * @param \stdClass $std |
||
| 92 | */ |
||
| 93 | public function __construct(\stdClass $std) |
||
| 98 | } |
||
| 99 |
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.