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 Z0140 extends Element implements ElementInterface |
|
|
|
|||
| 10 | { |
||
| 11 | const REG = '0140'; |
||
| 12 | const LEVEL = 2; |
||
| 13 | const PARENT = '000'; |
||
| 14 | |||
| 15 | protected $parameters = [ |
||
| 16 | 'COD_EST' => [ |
||
| 17 | 'type' => 'string', |
||
| 18 | 'regex' => '^.{0,60}$', |
||
| 19 | 'required' => false, |
||
| 20 | 'info' => 'Código de identificação do estabelecimento', |
||
| 21 | 'format' => '' |
||
| 22 | ], |
||
| 23 | 'NOME' => [ |
||
| 24 | 'type' => 'string', |
||
| 25 | 'regex' => '^.{0,100}$', |
||
| 26 | 'required' => false, |
||
| 27 | 'info' => 'Nome empresarial do estabelecimento', |
||
| 28 | 'format' => '' |
||
| 29 | ], |
||
| 30 | 'CNPJ' => [ |
||
| 31 | 'type' => 'string', |
||
| 32 | 'regex' => '^[0-9]{14}$', |
||
| 33 | 'required' => false, |
||
| 34 | 'info' => 'Número de inscrição do estabelecimento no CNPJ.', |
||
| 35 | 'format' => '' |
||
| 36 | ], |
||
| 37 | 'UF' => [ |
||
| 38 | 'type' => 'string', |
||
| 39 | 'regex' => '^.{2}$', |
||
| 40 | 'required' => false, |
||
| 41 | 'info' => 'Sigla da unidade da federação do estabelecimento.', |
||
| 42 | 'format' => '' |
||
| 43 | ], |
||
| 44 | 'IE' => [ |
||
| 45 | 'type' => 'string', |
||
| 46 | 'regex' => '^[0-9]{2,14}$', |
||
| 47 | 'required' => false, |
||
| 48 | 'info' => 'Inscrição Estadual do estabelecimento, se contribuinte de ICMS.', |
||
| 49 | 'format' => '' |
||
| 50 | ], |
||
| 51 | 'COD_MUN' => [ |
||
| 52 | 'type' => 'numeric', |
||
| 53 | 'regex' => '^(\d{7})$', |
||
| 54 | 'required' => false, |
||
| 55 | 'info' => 'Código do município do domicílio fiscal do estabelecimento, conforme a tabela IBGE', |
||
| 56 | 'format' => '' |
||
| 57 | ], |
||
| 58 | 'IM' => [ |
||
| 59 | 'type' => 'string', |
||
| 60 | 'regex' => '^(.*)$', |
||
| 61 | 'required' => false, |
||
| 62 | 'info' => 'Inscrição Municipal do estabelecimento, se contribuinte do ISS.', |
||
| 63 | 'format' => '' |
||
| 64 | ], |
||
| 65 | 'SUFRAMA' => [ |
||
| 66 | 'type' => 'string', |
||
| 67 | 'regex' => '^.{9}$', |
||
| 68 | 'required' => false, |
||
| 69 | 'info' => 'Inscrição do estabelecimento na Suframa', |
||
| 70 | 'format' => '' |
||
| 71 | ], |
||
| 72 | |||
| 73 | ]; |
||
| 74 | |||
| 75 | /** |
||
| 76 | * Constructor |
||
| 77 | * @param \stdClass $std |
||
| 78 | */ |
||
| 79 | public function __construct(\stdClass $std) |
||
| 84 | } |
||
| 85 |
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.