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 | ||
| 14 | View Code Duplication | class C800 extends Element implements ElementInterface | |
|  | |||
| 15 | { | ||
| 16 | const REG = 'C800'; | ||
| 17 | const LEVEL = 2; | ||
| 18 | const PARENT = 'C001'; | ||
| 19 | |||
| 20 | protected $parameters = [ | ||
| 21 | 'COD_MOD' => [ | ||
| 22 | 'type' => 'string', | ||
| 23 | 'regex' => '^(59)$', | ||
| 24 | 'required' => true, | ||
| 25 | 'info' => 'Código do modelo do documento fiscal, conforme a Tabela 4.1.1', | ||
| 26 | 'format' => '' | ||
| 27 | ], | ||
| 28 | 'COD_SIT' => [ | ||
| 29 | 'type' => 'numeric', | ||
| 30 | 'regex' => '^(0)[0-3]$', | ||
| 31 | 'required' => true, | ||
| 32 | 'info' => 'Código da situação do documento fiscal, conforme a Tabela 4.1.2', | ||
| 33 | 'format' => '' | ||
| 34 | ], | ||
| 35 | 'NUM_CFE' => [ | ||
| 36 | 'type' => 'numeric', | ||
| 37 |             'regex' => '^(\d{1,6})$', | ||
| 38 | 'required' => true, | ||
| 39 | 'info' => 'Número do Cupom Fiscal Eletrônico', | ||
| 40 | 'format' => '' | ||
| 41 | ], | ||
| 42 | 'DT_DOC' => [ | ||
| 43 | 'type' => 'string', | ||
| 44 |             'regex' => '^(0[1-9]|[1-2][0-9]|31(?!(?:0[2469]|11))|30(?!02))(0[1-9]|1[0-2])([12]\d{3})$', | ||
| 45 | 'required' => true, | ||
| 46 | 'info' => 'Data da emissão do Cupom Fiscal Eletrônico', | ||
| 47 | 'format' => '' | ||
| 48 | ], | ||
| 49 | 'VL_CFE' => [ | ||
| 50 | 'type' => 'numeric', | ||
| 51 | 'regex' => '^\d+(\.\d*)?|\.\d+$', | ||
| 52 | 'required' => true, | ||
| 53 | 'info' => 'Valor total do Cupom Fiscal Eletrônico', | ||
| 54 | 'format' => '15v2' | ||
| 55 | ], | ||
| 56 | 'VL_PIS' => [ | ||
| 57 | 'type' => 'numeric', | ||
| 58 | 'regex' => '^\d+(\.\d*)?|\.\d+$', | ||
| 59 | 'required' => false, | ||
| 60 | 'info' => 'Valor total do PIS', | ||
| 61 | 'format' => '15v2' | ||
| 62 | ], | ||
| 63 | 'VL_COFINS' => [ | ||
| 64 | 'type' => 'numeric', | ||
| 65 | 'regex' => '^\d+(\.\d*)?|\.\d+$', | ||
| 66 | 'required' => false, | ||
| 67 | 'info' => 'Valor total da COFINS', | ||
| 68 | 'format' => '15v2' | ||
| 69 | ], | ||
| 70 | 'CNPJ_CPF' => [ | ||
| 71 | 'type' => 'string', | ||
| 72 |             'regex' => '^([0-9]{11}|[0-9]{14})$', | ||
| 73 | 'required' => false, | ||
| 74 | 'info' => 'CNPJ ou CPF do destinatário', | ||
| 75 | 'format' => '' | ||
| 76 | ], | ||
| 77 | 'NR_SAT' => [ | ||
| 78 | 'type' => 'numeric', | ||
| 79 |             'regex' => '^(\d{1,9})$', | ||
| 80 | 'required' => true, | ||
| 81 | 'info' => 'Número de Série do equipamento SAT', | ||
| 82 | 'format' => '' | ||
| 83 | ], | ||
| 84 | 'CHV_CFE' => [ | ||
| 85 | 'type' => 'numeric', | ||
| 86 |             'regex' => '^([0-9]{44})?$', | ||
| 87 | 'required' => true, | ||
| 88 | 'info' => 'Chave do Cupom Fiscal Eletrônico', | ||
| 89 | 'format' => '' | ||
| 90 | ], | ||
| 91 | 'VL_DESC' => [ | ||
| 92 | 'type' => 'numeric', | ||
| 93 | 'regex' => '^\d+(\.\d*)?|\.\d+$', | ||
| 94 | 'required' => true, | ||
| 95 | 'info' => 'Valor total de descontos', | ||
| 96 | 'format' => '15v2' | ||
| 97 | ], | ||
| 98 | 'VL_MERC' => [ | ||
| 99 | 'type' => 'numeric', | ||
| 100 | 'regex' => '^\d+(\.\d*)?|\.\d+$', | ||
| 101 | 'required' => true, | ||
| 102 | 'info' => 'Valor total das mercadorias e serviços', | ||
| 103 | 'format' => '15v2' | ||
| 104 | ], | ||
| 105 | 'VL_OUT_DA' => [ | ||
| 106 | 'type' => 'numeric', | ||
| 107 | 'regex' => '^\d+(\.\d*)?|\.\d+$', | ||
| 108 | 'required' => true, | ||
| 109 | 'info' => 'Valor total de outras despesas acessórias e acréscimos', | ||
| 110 | 'format' => '15v2' | ||
| 111 | ], | ||
| 112 | 'VL_ICMS' => [ | ||
| 113 | 'type' => 'numeric', | ||
| 114 | 'regex' => '^\d+(\.\d*)?|\.\d+$', | ||
| 115 | 'required' => true, | ||
| 116 | 'info' => 'Valor do ICMS', | ||
| 117 | 'format' => '15v2' | ||
| 118 | ], | ||
| 119 | 'VL_PIS_ST' => [ | ||
| 120 | 'type' => 'numeric', | ||
| 121 | 'regex' => '^\d+(\.\d*)?|\.\d+$', | ||
| 122 | 'required' => true, | ||
| 123 | 'info' => 'Valor total do PIS retido por subst. trib.', | ||
| 124 | 'format' => '15v2' | ||
| 125 | ], | ||
| 126 | 'VL_COFINS_ST' => [ | ||
| 127 | 'type' => 'numeric', | ||
| 128 | 'regex' => '^\d+(\.\d*)?|\.\d+$', | ||
| 129 | 'required' => true, | ||
| 130 | 'info' => 'Valor total da COFINS retido por subst. trib.', | ||
| 131 | 'format' => '15v2' | ||
| 132 | ], | ||
| 133 | |||
| 134 | ]; | ||
| 135 | |||
| 136 | /** | ||
| 137 | * Constructor | ||
| 138 | * @param \stdClass $std | ||
| 139 | */ | ||
| 140 | public function __construct(\stdClass $std) | ||
| 146 | |||
| 147 | |||
| 148 | public function postValidation() | ||
| 158 | } | ||
| 159 | 
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.