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 | class Keyboard extends Entity |
||
31 | { |
||
32 | /** |
||
33 | * {@inheritdoc} |
||
34 | */ |
||
35 | 18 | public function __construct($data = []) |
|
43 | |||
44 | /** |
||
45 | * If this keyboard is an inline keyboard. |
||
46 | * |
||
47 | * @return bool |
||
48 | */ |
||
49 | 18 | public function isInlineKeyboard() |
|
53 | |||
54 | /** |
||
55 | * Get the proper keyboard button class for this keyboard. |
||
56 | * |
||
57 | * @return KeyboardButton|InlineKeyboardButton |
||
58 | */ |
||
59 | 12 | public function getKeyboardButtonClass() |
|
63 | |||
64 | /** |
||
65 | * Get the type of keyboard, either "inline_keyboard" or "keyboard". |
||
66 | * |
||
67 | * @return string |
||
68 | */ |
||
69 | 18 | public function getKeyboardType() |
|
73 | |||
74 | /** |
||
75 | * If no explicit keyboard is passed, try to create one from the parameters. |
||
76 | * |
||
77 | * @return array |
||
78 | */ |
||
79 | 18 | protected function createFromParams() |
|
116 | |||
117 | /** |
||
118 | * Create a new row in keyboard and add buttons. |
||
119 | * |
||
120 | * @return $this |
||
121 | */ |
||
122 | 2 | public function addRow() |
|
130 | |||
131 | /** |
||
132 | * Parse a given row to the correct array format. |
||
133 | * |
||
134 | * @param array $row |
||
135 | * |
||
136 | * @return array |
||
137 | */ |
||
138 | 15 | protected function parseRow($row) |
|
153 | |||
154 | /** |
||
155 | * Parse a given button to the correct KeyboardButton object type. |
||
156 | * |
||
157 | * @param array|string|\Longman\TelegramBot\Entities\KeyboardButton $button |
||
158 | * |
||
159 | * @return \Longman\TelegramBot\Entities\KeyboardButton|null |
||
160 | */ |
||
161 | 12 | protected function parseButton($button) |
|
175 | |||
176 | /** |
||
177 | * {@inheritdoc} |
||
178 | */ |
||
179 | 11 | View Code Duplication | protected function validate() |
195 | |||
196 | /** |
||
197 | * Hide the current custom keyboard and display the default letter-keyboard. |
||
198 | * |
||
199 | * @link https://core.telegram.org/bots/api#replykeyboardhide |
||
200 | * |
||
201 | * @param array $data |
||
202 | * |
||
203 | * @return \Longman\TelegramBot\Entities\Keyboard |
||
204 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
205 | */ |
||
206 | 1 | public static function hide(array $data = []) |
|
210 | |||
211 | /** |
||
212 | * Display a reply interface to the user (act as if the user has selected the bot's message and tapped 'Reply'). |
||
213 | * |
||
214 | * @link https://core.telegram.org/bots/api#forcereply |
||
215 | * |
||
216 | * @param array $data |
||
217 | * |
||
218 | * @return \Longman\TelegramBot\Entities\Keyboard |
||
219 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
220 | */ |
||
221 | 1 | public static function forceReply(array $data = []) |
|
225 | } |
||
226 |
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.