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 Z1800 extends Element implements ElementInterface |
|
|
|
|||
| 10 | { |
||
| 11 | const REG = '1800'; |
||
| 12 | const LEVEL = 2; |
||
| 13 | const PARENT = '1001'; |
||
| 14 | |||
| 15 | protected $parameters = [ |
||
| 16 | 'INC_IMOB' => [ |
||
| 17 | 'type' => 'string', |
||
| 18 | 'regex' => '^.{0,90}$', |
||
| 19 | 'required' => false, |
||
| 20 | 'info' => 'Empreendimento objeto de Incorporação Imobiliária, optante pelo RET. ', |
||
| 21 | 'format' => '' |
||
| 22 | ], |
||
| 23 | 'REC_RECEB_RET' => [ |
||
| 24 | 'type' => 'numeric', |
||
| 25 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
| 26 | 'required' => false, |
||
| 27 | 'info' => 'Receitas recebidas pela incorporadora na venda das unidades imobiliárias que compõem a ' . |
||
| 28 | 'incorporação. ', |
||
| 29 | 'format' => '15v2' |
||
| 30 | ], |
||
| 31 | 'REC_FIN_RET' => [ |
||
| 32 | 'type' => 'numeric', |
||
| 33 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
| 34 | 'required' => false, |
||
| 35 | 'info' => 'Receitas Financeiras e Variações Monetárias decorrentes das vendas submetidas ao RET. ', |
||
| 36 | 'format' => '15v2' |
||
| 37 | ], |
||
| 38 | 'BC_RET' => [ |
||
| 39 | 'type' => 'numeric', |
||
| 40 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
| 41 | 'required' => false, |
||
| 42 | 'info' => 'Base de Cálculo do Recolhimento Unificado ', |
||
| 43 | 'format' => '15v2' |
||
| 44 | ], |
||
| 45 | 'ALIQ_RET' => [ |
||
| 46 | 'type' => 'numeric', |
||
| 47 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
| 48 | 'required' => false, |
||
| 49 | 'info' => 'Alíquota do Recolhimento Unificado. ', |
||
| 50 | 'format' => '6v2' |
||
| 51 | ], |
||
| 52 | 'VL_REC_UNI' => [ |
||
| 53 | 'type' => 'numeric', |
||
| 54 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
| 55 | 'required' => false, |
||
| 56 | 'info' => 'Valor do Recolhimento Unificado. ', |
||
| 57 | 'format' => '15v2' |
||
| 58 | ], |
||
| 59 | 'DT_REC_UNI' => [ |
||
| 60 | 'type' => 'string', |
||
| 61 | 'regex' => '^(0[1-9]|[1-2][0-9]|31(?!(?:0[2469]|11))|30(?!02))(0[1-9]|1[0-2])([12]\d{3})$', |
||
| 62 | 'required' => false, |
||
| 63 | 'info' => 'Data do recolhimento unificado ', |
||
| 64 | 'format' => '' |
||
| 65 | ], |
||
| 66 | 'COD_REC' => [ |
||
| 67 | 'type' => 'string', |
||
| 68 | 'regex' => '^.{0,4}$', |
||
| 69 | 'required' => false, |
||
| 70 | 'info' => 'Código da Receita ', |
||
| 71 | 'format' => '' |
||
| 72 | ], |
||
| 73 | |||
| 74 | ]; |
||
| 75 | |||
| 76 | /** |
||
| 77 | * Constructor |
||
| 78 | * @param \stdClass $std |
||
| 79 | */ |
||
| 80 | public function __construct(\stdClass $std) |
||
| 85 | } |
||
| 86 |
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.