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 Z1900 extends Element implements ElementInterface | |
|  | |||
| 10 | { | ||
| 11 | const REG = '1900'; | ||
| 12 | const LEVEL = 2; | ||
| 13 | const PARENT = '1001'; | ||
| 14 | |||
| 15 | protected $parameters = [ | ||
| 16 | 'CNPJ' => [ | ||
| 17 | 'type' => 'string', | ||
| 18 |             'regex' => '^[0-9]{14}$', | ||
| 19 | 'required' => false, | ||
| 20 | 'info' => 'CNPJ do estabelecimento da pessoa jurídica, emitente dos documentos geradores de receita ', | ||
| 21 | 'format' => '' | ||
| 22 | ], | ||
| 23 | 'COD_MOD' => [ | ||
| 24 | 'type' => 'string', | ||
| 25 | 'regex' => '^(98|99)$', | ||
| 26 | 'required' => false, | ||
| 27 | 'info' => 'Código do modelo do documento fiscal conforme a Tabela 4.1.1, ou ' . | ||
| 28 | ' 98 – Nota Fiscal de Prestação de Serviços (ISSQN) 99 – Outros Documentos ', | ||
| 29 | 'format' => '' | ||
| 30 | ], | ||
| 31 | 'SER' => [ | ||
| 32 | 'type' => 'string', | ||
| 33 |             'regex' => '^.{0,4}$', | ||
| 34 | 'required' => false, | ||
| 35 | 'info' => 'Série do documento fiscal ', | ||
| 36 | 'format' => '' | ||
| 37 | ], | ||
| 38 | 'SUB_SER' => [ | ||
| 39 | 'type' => 'numeric', | ||
| 40 |             'regex' => '^(\d{0,20})$', | ||
| 41 | 'required' => false, | ||
| 42 | 'info' => 'Subserie do documento fiscal ', | ||
| 43 | 'format' => '' | ||
| 44 | ], | ||
| 45 | 'COD_SIT' => [ | ||
| 46 | 'type' => 'numeric', | ||
| 47 | 'regex' => '^(00|02|09)$', | ||
| 48 | 'required' => false, | ||
| 49 | 'info' => 'Código da situação do documento fiscal ' . | ||
| 50 | ' 00 – Documento regular 02 – Documento cancelado 99 – Outros ', | ||
| 51 | 'format' => '' | ||
| 52 | ], | ||
| 53 | 'VL_TOT_REC' => [ | ||
| 54 | 'type' => 'numeric', | ||
| 55 | 'regex' => '^\d+(\.\d*)?|\.\d+$', | ||
| 56 | 'required' => false, | ||
| 57 | 'info' => 'Valor total da receita, conforme os documentos emitidos no período, representativos da ' . | ||
| 58 | 'venda de bens e serviços ', | ||
| 59 | 'format' => '15v2' | ||
| 60 | ], | ||
| 61 | 'QUANT_DOC' => [ | ||
| 62 | 'type' => 'numeric', | ||
| 63 | 'regex' => '^([0-9]+)$', | ||
| 64 | 'required' => false, | ||
| 65 | 'info' => 'Quantidade total de documentos emitidos no período ', | ||
| 66 | 'format' => '' | ||
| 67 | ], | ||
| 68 | 'CST_PIS' => [ | ||
| 69 | 'type' => 'string', | ||
| 70 | 'regex' => '^((0[1-9])|49|99)$', | ||
| 71 | 'required' => false, | ||
| 72 | 'info' => 'Código da Situação Tributária do PIS/Pasep ', | ||
| 73 | 'format' => '' | ||
| 74 | ], | ||
| 75 | 'CST_COFINS' => [ | ||
| 76 | 'type' => 'string', | ||
| 77 | 'regex' => '^((0[1-9])|49|99)$', | ||
| 78 | 'required' => false, | ||
| 79 | 'info' => 'Código da Situação Tributária da Cofins ', | ||
| 80 | 'format' => '' | ||
| 81 | ], | ||
| 82 | 'CFOP' => [ | ||
| 83 | 'type' => 'numeric', | ||
| 84 |             'regex' => '^(\d{4})$', | ||
| 85 | 'required' => false, | ||
| 86 | 'info' => 'Código fiscal de operação e prestação ', | ||
| 87 | 'format' => '' | ||
| 88 | ], | ||
| 89 | 'INF_COMPL' => [ | ||
| 90 | 'type' => 'string', | ||
| 91 | 'regex' => '^(.*)$', | ||
| 92 | 'required' => false, | ||
| 93 | 'info' => 'Informações complementares ', | ||
| 94 | 'format' => '' | ||
| 95 | ], | ||
| 96 | 'COD_CTA' => [ | ||
| 97 | 'type' => 'string', | ||
| 98 |             'regex' => '^.{0,255}$', | ||
| 99 | 'required' => false, | ||
| 100 | 'info' => 'Código da conta analítica contábil representativa da receita ', | ||
| 101 | 'format' => '' | ||
| 102 | ], | ||
| 103 | |||
| 104 | ]; | ||
| 105 | |||
| 106 | /** | ||
| 107 | * Constructor | ||
| 108 | * @param \stdClass $std | ||
| 109 | */ | ||
| 110 | public function __construct(\stdClass $std) | ||
| 115 | } | ||
| 116 | 
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.