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 GetByFiltrosRequest implements \JsonSerializable |
|
|
|||
10 | { |
||
11 | /** |
||
12 | * @var integer |
||
13 | */ |
||
14 | private $intencaoVendaId; |
||
15 | |||
16 | /** |
||
17 | * @var integer |
||
18 | */ |
||
19 | private $formaPagamentoId; |
||
20 | |||
21 | /** |
||
22 | * @var integer |
||
23 | */ |
||
24 | private $terminalId; |
||
25 | |||
26 | /** |
||
27 | * @var integer |
||
28 | */ |
||
29 | private $status; |
||
30 | |||
31 | /** |
||
32 | * @var integer |
||
33 | */ |
||
34 | private $vendasDia; |
||
35 | |||
36 | /** |
||
37 | * @var string |
||
38 | */ |
||
39 | private $referencia; |
||
40 | |||
41 | /** |
||
42 | * GetByFiltrosRequest constructor. |
||
43 | */ |
||
44 | public function __construct() |
||
47 | |||
48 | /** |
||
49 | * @return int |
||
50 | */ |
||
51 | public function getIntencaoVendaId() |
||
55 | |||
56 | /** |
||
57 | * @param int $intencaoVendaId |
||
58 | * @return GetByFiltrosRequest |
||
59 | */ |
||
60 | public function setIntencaoVendaId($intencaoVendaId) |
||
65 | |||
66 | /** |
||
67 | * @return int |
||
68 | */ |
||
69 | public function getFormaPagamentoId() |
||
73 | |||
74 | /** |
||
75 | * @param int $formaPagamentoId |
||
76 | * @return GetByFiltrosRequest |
||
77 | */ |
||
78 | public function setFormaPagamentoId($formaPagamentoId) |
||
83 | |||
84 | /** |
||
85 | * @return int |
||
86 | */ |
||
87 | public function getTerminalId() |
||
91 | |||
92 | /** |
||
93 | * @param int $terminalId |
||
94 | * @return GetByFiltrosRequest |
||
95 | */ |
||
96 | public function setTerminalId($terminalId) |
||
101 | |||
102 | /** |
||
103 | * @return int |
||
104 | */ |
||
105 | public function getStatus() |
||
109 | |||
110 | /** |
||
111 | * @param int $status |
||
112 | * @return GetByFiltrosRequest |
||
113 | */ |
||
114 | public function setStatus($status) |
||
119 | |||
120 | /** |
||
121 | * @return int |
||
122 | */ |
||
123 | public function getVendasDia() |
||
127 | |||
128 | /** |
||
129 | * @param int $vendasDia |
||
130 | * @return GetByFiltrosRequest |
||
131 | */ |
||
132 | public function setVendasDia($vendasDia) |
||
137 | |||
138 | /** |
||
139 | * @return string |
||
140 | */ |
||
141 | public function getReferencia() |
||
145 | |||
146 | /** |
||
147 | * @param string $referencia |
||
148 | * @return GetByFiltrosRequest |
||
149 | */ |
||
150 | public function setReferencia($referencia) |
||
155 | |||
156 | /** |
||
157 | * @return array |
||
158 | */ |
||
159 | function jsonSerialize() |
||
170 | |||
171 | |||
172 | } |
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.