| Conditions | 18 |
| Paths | 24 |
| Total Lines | 60 |
| Code Lines | 43 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 63 | public static function easyKey(array $keyboard = [], array $inline = []): inlineKeyboardMarkup|replyKeyboardMarkup { |
||
| 64 | if (!empty($keyboard)) { |
||
| 65 | $keyboard_object = new replyKeyboardMarkup(); |
||
| 66 | $keyboard_object->setResize_keyboard($keyboard['resize'] ?? true); |
||
| 67 | if (isset($keyboard['one_time'])) { |
||
| 68 | $keyboard_object->setOne_time_keyboard($keyboard['one_time']) ; |
||
| 69 | } |
||
| 70 | foreach ($keyboard as $row) { |
||
| 71 | $buttons = []; |
||
| 72 | foreach ($row as $base_button) { |
||
| 73 | $button_info = explode('||', $base_button); |
||
| 74 | $button = new keyboardButton(); |
||
| 75 | $button->setText($button_info[0] ?? $base_button); |
||
| 76 | if (count($button_info) > 1) { |
||
| 77 | if ($button_info[1] === 'con') { |
||
| 78 | $button->setRequest_contact(true); |
||
| 79 | } |
||
| 80 | elseif ($button_info[1] === 'loc') { |
||
| 81 | $button->setRequest_location(true); |
||
| 82 | } |
||
| 83 | elseif ($button_info[1] === 'poll') { |
||
| 84 | $type = $button_info[2] === pollType::QUIZ ? pollType::QUIZ : pollType::REGULAR; |
||
| 85 | $button->setRequest_poll((new keyboardButtonPollType())->setType($type)); |
||
| 86 | } |
||
| 87 | elseif ($button_info[1] === 'web' && isset($button_info[2])) { |
||
| 88 | $url = $button_info[2]; |
||
| 89 | $button->setWeb_app((new webAppInfo())->setUrl($url)); |
||
| 90 | } |
||
| 91 | } |
||
| 92 | $buttons[] = $button; |
||
| 93 | } |
||
| 94 | $keyboard_object->setKeyboard([$buttons]); |
||
| 95 | } |
||
| 96 | return $keyboard_object; |
||
| 97 | } |
||
| 98 | elseif (!empty($inline)) { |
||
| 99 | $keyboard_object = new inlineKeyboardMarkup(); |
||
| 100 | foreach ($inline as $row) { |
||
| 101 | $buttons = []; |
||
| 102 | foreach ($row as $button_info) { |
||
| 103 | $button = new inlineKeyboardButton(); |
||
| 104 | if (isset($button_info[1])) { |
||
| 105 | if (filter_var($button_info[1], FILTER_VALIDATE_URL) && str_starts_with($button_info[1], 'http')) { |
||
| 106 | $button->setText($button_info[0])->setUrl($button_info[1]); |
||
| 107 | } |
||
| 108 | else { |
||
| 109 | $button->setText($button_info[0])->setCallback_data($button_info[1]); |
||
| 110 | } |
||
| 111 | } |
||
| 112 | else { |
||
| 113 | $button->setText($button_info[0])->setUrl('https://t.me/BPT_CH'); |
||
| 114 | } |
||
| 115 | } |
||
| 116 | $keyboard_object->setInline_keyboard([$buttons]); |
||
| 117 | } |
||
| 118 | return $keyboard_object; |
||
| 119 | } |
||
| 120 | else { |
||
| 121 | logger::write("tools::eKey function used\nkeyboard or inline parameter must be set",loggerTypes::ERROR); |
||
| 122 | throw new bptException('ARGUMENT_NOT_FOUND_KEYBOARD_INLINE'); |
||
| 123 | } |
||
| 125 | } |