Conditions | 1 |
Paths | 1 |
Total Lines | 73 |
Code Lines | 43 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
34 | public function execute() |
||
35 | { |
||
36 | $message = $this->getMessage(); |
||
37 | $chat_id = $message->getChat()->getId(); |
||
38 | |||
39 | $data = [ |
||
40 | 'chat_id' => $chat_id, |
||
41 | 'text' => 'Press a Button:', |
||
42 | ]; |
||
43 | |||
44 | //Keyboard examples |
||
45 | $keyboards = []; |
||
46 | |||
47 | //Example 0 |
||
48 | $keyboard = []; |
||
49 | $keyboard[] = ['7', '8', '9']; |
||
50 | $keyboard[] = ['4', '5', '6']; |
||
51 | $keyboard[] = ['1', '2', '3']; |
||
52 | $keyboard[] = [' ', '0', ' ']; |
||
53 | $keyboards[] = $keyboard; |
||
54 | |||
55 | //Example 1 |
||
56 | $keyboard = []; |
||
57 | $keyboard[] = ['7', '8', '9', '+']; |
||
58 | $keyboard[] = ['4', '5', '6', '-']; |
||
59 | $keyboard[] = ['1', '2', '3', '*']; |
||
60 | $keyboard[] = [' ', '0', ' ', '/']; |
||
61 | $keyboards[] = $keyboard; |
||
62 | |||
63 | //Example 2 |
||
64 | $keyboard = []; |
||
65 | $keyboard[] = ['A']; |
||
66 | $keyboard[] = ['B']; |
||
67 | $keyboard[] = ['C']; |
||
68 | $keyboards[] = $keyboard; |
||
69 | |||
70 | //Example 3 |
||
71 | $keyboard = []; |
||
72 | $keyboard[] = ['A']; |
||
73 | $keyboard[] = ['B']; |
||
74 | $keyboard[] = ['C', 'D']; |
||
75 | $keyboards[] = $keyboard; |
||
76 | |||
77 | //Example 4 (bots version 2.0) |
||
78 | $keyboard = []; |
||
79 | $keyboard[] = [ |
||
80 | [ |
||
81 | 'text' => 'Send my contact', |
||
82 | 'request_contact' => true, |
||
83 | ], |
||
84 | [ |
||
85 | 'text' => 'Send my location', |
||
86 | 'request_location' => true, |
||
87 | ], |
||
88 | ]; |
||
89 | $keyboards[] = $keyboard; |
||
90 | |||
91 | //Return a random keyboard. |
||
92 | $keyboard = $keyboards[mt_rand(0, count($keyboards) - 1)]; |
||
93 | $data['reply_markup'] = new ReplyKeyboardMarkup( |
||
94 | [ |
||
95 | 'keyboard' => $keyboard, |
||
96 | 'resize_keyboard' => true, |
||
97 | 'one_time_keyboard' => false, |
||
98 | 'selective' => false, |
||
99 | ] |
||
100 | ); |
||
101 | |||
102 | return Request::sendMessage($data); |
||
103 | } |
||
104 | } |
||
105 |