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 |
||
| 44 | View Code Duplication | class K220 extends Element implements ElementInterface |
|
|
|
|||
| 45 | { |
||
| 46 | const REG = 'K220'; |
||
| 47 | const LEVEL = 3; |
||
| 48 | const PARENT = 'K215|K210|K200|K100'; |
||
| 49 | |||
| 50 | protected $parameters = [ |
||
| 51 | 'DT_MOV' => [ |
||
| 52 | 'type' => 'string', |
||
| 53 | 'regex' => '^(0[1-9]|[1-2][0-9]|31(?!(?:0[2469]|11))|30(?!02))(0[1-9]|1[0-2])([12]\d{3})$', |
||
| 54 | 'required' => true, |
||
| 55 | 'info' => 'Data da movimentação interna', |
||
| 56 | 'format' => '' |
||
| 57 | ], |
||
| 58 | 'COD_ITEM_ORI' => [ |
||
| 59 | 'type' => 'string', |
||
| 60 | 'regex' => '^.{1,60}$', |
||
| 61 | 'required' => true, |
||
| 62 | 'info' => 'Código do item de origem (campo 02 do Registro 0200)', |
||
| 63 | 'format' => '' |
||
| 64 | ], |
||
| 65 | 'COD_ITEM_DEST' => [ |
||
| 66 | 'type' => 'string', |
||
| 67 | 'regex' => '^.{1,60}$', |
||
| 68 | 'required' => true, |
||
| 69 | 'info' => 'Código do item de destino (campo 02 do Registro 0200)', |
||
| 70 | 'format' => '' |
||
| 71 | ], |
||
| 72 | 'QTD_ORI' => [ |
||
| 73 | 'type' => 'numeric', |
||
| 74 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
| 75 | 'required' => true, |
||
| 76 | 'info' => 'Quantidade movimentada do item de origem', |
||
| 77 | 'format' => '15v6' |
||
| 78 | ], |
||
| 79 | 'QTD_DEST' => [ |
||
| 80 | 'type' => 'numeric', |
||
| 81 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
||
| 82 | 'required' => true, |
||
| 83 | 'info' => 'Quantidade movimentada do item de destino', |
||
| 84 | 'format' => '15v6' |
||
| 85 | ], |
||
| 86 | ]; |
||
| 87 | |||
| 88 | /** |
||
| 89 | * Constructor |
||
| 90 | * @param \stdClass $std |
||
| 91 | */ |
||
| 92 | public function __construct(\stdClass $std) |
||
| 97 | } |
||
| 98 |
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.