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 Z1700 extends Element implements ElementInterface | |
|  | |||
| 10 | { | ||
| 11 | const REG = '1700'; | ||
| 12 | const LEVEL = 2; | ||
| 13 | const PARENT = '1001'; | ||
| 14 | |||
| 15 | protected $parameters = [ | ||
| 16 | 'COD_DISP' => [ | ||
| 17 | 'type' => 'string', | ||
| 18 | 'regex' => '^0[0-5]$', | ||
| 19 | 'required' => true, | ||
| 20 | 'info' => 'Código dispositivo autorizado: ' | ||
| 21 | .'00 - Formulário de Segurança – impressor autônomo ' | ||
| 22 | .'01 - FS-DA – Formulário de Segurança para Impressão de DANFE ' | ||
| 23 | .'02 – Formulário de segurança - NF-e ' | ||
| 24 | .'03 - Formulário Contínuo 04 – Blocos ' | ||
| 25 | .'05 - Jogos Soltos', | ||
| 26 | 'format' => '' | ||
| 27 | ], | ||
| 28 | 'COD_MOD' => [ | ||
| 29 | 'type' => 'string', | ||
| 30 |             'regex'    => '^.{2}$', | ||
| 31 | 'required' => true, | ||
| 32 | 'info' => 'Código do modelo do dispositivo autorizado, conforme a Tabela 4.1.1', | ||
| 33 | 'format' => '' | ||
| 34 | ], | ||
| 35 | 'SER' => [ | ||
| 36 | 'type' => 'string', | ||
| 37 |             'regex'    => '^.{1,4}$', | ||
| 38 | 'required' => false, | ||
| 39 | 'info' => 'Série do dispositivo autorizado', | ||
| 40 | 'format' => '' | ||
| 41 | ], | ||
| 42 | 'SUB' => [ | ||
| 43 | 'type' => 'string', | ||
| 44 |             'regex'    => '^.{1,3}$', | ||
| 45 | 'required' => false, | ||
| 46 | 'info' => 'Subsérie do dispositivo autorizado', | ||
| 47 | 'format' => '' | ||
| 48 | ], | ||
| 49 | 'NUM_DOC_INI' => [ | ||
| 50 | 'type' => 'integer', | ||
| 51 |             'regex'    => '^\d{1,12}$', | ||
| 52 | 'required' => true, | ||
| 53 | 'info' => 'Número do dispositivo autorizado (utilizado) inicial', | ||
| 54 | 'format' => '' | ||
| 55 | ], | ||
| 56 | 'NUM_DOC_FIN' => [ | ||
| 57 | 'type' => 'integer', | ||
| 58 |             'regex'    => '^\d{1,12}$', | ||
| 59 | 'required' => true, | ||
| 60 | 'info' => 'Número do dispositivo autorizado (utilizado) final', | ||
| 61 | 'format' => '' | ||
| 62 | ], | ||
| 63 | 'NUM_AUT' => [ | ||
| 64 | 'type' => 'string', | ||
| 65 |             'regex'    => '^\d{1,60}$', | ||
| 66 | 'required' => true, | ||
| 67 | 'info' => 'Número da autorização, conforme dispositivo autorizado', | ||
| 68 | 'format' => '' | ||
| 69 | ] | ||
| 70 | ]; | ||
| 71 | |||
| 72 | /** | ||
| 73 | * Constructor | ||
| 74 | * @param \stdClass $std | ||
| 75 | */ | ||
| 76 | public function __construct(\stdClass $std) | ||
| 81 | } | ||
| 82 | 
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.