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 P110 extends Element implements ElementInterface |
|
|
|
|||
| 10 | { |
||
| 11 | const REG = 'P110'; |
||
| 12 | const LEVEL = 4; |
||
| 13 | const PARENT = 'P100'; |
||
| 14 | |||
| 15 | protected $parameters = [ |
||
| 16 | 'NUM_CAMPO' => [ |
||
| 17 | 'type' => 'string', |
||
| 18 | 'regex' => '^.{2}$', |
||
| 19 | 'required' => false, |
||
| 20 | 'info' => 'Informar o número do campo do registro “P100”, objeto de detalhamento neste registro. ', |
||
| 21 | 'format' => '' |
||
| 22 | ], |
||
| 23 | 'COD_DET' => [ |
||
| 24 | 'type' => 'string', |
||
| 25 | 'regex' => '^.{8}$', |
||
| 26 | 'required' => false, |
||
| 27 | 'info' => 'Código do tipo de detalhamento, conforme Tabela 5.1.2 ', |
||
| 28 | 'format' => '' |
||
| 29 | ], |
||
| 30 | 'DET_VALOR' => [ |
||
| 31 | 'type' => 'numeric', |
||
| 32 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
| 33 | 'required' => false, |
||
| 34 | 'info' => 'Valor detalhado referente ao campo 02 deste registro ', |
||
| 35 | 'format' => '15v2' |
||
| 36 | ], |
||
| 37 | 'INF_COMPL' => [ |
||
| 38 | 'type' => 'string', |
||
| 39 | 'regex' => '^(.*)$', |
||
| 40 | 'required' => false, |
||
| 41 | 'info' => 'Informação complementar do detalhamento. ', |
||
| 42 | 'format' => '' |
||
| 43 | ], |
||
| 44 | |||
| 45 | ]; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Constructor |
||
| 49 | * @param \stdClass $std |
||
| 50 | */ |
||
| 51 | public function __construct(\stdClass $std) |
||
| 56 | } |
||
| 57 |
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.