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 |
||
30 | View Code Duplication | class ShippingQuery implements \ArrayAccess |
|
|
|||
31 | { |
||
32 | |||
33 | /** @} */ |
||
34 | |||
35 | use EntityAccess; |
||
36 | |||
37 | /** |
||
38 | * \brief Get payload for the current invoice's checkout. |
||
39 | * @return string $payload The invoice's payload. |
||
40 | */ |
||
41 | public function getPayload() : string |
||
45 | |||
46 | /** |
||
47 | * \brief Get chat ID of the chat where the message comes from. |
||
48 | * @return $chat_id Chat ID. |
||
49 | */ |
||
50 | public function getChatID() |
||
54 | |||
55 | /** |
||
56 | * \brief (<i>Internal</i>) Get parameter to set to the bot. |
||
57 | * \details Each time the bot receive a query, |
||
58 | * the parameter _shipping_query_id will be set to the ID of this callback. |
||
59 | * @return array Array with the parameter name as "var" index, and the id in "id" index. |
||
60 | */ |
||
61 | public function getBotParameter() : array |
||
65 | |||
66 | /** |
||
67 | * \brief Get ID of this callback query. |
||
68 | * @return int $id ID of the callback. |
||
69 | */ |
||
70 | public function getID() : int |
||
74 | } |
||
75 |
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.