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 D161 extends Element implements ElementInterface |
|
|
|
|||
| 10 | { |
||
| 11 | const REG = 'D161'; |
||
| 12 | const LEVEL = 4; |
||
| 13 | const PARENT = ''; |
||
| 14 | |||
| 15 | protected $parameters = [ |
||
| 16 | 'IND_CARGA' => [ |
||
| 17 | 'type' => 'numeric', |
||
| 18 | 'regex' => '', |
||
| 19 | 'required' => true, |
||
| 20 | 'info' => 'Indicador do tipo de transporte da carga coletada: 0 - Rodoviário' |
||
| 21 | . '1 - Ferroviário' |
||
| 22 | . '2 - Rodo-Ferroviário' |
||
| 23 | . '3 - Aquaviário' |
||
| 24 | . '4 - Dutoviário' |
||
| 25 | . '5 - Aéreo' |
||
| 26 | . '9 - Outros', |
||
| 27 | 'format' => '' |
||
| 28 | ], |
||
| 29 | 'CNPJ_CPF_COL' => [ |
||
| 30 | 'type' => 'string', |
||
| 31 | 'regex' => '^[0-9]{14}$', |
||
| 32 | 'required' => true, |
||
| 33 | 'info' => 'Número do CNPJ ou CPF do local da coleta', |
||
| 34 | 'format' => '' |
||
| 35 | ], |
||
| 36 | 'IE_COL' => [ |
||
| 37 | 'type' => 'string', |
||
| 38 | 'regex' => '^[0-9]{14}$', |
||
| 39 | 'required' => true, |
||
| 40 | 'info' => 'Inscrição Estadual do contribuinte do local de coleta', |
||
| 41 | 'format' => '' |
||
| 42 | ], |
||
| 43 | 'COD_MUN_COL' => [ |
||
| 44 | 'type' => 'numeric', |
||
| 45 | 'regex' => '', |
||
| 46 | 'required' => true, |
||
| 47 | 'info' => 'Código do Município do local de coleta, conforme tabela IBGE', |
||
| 48 | 'format' => '' |
||
| 49 | ], |
||
| 50 | 'CNPJ_CPF_ENTG' => [ |
||
| 51 | 'type' => 'string', |
||
| 52 | 'regex' => '^[0-9]{14}$', |
||
| 53 | 'required' => true, |
||
| 54 | 'info' => 'Número do CNPJ ou CPF do local da entrega', |
||
| 55 | 'format' => '' |
||
| 56 | ], |
||
| 57 | 'IE_ENTG' => [ |
||
| 58 | 'type' => 'string', |
||
| 59 | 'regex' => '^[0-9]{14}$', |
||
| 60 | 'required' => true, |
||
| 61 | 'info' => 'Inscrição Estadual do contribuinte do local de entrega', |
||
| 62 | 'format' => '' |
||
| 63 | ], |
||
| 64 | 'COD_MUN_ENTG' => [ |
||
| 65 | 'type' => 'numeric', |
||
| 66 | 'regex' => '^[0-9]{7}$', |
||
| 67 | 'required' => true, |
||
| 68 | 'info' => 'Código do Município do local de entrega, conforme tabela IBGE', |
||
| 69 | 'format' => '' |
||
| 70 | ] |
||
| 71 | ]; |
||
| 72 | |||
| 73 | /** |
||
| 74 | * Constructor |
||
| 75 | * @param \stdClass $std |
||
| 76 | */ |
||
| 77 | public function __construct(\stdClass $std) |
||
| 82 | } |
||
| 83 |
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.