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 |
||
14 | class SelectPayload |
||
15 | { |
||
16 | /** |
||
17 | * Payload recebido do front-end |
||
18 | * |
||
19 | * @var array |
||
20 | */ |
||
21 | protected $payload; |
||
22 | |||
23 | /** |
||
24 | * Constrói o payload |
||
25 | * |
||
26 | * @param array $payload |
||
27 | */ |
||
28 | 1 | public function __construct(array $payload) |
|
32 | |||
33 | /** |
||
34 | * Retorna as colunas filtradas no select |
||
35 | * @return array |
||
36 | * @throws InvalidColumnNameException |
||
37 | */ |
||
38 | 1 | public function getColumns() |
|
60 | |||
61 | /** |
||
62 | * Retorna o limite de linhas |
||
63 | * |
||
64 | * @return int|null |
||
65 | */ |
||
66 | 1 | View Code Duplication | public function getLimit() |
76 | |||
77 | /** |
||
78 | * Retorna o offset de linhas |
||
79 | * |
||
80 | * @return int|null |
||
81 | */ |
||
82 | 1 | View Code Duplication | public function getOffset() |
92 | |||
93 | /** |
||
94 | * Retorna a ordem definida pelo usuário em string |
||
95 | * |
||
96 | * @return string |
||
97 | */ |
||
98 | 1 | public function getOrder() |
|
116 | |||
117 | /** |
||
118 | * Retorna o where do payload de seleção |
||
119 | * |
||
120 | * @return array |
||
121 | */ |
||
122 | 1 | public function getWhere() |
|
132 | } |
||
133 |
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.