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 |
||
19 | View Code Duplication | class Z0100 extends Element implements ElementInterface |
|
|
|||
20 | { |
||
21 | const REG = '0100'; |
||
22 | const LEVEL = 2; |
||
23 | const PARENT = '0015|0005'; |
||
24 | |||
25 | protected $parameters = [ |
||
26 | 'NOME' => [ |
||
27 | 'type' => 'string', |
||
28 | 'regex' => '^.{3,100}$', |
||
29 | 'required' => true, |
||
30 | 'info' => 'Nome do contabilista', |
||
31 | 'format' => '' |
||
32 | ], |
||
33 | 'CPF' => [ |
||
34 | 'type' => 'string', |
||
35 | 'regex' => '^[0-9]{11}$', |
||
36 | 'required' => true, |
||
37 | 'info' => 'Número de inscrição do contabilista no CPF', |
||
38 | 'format' => '' |
||
39 | ], |
||
40 | 'CRC' => [ |
||
41 | 'type' => 'string', |
||
42 | 'regex' => '^.{8,15}$', |
||
43 | 'required' => true, |
||
44 | 'info' => 'Número de inscrição do contabilista no Conselho Regional de Contabilidade', |
||
45 | 'format' => '' |
||
46 | ], |
||
47 | 'CNPJ' => [ |
||
48 | 'type' => 'string', |
||
49 | 'regex' => '^[0-9]{14}$', |
||
50 | 'required' => false, |
||
51 | 'info' => 'Número de inscrição do escritório de contabilidade no CNPJ, se houver.', |
||
52 | 'format' => '' |
||
53 | ], |
||
54 | 'CEP' => [ |
||
55 | 'type' => 'string', |
||
56 | 'regex' => '^[0-9]{8}$', |
||
57 | 'required' => false, |
||
58 | 'info' => 'Código de Endereçamento Posta.l', |
||
59 | 'format' => '' |
||
60 | ], |
||
61 | 'END' => [ |
||
62 | 'type' => 'string', |
||
63 | 'regex' => '^.{3,60}$', |
||
64 | 'required' => false, |
||
65 | 'info' => 'Logradouro e endereço do imóvel.', |
||
66 | 'format' => '' |
||
67 | ], |
||
68 | 'NUM' => [ |
||
69 | 'type' => 'string', |
||
70 | 'regex' => '^.{1,10}$', |
||
71 | 'required' => false, |
||
72 | 'info' => 'Número do imóvel.', |
||
73 | 'format' => '' |
||
74 | ], |
||
75 | 'COMPL' => [ |
||
76 | 'type' => 'string', |
||
77 | 'regex' => '^.{1,60}$', |
||
78 | 'required' => false, |
||
79 | 'info' => 'Dados complementares do endereço.', |
||
80 | 'format' => '' |
||
81 | ], |
||
82 | 'BAIRRO' => [ |
||
83 | 'type' => 'string', |
||
84 | 'regex' => '^.{3,60}$', |
||
85 | 'required' => false, |
||
86 | 'info' => 'Bairro em que o imóvel está situado.', |
||
87 | 'format' => '' |
||
88 | ], |
||
89 | 'FONE' => [ |
||
90 | 'type' => 'string', |
||
91 | 'regex' => '^[0-9]{8,11}$', |
||
92 | 'required' => false, |
||
93 | 'info' => 'Número do telefone (DDD+FONE).', |
||
94 | 'format' => '' |
||
95 | ], |
||
96 | 'FAX' => [ |
||
97 | 'type' => 'string', |
||
98 | 'regex' => '^[0-9]{8,11}$', |
||
99 | 'required' => false, |
||
100 | 'info' => 'Número do fax.', |
||
101 | 'format' => '' |
||
102 | ], |
||
103 | 'EMAIL' => [ |
||
104 | 'type' => 'string', |
||
105 | 'regex' => 'email', |
||
106 | 'required' => true, |
||
107 | 'info' => 'Endereço do correio eletrônico.', |
||
108 | 'format' => '' |
||
109 | ], |
||
110 | 'COD_MUN' => [ |
||
111 | 'type' => 'integer', |
||
112 | 'regex' => '^[0-9]{7}$', |
||
113 | 'required' => true, |
||
114 | 'info' => 'Código do município, conforme tabela IBGE.', |
||
115 | 'format' => '' |
||
116 | ] |
||
117 | ]; |
||
118 | |||
119 | /** |
||
120 | * Constructor |
||
121 | * @param \stdClass $std |
||
122 | */ |
||
123 | public function __construct(\stdClass $std) |
||
128 | } |
||
129 |
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.