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 |
||
5 | trait Edit { |
||
6 | |||
7 | /** |
||
8 | * \addtogroup Api Api Methods |
||
9 | * @{ |
||
10 | */ |
||
11 | |||
12 | /** |
||
13 | * \brief Edit text of a message sent by the bot. |
||
14 | * \details Use this method to edit text and game messages sent by the bot. [Api reference](https://core.telegram.org/bots/api#editmessagetext) |
||
15 | * @param $message_id Unique identifier of the sent message. |
||
16 | * @param $text New text of the message. |
||
17 | * @param $reply_markup Reply markup of the message will have (will be removed if this is null). |
||
18 | * @param $parse_mode <i>Optional</i>. Send Markdown or HTML. |
||
19 | * @param $disable_web_preview <i>Optional</i>. Disables link previews for links in this message. |
||
20 | */ |
||
21 | View Code Duplication | public function editMessageText(int $message_id, $text, $reply_markup = null, string $parse_mode = 'HTML', bool $disable_web_preview = true) { |
|
35 | |||
36 | /** |
||
37 | * \brief Edit text of a message sent via the bot. |
||
38 | * \details Use this method to edit text messages sent via the bot (for inline queries). [Api reference](https://core.telegram.org/bots/api#editmessagetext) |
||
39 | * @param $inline_message_id Identifier of the inline message. |
||
40 | * @param $text New text of the message. |
||
41 | * @param $reply_markup Reply markup of the message will have (will be removed if this is null). |
||
42 | * @param $parse_mode <i>Optional</i>. Send Markdown or HTML. |
||
43 | * @param $disable_web_preview <i>Optional</i>. Disables link previews for links in this message. |
||
44 | */ |
||
45 | public function editInlineMessageText(string $inline_message_id, $text, string $reply_markup = null, string $parse_mode = 'HTML', bool $disable_web_preview = false) { |
||
58 | |||
59 | /* |
||
60 | * Edit only the inline keyboard of a message (https://core.telegram.org/bots/api#editmessagereplymarkup)ù |
||
61 | * @param |
||
62 | * $message_id Identifier of the message to edit |
||
63 | * $inline_keyboard Inlike keyboard array (https://core.telegram.org/bots/api#inlinekeyboardmarkup) |
||
64 | */ |
||
65 | public function editMessageReplyMarkup($message_id, $inline_keyboard) { |
||
76 | |||
77 | /** @} */ |
||
78 | |||
79 | } |
||
80 |
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.