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 | class C425 extends Element implements ElementInterface |
||
| 10 | { |
||
| 11 | const REG = 'C425'; |
||
| 12 | const LEVEL = 5; |
||
| 13 | const PARENT = 'C420'; |
||
| 14 | |||
| 15 | protected $parameters = [ |
||
| 16 | 'COD_ITEM' => [ |
||
| 17 | 'type' => 'string', |
||
| 18 | 'regex' => '^.{1,60}$', |
||
| 19 | 'required' => true, |
||
| 20 | 'info' => 'Código do item (campo 02 do Registro 0200)', |
||
| 21 | 'format' => '' |
||
| 22 | ], |
||
| 23 | 'QTD' => [ |
||
| 24 | 'type' => 'numeric', |
||
| 25 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
| 26 | 'required' => true, |
||
| 27 | 'info' => 'Quantidade acumulada do item', |
||
| 28 | 'format' => '15v3' |
||
| 29 | ], |
||
| 30 | 'UNID' => [ |
||
| 31 | 'type' => 'string', |
||
| 32 | 'regex' => '^.{1,6}$', |
||
| 33 | 'required' => true, |
||
| 34 | 'info' => 'Unidade do item (Campo 02 do registro 0190)', |
||
| 35 | 'format' => '' |
||
| 36 | ], |
||
| 37 | 'VL_ITEM' => [ |
||
| 38 | 'type' => 'numeric', |
||
| 39 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
| 40 | 'required' => true, |
||
| 41 | 'info' => 'Valor acumulado do item', |
||
| 42 | 'format' => '15v2' |
||
| 43 | ], |
||
| 44 | 'VL_PIS' => [ |
||
| 45 | 'type' => 'numeric', |
||
| 46 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
| 47 | 'required' => false, |
||
| 48 | 'info' => 'Valor do PIS', |
||
| 49 | 'format' => '15v2' |
||
| 50 | ], |
||
| 51 | 'VL_COFINS' => [ |
||
| 52 | 'type' => 'numeric', |
||
| 53 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
| 54 | 'required' => false, |
||
| 55 | 'info' => 'Valor da COFINS', |
||
| 56 | 'format' => '15v2' |
||
| 57 | ], |
||
| 58 | ]; |
||
| 59 | |||
| 60 | /** |
||
| 61 | * Constructor |
||
| 62 | * @param \stdClass $std |
||
| 63 | */ |
||
| 64 | public function __construct(\stdClass $std) |
||
| 70 | |||
| 71 | View Code Duplication | public function postValidation() |
|
| 78 | } |
||
| 79 |
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.