Passed
Push — main ( e1a2dc...e011f6 )
by Miaad
02:06
created

request::catchFields()   F

Complexity

Conditions 21
Paths 21

Size

Total Lines 139
Code Lines 122

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 122
dl 0
loc 139
rs 3.3333
c 0
b 0
f 0
cc 21
nc 21
nop 1

How to fix   Long Method    Complexity   

Long Method

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:

1
<?php
2
3
namespace BPT\api;
4
5
use BPT\api\request\answer;
6
use BPT\api\request\curl;
7
use BPT\BPT;
8
use BPT\constants\chatActions;
9
use BPT\constants\loggerTypes;
10
use BPT\logger;
11
use CURLFile;
12
13
class request {
14
    private const METHODS_ACTION = [
15
        'getupdates'                      => 'getUpdates',
16
        'getup'                           => 'getUpdates',
17
        'updates'                         => 'getUpdates',
18
        'setwebhook'                      => 'setWebhook',
19
        'setweb'                          => 'setWebhook',
20
        'webhook'                         => 'setWebhook',
21
        'deletewebhook'                   => 'deleteWebhook',
22
        'deleteweb'                       => 'deleteWebhook',
23
        'delweb'                          => 'deleteWebhook',
24
        'getwebhookinfo'                  => 'getWebhookInfo',
25
        'getweb'                          => 'getWebhookInfo',
26
        'getme'                           => 'getMe',
27
        'me'                              => 'getMe',
28
        'logout'                          => 'logOut',
29
        'close'                           => 'close',
30
        'sendmessage'                     => 'sendMessage',
31
        'send'                            => 'sendMessage',
32
        'forwardmessage'                  => 'forwardMessage',
33
        'forward'                         => 'forwardMessage',
34
        'copymessage'                     => 'copyMessage',
35
        'copy'                            => 'copyMessage',
36
        'sendphoto'                       => 'sendPhoto',
37
        'photo'                           => 'sendPhoto',
38
        'sendaudio'                       => 'sendAudio',
39
        'audio'                           => 'sendAudio',
40
        'senddocument'                    => 'sendDocument',
41
        'senddoc'                         => 'sendDocument',
42
        'document'                        => 'sendDocument',
43
        'doc'                             => 'sendDocument',
44
        'sendvideo'                       => 'sendVideo',
45
        'video'                           => 'sendVideo',
46
        'sendanimation'                   => 'sendAnimation',
47
        'animation'                       => 'sendAnimation',
48
        'sendgif'                         => 'sendAnimation',
49
        'gif'                             => 'sendAnimation',
50
        'sendvoice'                       => 'sendVoice',
51
        'voice'                           => 'sendVoice',
52
        'sendvideonote'                   => 'sendVideoNote',
53
        'videonote'                       => 'sendVideoNote',
54
        'sendmediagroup'                  => 'sendMediaGroup',
55
        'mediagroup'                      => 'sendMediaGroup',
56
        'media'                           => 'sendMediaGroup',
57
        'sendlocation'                    => 'sendLocation',
58
        'sendloc'                         => 'sendLocation',
59
        'location'                        => 'sendLocation',
60
        'loc'                             => 'sendLocation',
61
        'editmessagelivelocation'         => 'editMessageLiveLocation',
62
        'editliveloc'                     => 'editMessageLiveLocation',
63
        'stopmessagelivelocation'         => 'stopMessageLiveLocation',
64
        'stopliveloc'                     => 'stopMessageLiveLocation',
65
        'sendvenue'                       => 'sendVenue',
66
        'venue'                           => 'sendVenue',
67
        'sendcontact'                     => 'sendContact',
68
        'contact'                         => 'sendContact',
69
        'sendpoll'                        => 'sendPoll',
70
        'poll'                            => 'sendPoll',
71
        'senddice'                        => 'sendDice',
72
        'dice'                            => 'sendDice',
73
        'sendchataction'                  => 'sendChatAction',
74
        'chataction'                      => 'sendChatAction',
75
        'action'                          => 'sendChatAction',
76
        'getuserprofilephotos'            => 'getUserProfilePhotos',
77
        'userphotos'                      => 'getUserProfilePhotos',
78
        'getfile'                         => 'getFile',
79
        'file'                            => 'getFile',
80
        'banchatmember'                   => 'banChatMember',
81
        'ban'                             => 'banChatMember',
82
        'kickchatmember'                  => 'banChatMember',
83
        'kick'                            => 'unbanChatMember',
84
        'unbanchatmember'                 => 'unbanChatMember',
85
        'unban'                           => 'unbanChatMember',
86
        'restrictchatmember'              => 'restrictChatMember',
87
        'restrict'                        => 'restrictChatMember',
88
        'promotechatmember'               => 'promoteChatMember',
89
        'promote'                         => 'promoteChatMember',
90
        'setchatadministratorcustomtitle' => 'setChatAdministratorCustomTitle',
91
        'customtitle'                     => 'setChatAdministratorCustomTitle',
92
        'banchatsenderchat'               => 'banChatSenderChat',
93
        'bansender'                       => 'banChatSenderChat',
94
        'unbanchatsenderchat'             => 'unbanChatSenderChat',
95
        'unbansender'                     => 'unbanChatSenderChat',
96
        'setchatpermissions'              => 'setChatPermissions',
97
        'permissions'                     => 'setChatPermissions',
98
        'exportchatinvitelink'            => 'exportChatInviteLink',
99
        'link'                            => 'exportChatInviteLink',
100
        'createchatinvitelink'            => 'createChatInviteLink',
101
        'crlink'                          => 'createChatInviteLink',
102
        'editchatinvitelink'              => 'editChatInviteLink',
103
        'edlink'                          => 'editChatInviteLink',
104
        'revokechatinvitelink'            => 'revokeChatInviteLink',
105
        'relink'                          => 'revokeChatInviteLink',
106
        'approvechatjoinrequest'          => 'approveChatJoinRequest',
107
        'acceptjoin'                      => 'approveChatJoinRequest',
108
        'declinechatjoinrequest'          => 'declineChatJoinRequest',
109
        'denyjoin'                        => 'declineChatJoinRequest',
110
        'setchatphoto'                    => 'setChatPhoto',
111
        'deletechatphoto'                 => 'deleteChatPhoto',
112
        'setchattitle'                    => 'setChatTitle',
113
        'title'                           => 'setChatTitle',
114
        'setchatdescription'              => 'setChatDescription',
115
        'description'                     => 'setChatDescription',
116
        'pinchatmessage'                  => 'pinChatMessage',
117
        'pin'                             => 'pinChatMessage',
118
        'unpinchatmessage'                => 'unpinChatMessage',
119
        'unpin'                           => 'unpinChatMessage',
120
        'unpinallchatmessages'            => 'unpinAllChatMessages',
121
        'unpinall'                        => 'unpinAllChatMessages',
122
        'leavechat'                       => 'leaveChat',
123
        'leave'                           => 'leaveChat',
124
        'getchat'                         => 'getChat',
125
        'chat'                            => 'getChat',
126
        'getchatadministrators'           => 'getChatAdministrators',
127
        'admins'                          => 'getChatAdministrators',
128
        'getchatmembercount'              => 'getChatMemberCount',
129
        'getchatmemberscount'             => 'getChatMemberCount',
130
        'memberscount'                    => 'getChatMemberCount',
131
        'getchatmember'                   => 'getChatMember',
132
        'member'                          => 'getChatMember',
133
        'setchatstickerset'               => 'setChatStickerSet',
134
        'setsticker'                      => 'setChatStickerSet',
135
        'deletechatstickerset'            => 'deleteChatStickerSet',
136
        'delsticker'                      => 'deleteChatStickerSet',
137
        'answercallbackquery'             => 'answerCallbackQuery',
138
        'answer'                          => 'answerCallbackQuery',
139
        'setmycommands'                   => 'setMyCommands',
140
        'setcommands'                     => 'setMyCommands',
141
        'deletemycommands'                => 'deleteMyCommands',
142
        'deletecommands'                  => 'deleteMyCommands',
143
        'getmycommands'                   => 'getMyCommands',
144
        'getcommands'                     => 'getMyCommands',
145
        'setchatmenubutton'               => 'setChatMenuButton',
146
        'setmenubutton'                   => 'setChatMenuButton',
147
        'setmenu'                         => 'setChatMenuButton',
148
        'setbutton'                       => 'setChatMenuButton',
149
        'getchatmenubutton'               => 'getChatMenuButton',
150
        'getmenubutton'                   => 'getChatMenuButton',
151
        'getmenu'                         => 'getChatMenuButton',
152
        'getbutton'                       => 'getChatMenuButton',
153
        'setmydefaultadministratorrights' => 'setMyDefaultAdministratorRights',
154
        'setmydefaultadminrights'         => 'setMyDefaultAdministratorRights',
155
        'setmydefaultrights'              => 'setMyDefaultAdministratorRights',
156
        'setdefaultrights'                => 'setMyDefaultAdministratorRights',
157
        'getmydefaultadministratorrights' => 'getMyDefaultAdministratorRights',
158
        'getmydefaultadminrights'         => 'getMyDefaultAdministratorRights',
159
        'getmydefaultrights'              => 'getMyDefaultAdministratorRights',
160
        'getdefaultrights'                => 'getMyDefaultAdministratorRights',
161
        'editmessagetext'                 => 'editMessageText',
162
        'edittext'                        => 'editMessageText',
163
        'editmessagecaption'              => 'editMessageCaption',
164
        'editcap'                         => 'editMessageCaption',
165
        'editcaption'                     => 'editMessageCaption',
166
        'editmessagemedia'                => 'editMessageMedia',
167
        'editmedia'                       => 'editMessageMedia',
168
        'editmessagereplymarkup'          => 'editMessageReplyMarkup',
169
        'editreply'                       => 'editMessageReplyMarkup',
170
        'editkeyboard'                    => 'editMessageReplyMarkup',
171
        'stoppoll'                        => 'stopPoll',
172
        'deletemessage'                   => 'deleteMessage',
173
        'del'                             => 'deleteMessage',
174
        'sendsticker'                     => 'sendSticker',
175
        'sticker'                         => 'sendSticker',
176
        'getstickerset'                   => 'getStickerSet',
177
        'uploadstickerfile'               => 'uploadStickerFile',
178
        'uploadsticker'                   => 'uploadStickerFile',
179
        'createnewstickerset'             => 'createNewStickerSet',
180
        'createsticker'                   => 'createNewStickerSet',
181
        'addstickertoset'                 => 'addStickerToSet',
182
        'addsticker'                      => 'addStickerToSet',
183
        'setstickerpositioninset'         => 'setStickerPositionInSet',
184
        'setstickerposition'              => 'setStickerPositionInSet',
185
        'setstickerpos'                   => 'setStickerPositionInSet',
186
        'deletestickerfromset'            => 'deleteStickerFromSet',
187
        'deletesticker'                   => 'deleteStickerFromSet',
188
        'setstickersetthumb'              => 'setStickerSetThumb',
189
        'setstickerthumb'                 => 'setStickerSetThumb',
190
        'answerinlinequery'               => 'answerInlineQuery',
191
        'answerinline'                    => 'answerInlineQuery',
192
        'answerwebappquery'               => 'answerWebAppQuery',
193
        'answerwebapp'                    => 'answerWebAppQuery',
194
        'answerweb'                       => 'answerWebAppQuery',
195
        'sendinvoice'                     => 'sendInvoice',
196
        'invoice'                         => 'sendInvoice',
197
        'createinvoicelink'               => 'createInvoiceLink',
198
        'createinvoice'                   => 'sendInvoice',
199
        'answershippingquery'             => 'answerShippingQuery',
200
        'answershipping'                  => 'answerShippingQuery',
201
        'answerprecheckoutquery'          => 'answerPreCheckoutQuery',
202
        'answerprecheckout'               => 'answerPreCheckoutQuery',
203
        'answerprecheck'                  => 'answerPreCheckoutQuery',
204
        'setpassportdataerrors'           => 'setPassportDataErrors',
205
        'setpassport'                     => 'setPassportDataErrors',
206
        'sendgame'                        => 'sendGame',
207
        'game'                            => 'sendGame',
208
        'setgamescore'                    => 'setGameScore',
209
        'gamescore'                       => 'setGameScore',
210
        'getgamehighscores'               => 'getGameHighScores',
211
        'getgamehigh'                     => 'getGameHighScores'
212
    ];
213
214
    private const METHODS_KEYS = [
215
        'getUpdates'                      => ['offset','limit','timeout','allowed_updates','token','return_array','forgot','answer'],
216
        'setWebhook'                      => ['url','certificate','ip_address','max_connections','allowed_updates','drop_pending_updates','secret_token','token','return_array','forgot','answer'],
217
        'deleteWebhook'                   => ['drop_pending_updates','token','return_array','forgot','answer'],
218
        'getWebhookInfo'                  => ['token','return_array','forgot','answer'],
219
        'getMe'                           => ['token','return_array','forgot','answer'],
220
        'logOut'                          => ['token','return_array','forgot','answer'],
221
        'close'                           => ['token','return_array','forgot','answer'],
222
        'sendMessage'                     => ['text','chat_id','parse_mode','entities','disable_web_page_preview','disable_notification','protect_content','reply_to_message_id','allow_sending_without_reply','reply_markup','token','return_array','forgot','answer'],
223
        'forwardMessage'                  => ['chat_id','from_chat_id','disable_notification','protect_content','message_id','token','return_array','forgot','answer'],
224
        'copyMessage'                     => ['chat_id','from_chat_id','message_id','caption','parse_mode','caption_entities','disable_notification','protect_content','reply_to_message_id','allow_sending_without_reply','reply_markup','token','return_array','forgot','answer'],
225
        'sendPhoto'                       => ['photo','chat_id','caption','parse_mode','caption_entities','disable_notification','protect_content','reply_to_message_id','allow_sending_without_reply','reply_markup','token','return_array','forgot','answer'],
226
        'sendAudio'                       => ['audio','chat_id','caption','parse_mode','caption_entities','duration','performer','title','thumb','disable_notification','protect_content','reply_to_message_id','allow_sending_without_reply','reply_markup','token','return_array','forgot','answer'],
227
        'sendDocument'                    => ['document','chat_id','thumb','caption','parse_mode','caption_entities','disable_content_type_detection','disable_notification','protect_content','reply_to_message_id','allow_sending_without_reply','reply_markup','token','return_array','forgot','answer'],
228
        'sendVideo'                       => ['video','chat_id','duration','width','height','thumb','caption','parse_mode','caption_entities','supports_streaming','disable_notification','protect_content','reply_to_message_id','allow_sending_without_reply','reply_markup','token','return_array','forgot','answer'],
229
        'sendAnimation'                   => ['animation','chat_id','duration','width','height','thumb','caption','parse_mode','caption_entities','disable_notification','protect_content','reply_to_message_id','allow_sending_without_reply','reply_markup','token','return_array','forgot','answer'],
230
        'sendVoice'                       => ['voice','chat_id','caption','parse_mode','caption_entities','duration','disable_notification','protect_content','reply_to_message_id','allow_sending_without_reply','reply_markup','token','return_array','forgot','answer'],
231
        'sendVideoNote'                   => ['video_note','chat_id','duration','length','thumb','disable_notification','protect_content','reply_to_message_id','allow_sending_without_reply','reply_markup','token','return_array','forgot','answer'],
232
        'sendMediaGroup'                  => ['media','chat_id','disable_notification','protect_content','reply_to_message_id','allow_sending_without_reply','token','return_array','forgot','answer'],
233
        'sendLocation'                    => ['latitude','longitude','chat_id','horizontal_accuracy','live_period','heading','proximity_alert_radius','disable_notification','protect_content','reply_to_message_id','allow_sending_without_reply','reply_markup','token','return_array','forgot','answer'],
234
        'editMessageLiveLocation'         => ['latitude','longitude','chat_id','message_id','inline_message_id','horizontal_accuracy','heading','proximity_alert_radius','reply_markup','token','return_array','forgot','answer'],
235
        'stopMessageLiveLocation'         => ['chat_id','message_id','inline_message_id','reply_markup','token','return_array','forgot','answer'],
236
        'sendVenue'                       => ['chat_id','latitude','longitude','title','address','foursquare_id','foursquare_type','google_place_id','google_place_type','disable_notification','protect_content','reply_to_message_id','allow_sending_without_reply','reply_markup','token','return_array','forgot','answer'],
237
        'sendContact'                     => ['phone_number','first_name','chat_id','last_name','vcard','disable_notification','protect_content','reply_to_message_id','allow_sending_without_reply','reply_markup','token','return_array','forgot','answer'],
238
        'sendPoll'                        => ['question','options','chat_id','is_anonymous','type','allows_multiple_answers','correct_option_id','explanation','explanation_parse_mode','explanation_entities','open_period','close_date','is_closed','disable_notification','protect_content','reply_to_message_id','allow_sending_without_reply','reply_markup','token','return_array','forgot','answer'],
239
        'sendDice'                        => ['chat_id','emoji','disable_notification','protect_content','reply_to_message_id','allow_sending_without_reply','reply_markup','token','return_array','forgot','answer'],
240
        'sendChatAction'                  => ['chat_id','action','token','return_array','forgot','answer'],
241
        'getUserProfilePhotos'            => ['user_id','offset','limit','token','return_array','forgot','answer'],
242
        'getFile'                         => ['file_id','token','return_array','forgot','answer'],
243
        'banChatMember'                   => ['chat_id','user_id','until_date','revoke_messages','token','return_array','forgot','answer'],
244
        'unbanChatMember'                 => ['chat_id','user_id','only_if_banned','token','return_array','forgot','answer'],
245
        'restrictChatMember'              => ['permissions','chat_id','user_id','until_date','token','return_array','forgot','answer'],
246
        'promoteChatMember'               => ['chat_id','user_id','is_anonymous','can_manage_chat','can_post_messages','can_edit_messages','can_delete_messages','can_manage_video_chats','can_restrict_members','can_promote_members','can_change_info','can_invite_users','can_pin_messages','token','return_array','forgot','answer'],
247
        'setChatAdministratorCustomTitle' => ['custom_title','chat_id','user_id','token','return_array','forgot','answer'],
248
        'banChatSenderChat'               => ['sender_chat_id','chat_id','token','return_array','forgot','answer'],
249
        'unbanChatSenderChat'             => ['sender_chat_id','chat_id','token','return_array','forgot','answer'],
250
        'setChatPermissions'              => ['permissions','chat_id','token','return_array','forgot','answer'],
251
        'exportChatInviteLink'            => ['chat_id','token','return_array','forgot','answer'],
252
        'createChatInviteLink'            => ['chat_id','name','expire_date','member_limit','creates_join_request','token','return_array','forgot','answer'],
253
        'editChatInviteLink'              => ['invite_link','chat_id','name','expire_date','member_limit','creates_join_request','token','return_array','forgot','answer'],
254
        'revokeChatInviteLink'            => ['invite_link','chat_id','token','return_array','forgot','answer'],
255
        'approveChatJoinRequest'          => ['chat_id','user_id','token','return_array','forgot','answer'],
256
        'declineChatJoinRequest'          => ['chat_id','user_id','token','return_array','forgot','answer'],
257
        'setChatPhoto'                    => ['photo','chat_id','token','return_array','forgot','answer'],
258
        'deleteChatPhoto'                 => ['chat_id','token','return_array','forgot','answer'],
259
        'setChatTitle'                    => ['title','chat_id','token','return_array','forgot','answer'],
260
        'setChatDescription'              => ['chat_id','description','token','return_array','forgot','answer'],
261
        'pinChatMessage'                  => ['message_id','chat_id','disable_notification','token','return_array','forgot','answer'],
262
        'unpinChatMessage'                => ['chat_id','message_id','token','return_array','forgot','answer'],
263
        'unpinAllChatMessages'            => ['chat_id','token','return_array','forgot','answer'],
264
        'leaveChat'                       => ['chat_id','token','return_array','forgot','answer'],
265
        'getChat'                         => ['chat_id','token','return_array','forgot','answer'],
266
        'getChatAdministrators'           => ['chat_id','token','return_array','forgot','answer'],
267
        'getChatMemberCount'              => ['chat_id','token','return_array','forgot','answer'],
268
        'getChatMember'                   => ['chat_id','user_id','token','return_array','forgot','answer'],
269
        'setChatStickerSet'               => ['sticker_set_name','chat_id','token','return_array','forgot','answer'],
270
        'deleteChatStickerSet'            => ['chat_id','token','return_array','forgot','answer'],
271
        'answerCallbackQuery'             => ['callback_query_id','text','show_alert','url','cache_time','token','return_array','forgot','answer'],
272
        'setMyCommands'                   => ['commands','scope','language_code','token','return_array','forgot','answer'],
273
        'deleteMyCommands'                => ['scope','language_code','token','return_array','forgot','answer'],
274
        'getMyCommands'                   => ['scope','language_code','token','return_array','forgot','answer'],
275
        'setChatMenuButton'               => ['chat_id','menu_button','token','return_array','forgot','answer'],
276
        'getChatMenuButton'               => ['chat_id','token','return_array','forgot','answer'],
277
        'setMyDefaultAdministratorRights' => ['rights','for_channels','token','return_array','forgot','answer'],
278
        'getMyDefaultAdministratorRights' => ['for_channels','token','return_array','forgot','answer'],
279
        'editMessageText'                 => ['text','chat_id','message_id','inline_message_id','parse_mode','entities','disable_web_page_preview','reply_markup','token','return_array','forgot','answer'],
280
        'editMessageCaption'              => ['chat_id','message_id','inline_message_id','caption','parse_mode','caption_entities','reply_markup','token','return_array','forgot','answer'],
281
        'editMessageMedia'                => ['media','chat_id','message_id','inline_message_id','reply_markup','token','return_array','forgot','answer'],
282
        'editMessageReplyMarkup'          => ['chat_id','message_id','inline_message_id','reply_markup','token','return_array','forgot','answer'],
283
        'stopPoll'                        => ['chat_id','message_id','reply_markup','token','return_array','forgot','answer'],
284
        'deleteMessage'                   => ['chat_id','message_id','token','return_array','forgot','answer'],
285
        'sendSticker'                     => ['sticker','chat_id','disable_notification','protect_content','reply_to_message_id','allow_sending_without_reply','reply_markup','token','return_array','forgot','answer'],
286
        'getStickerSet'                   => ['name','token','return_array','forgot','answer'],
287
        'uploadStickerFile'               => ['png_sticker','user_id','token','return_array','forgot','answer'],
288
        'createNewStickerSet'             => ['name','title','emojis','user_id','png_sticker','tgs_sticker','webm_sticker','contains_masks','mask_position','token','return_array','forgot','answer'],
289
        'addStickerToSet'                 => ['name','emojis','user_id','png_sticker','tgs_sticker','webm_sticker','mask_position','token','return_array','forgot','answer'],
290
        'setStickerPositionInSet'         => ['sticker','position','token','return_array','forgot','answer'],
291
        'deleteStickerFromSet'            => ['sticker','token','return_array','forgot','answer'],
292
        'setStickerSetThumb'              => ['name','user_id','thumb','token','return_array','forgot','answer'],
293
        'answerInlineQuery'               => ['results','inline_query_id','cache_time','is_personal','next_offset','switch_pm_text','switch_pm_parameter','token','return_array','forgot','answer'],
294
        'answerWebAppQuery'               => ['web_app_query_id','result','token','return_array','forgot','answer'],
295
        'sendInvoice'                     => ['title','description','payload','provider_token','currency','prices','chat_id','max_tip_amount','suggested_tip_amounts','start_parameter','provider_data','photo_url','photo_size','photo_width','photo_height','need_name','need_phone_number','need_email','need_shipping_address','send_phone_number_to_provider','send_email_to_provider','is_flexible','disable_notification','protect_content','reply_to_message_id','allow_sending_without_reply','reply_markup','token','return_array','forgot','answer'],
296
        'createInvoiceLink'               => ['title','description','payload','provider_token','currency','prices','max_tip_amount','suggested_tip_amounts','provider_data','photo_url','photo_size','photo_width','photo_height','need_name','need_phone_number','need_email','need_shipping_address','send_phone_number_to_provider','send_email_to_provider','is_flexible','token','return_array','forgot','answer'],
297
        'answerShippingQuery'             => ['ok','shipping_query_id','shipping_options','error_message','token','return_array','forgot','answer'],
298
        'answerPreCheckoutQuery'          => ['ok','pre_checkout_query_id','error_message','token','return_array','forgot','answer'],
299
        'setPassportDataErrors'           => ['errors','user_id','token','return_array','forgot','answer'],
300
        'sendGame'                        => ['game_short_name','chat_id','disable_notification','protect_content','reply_to_message_id','allow_sending_without_reply','reply_markup','token','return_array','forgot','answer'],
301
        'setGameScore'                    => ['score','user_id','force','disable_edit_message','chat_id','message_id','inline_message_id','token','return_array','forgot','answer'],
302
        'getGameHighScores'               => ['user_id','chat_id','message_id','inline_message_id','token','return_array','forgot','answer'],
303
    ];
304
305
    private const METHODS_WITH_FILE = [
306
        'setWebhook'          => ['certificate'],
307
        'sendPhoto'           => ['photo'],
308
        'sendAudio'           => ['audio', 'thumb'],
309
        'sendDocument'        => ['document', 'thumb'],
310
        'sendVideo'           => ['video', 'thumb'],
311
        'sendAnimation'       => ['animation', 'thumb'],
312
        'sendVoice'           => ['voice', 'thumb'],
313
        'sendVideoNote'       => ['video_note', 'thumb'],
314
        'setChatPhoto'        => ['photo'],
315
        'sendSticker'         => ['sticker'],
316
        'uploadStickerFile'   => ['png_sticker'],
317
        'createNewStickerSet' => ['png_sticker', 'tgs_sticker'],
318
        'addStickerToSet'     => ['png_sticker', 'tgs_sticker'],
319
        'setStickerSetThumb'  => ['thumb'],
320
    ];
321
322
    private const METHODS_EXTRA_DEFAULTS = [
323
        'getUpdates'                      => [],
324
        'setWebhook'                      => ['url'],
325
        'deleteWebhook'                   => [],
326
        'getWebhookInfo'                  => [],
327
        'getMe'                           => [],
328
        'logOut'                          => [],
329
        'close'                           => [],
330
        'sendMessage'                     => ['chat_id'],
331
        'forwardMessage'                  => ['from_chat_id','message_id'],
332
        'copyMessage'                     => ['from_chat_id','message_id'],
333
        'sendPhoto'                       => ['chat_id'],
334
        'sendAudio'                       => ['chat_id'],
335
        'sendDocument'                    => ['chat_id'],
336
        'sendVideo'                       => ['chat_id'],
337
        'sendAnimation'                   => ['chat_id'],
338
        'sendVoice'                       => ['chat_id'],
339
        'sendVideoNote'                   => ['chat_id'],
340
        'sendMediaGroup'                  => ['chat_id'],
341
        'sendLocation'                    => ['chat_id'],
342
        'editMessageLiveLocation'         => [],
343
        'stopMessageLiveLocation'         => [],
344
        'sendVenue'                       => [],
345
        'sendContact'                     => ['chat_id'],
346
        'sendPoll'                        => ['chat_id'],
347
        'sendDice'                        => ['chat_id'],
348
        'sendChatAction'                  => ['chat_id','action'],
349
        'getUserProfilePhotos'            => ['user_id'],
350
        'getFile'                         => ['file_id'],
351
        'banChatMember'                   => ['chat_id','user_id'],
352
        'kickChatMember'                  => ['chat_id','user_id'],
353
        'unbanChatMember'                 => ['chat_id','user_id'],
354
        'restrictChatMember'              => ['chat_id','user_id'],
355
        'promoteChatMember'               => ['chat_id','user_id'],
356
        'setChatAdministratorCustomTitle' => ['chat_id','user_id'],
357
        'banChatSenderChat'               => ['chat_id'],
358
        'unbanChatSenderChat'             => ['chat_id'],
359
        'setChatPermissions'              => ['chat_id'],
360
        'exportChatInviteLink'            => ['chat_id'],
361
        'createChatInviteLink'            => ['chat_id'],
362
        'editChatInviteLink'              => ['chat_id'],
363
        'revokeChatInviteLink'            => ['chat_id'],
364
        'approveChatJoinRequest'          => ['chat_id','user_id'],
365
        'declineChatJoinRequest'          => ['chat_id','user_id'],
366
        'setChatPhoto'                    => ['chat_id'],
367
        'deleteChatPhoto'                 => ['chat_id'],
368
        'setChatTitle'                    => ['chat_id'],
369
        'setChatDescription'              => ['chat_id'],
370
        'pinChatMessage'                  => ['chat_id'],
371
        'unpinChatMessage'                => ['chat_id'],
372
        'unpinAllChatMessages'            => ['chat_id'],
373
        'leaveChat'                       => ['chat_id'],
374
        'getChat'                         => ['chat_id'],
375
        'getChatAdministrators'           => ['chat_id'],
376
        'getChatMembersCount'             => ['chat_id'],
377
        'getChatMember'                   => ['chat_id','user_id'],
378
        'setChatStickerSet'               => ['chat_id'],
379
        'deleteChatStickerSet'            => ['chat_id'],
380
        'answerCallbackQuery'             => ['callback_query_id'],
381
        'setMyCommands'                   => [],
382
        'deleteMyCommands'                => [],
383
        'getMyCommands'                   => [],
384
        'setChatMenuButton'               => [],
385
        'getChatMenuButton'               => [],
386
        'setMyDefaultAdministratorRights' => [],
387
        'getMyDefaultAdministratorRights' => [],
388
        'editMessageText'                 => ['inline_query'=>['inline_message_id'],'other'=>['chat_id','message_id']],
389
        'editMessageCaption'              => ['inline_query'=>['inline_message_id'],'other'=>['chat_id','message_id']],
390
        'editMessageMedia'                => ['inline_query'=>['inline_message_id'],'other'=>['chat_id','message_id']],
391
        'editMessageReplyMarkup'          => ['inline_query'=>['inline_message_id'],'other'=>['chat_id','message_id']],
392
        'stopPoll'                        => ['chat_id','message_id'],
393
        'deleteMessage'                   => ['chat_id','message_id'],
394
        'sendSticker'                     => ['chat_id'],
395
        'getStickerSet'                   => [],
396
        'uploadStickerFile'               => ['user_id'],
397
        'createNewStickerSet'             => ['user_id'],
398
        'addStickerToSet'                 => ['user_id'],
399
        'setStickerPositionInSet'         => [],
400
        'deleteStickerFromSet'            => [],
401
        'setStickerSetThumb'              => ['user_id'],
402
        'answerInlineQuery'               => ['inline_query_id'],
403
        'sendInvoice'                     => ['chat_id'],
404
        'answerWebAppQuery'               => [],
405
        'answerShippingQuery'             => ['shipping_query_id'],
406
        'answerPreCheckoutQuery'          => ['pre_checkout_query_id'],
407
        'setPassportDataErrors'           => ['user_id'],
408
        'sendGame'                        => ['chat_id'],
409
        'setGameScore'                    => ['user_id','inline_query'=>['inline_message_id'],'other'=>['chat_id','message_id']],
410
        'getGameHighScores'               => ['user_id','inline_query'=>['inline_message_id'],'other'=>['chat_id','message_id']]
411
    ];
412
413
414
    public static function __callStatic (string $name, array $arguments) {
415
        if ($action = self::methodAction($name)) {
416
            self::keysName($action,$arguments);
417
            self::readyFile($action,$arguments);
418
            self::setDefaults($action,$arguments);
0 ignored issues
show
Bug introduced by
The method setDefaults() does not exist on BPT\api\request. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

418
            self::/** @scrutinizer ignore-call */ setDefaults($action,$arguments);
Loading history...
419
            if (isset($arguments['answer'])) {
420
                return answer::init($action,$arguments);
421
            }
422
            else {
423
                return curl::init($action,$arguments);
424
            }
425
        }
426
        else {
427
            logger::write("$name method is not supported",loggerTypes::ERROR);
428
        }
429
    }
430
431
    private static function keysName (string $name, array &$arguments) {
432
        foreach ($arguments as $key => $argument) {
433
            if (is_numeric($key) && isset(self::METHODS_KEYS[$name][$key])) {
434
                $arguments[self::METHODS_KEYS[$name][$key]] = $argument;
435
                unset($arguments[$key]);
436
            }
437
        }
438
    }
439
440
    private static function methodAction(string $name): string|false {
441
        return self::METHODS_ACTION[str_replace('_', '', strtolower($name))] ?? false;
442
    }
443
444
    private static function readyFile(string $name, array &$arguments) {
445
        if ($name === 'sendMediaGroup') {
446
            foreach ($arguments['media'] as $key => $media) {
447
                if (file_exists($media['media'])) {
448
                    $arguments['media'][$key]['media'] = new CURLFile($media['media']);
449
                }
450
            }
451
        }
452
        elseif ($file_params = self::methodFile($name)) {
453
            foreach ($file_params as $param) {
454
                if (isset($arguments[$param]) && file_exists($arguments[$param])) {
455
                    $arguments[$param] = new CURLFile($arguments[$param]);
456
                }
457
            }
458
        }
459
    }
460
461
    private static function methodFile(string $name): array|false {
462
        return self::METHODS_WITH_FILE[$name] ?? false;
463
    }
464
465
    private static function setDefaults(string $name, array &$arguments) {
466
        $defaults = self::METHODS_EXTRA_DEFAULTS[$name];
0 ignored issues
show
Bug introduced by
The constant BPT\api\request::METHODS_EXTRA_DEFAULTS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
467
        foreach ($defaults as $key => $default) {
468
            if (is_numeric($key)) {
469
                if (!isset($arguments[$default])){
470
                    $arguments[$default] = self::catchFields($default);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $arguments[$default] is correct as self::catchFields($default) targeting BPT\api\request::__callStatic() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Bug introduced by
The method catchFields() does not exist on BPT\api\request. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

470
                    /** @scrutinizer ignore-call */ $arguments[$default] = self::catchFields($default);
Loading history...
471
                }
472
            }
473
            elseif (isset(BPT::$update->$key) || $key === 'other') {
474
                foreach ($default as $def) {
475
                    if (!isset($arguments[$def])){
476
                        $arguments[$def] = self::catchFields($def);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $arguments[$def] is correct as self::catchFields($def) targeting BPT\api\request::__callStatic() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
477
                    }
478
                }
479
                break;
480
            }
481
        }
482
    }
483
484
    public static function catchFields (string $field): int|string|bool {
485
        switch ($field) {
486
            case 'chat_id' :
487
            case 'from_chat_id' :
488
                return match (true) {
489
                    isset(BPT::$update->message) => BPT::$update->message->chat->id,
490
                    isset(BPT::$update->edited_message) => BPT::$update->edited_message->chat->id,
491
                    isset(BPT::$update->inline_query) => BPT::$update->inline_query->from->id,
492
                    isset(BPT::$update->callback_query) => BPT::$update->callback_query->from->id,
493
                    isset(BPT::$update->chat_join_request) => BPT::$update->chat_join_request->chat->id,
494
                    default => false
495
                };
496
            case 'user_id' :
497
                return match(true) {
498
                    isset(BPT::$update->message) => BPT::$update->message->from->id,
499
                    isset(BPT::$update->edited_message) => BPT::$update->edited_message->from->id,
500
                    isset(BPT::$update->inline_query) => BPT::$update->inline_query->from->id,
501
                    isset(BPT::$update->callback_query) => BPT::$update->callback_query->from->id,
502
                    isset(BPT::$update->chat_join_request) => BPT::$update->chat_join_request->from->id,
503
                    default => false
504
                };
505
            case 'message_id' :
506
                return match(true) {
507
                    isset(BPT::$update->message) => BPT::$update->message->message_id,
508
                    isset(BPT::$update->edited_message) => BPT::$update->edited_message->message_id,
509
                    isset(BPT::$update->callback_query) => BPT::$update->callback_query->message->message_id,
510
                    default => false
511
                };
512
            case 'file_id' :
513
                if (isset(BPT::$update->message)) $type = 'message';
514
                elseif (isset(BPT::$update->edited_message)) $type = 'edited_message';
515
                else return false;
516
517
                return match(true) {
518
                    isset(BPT::$update->$type->animation) => BPT::$update->$type->animation->file_id,
519
                    isset(BPT::$update->$type->audio) => BPT::$update->$type->audio->file_id,
520
                    isset(BPT::$update->$type->document) => BPT::$update->$type->document->file_id,
521
                    isset(BPT::$update->$type->photo) => end(BPT::$update->$type->photo)->file_id,
522
                    isset(BPT::$update->$type->sticker) => BPT::$update->$type->sticker->file_id,
523
                    isset(BPT::$update->$type->video) => BPT::$update->$type->video->file_id,
524
                    isset(BPT::$update->$type->video_note) => BPT::$update->$type->video_note->file_id,
525
                    isset(BPT::$update->$type->voice) => BPT::$update->$type->voice->file_id,
526
                    default => false
527
                };
528
            case 'callback_query_id' :
529
                return match (true) {
530
                    isset(BPT::$update->callback_query) => BPT::$update->callback_query->id,
531
                    default => false
532
                };
533
            case 'shipping_query_id' :
534
                return match(true) {
535
                    isset(BPT::$update->shipping_query) => BPT::$update->shipping_query->id,
536
                    default => false
537
                };
538
            case 'pre_checkout_query_id' :
539
                return match(true) {
540
                    isset(BPT::$update->pre_checkout_query) => BPT::$update->pre_checkout_query->id,
541
                    default => false
542
                };
543
            case 'inline_query_id' :
544
                return match(true) {
545
                    isset(BPT::$update->inline_query) => BPT::$update->inline_query->id,
546
                    default => false
547
                };
548
            case 'type' :
549
                return match(true) {
550
                    isset(BPT::$update->message) => BPT::$update->message->chat->type,
551
                    isset(BPT::$update->edited_message) => BPT::$update->edited_message->chat->type,
552
                    isset(BPT::$update->inline_query) => BPT::$update->inline_query->chat_type,
553
                    isset(BPT::$update->callback_query) => BPT::$update->callback_query->message->chat->type,
554
                    default => false
555
                };
556
            case 'action' :
557
                return chatActions::TYPING;
558
            case 'name' :
559
                return match(true) {
560
                    isset(BPT::$update->message) => BPT::$update->message->from->first_name,
561
                    isset(BPT::$update->edited_message) => BPT::$update->edited_message->from->first_name,
562
                    isset(BPT::$update->inline_query) => BPT::$update->inline_query->from->first_name,
563
                    isset(BPT::$update->callback_query) => BPT::$update->callback_query->from->first_name,
564
                    isset(BPT::$update->chat_join_request) => BPT::$update->chat_join_request->from->first_name,
565
                    default => false
566
                };
567
            case 'last_name' :
568
                return match(true) {
569
                    isset(BPT::$update->message) => BPT::$update->message->from->last_name ?? '',
570
                    isset(BPT::$update->edited_message) => BPT::$update->edited_message->from->last_name ?? '',
571
                    isset(BPT::$update->inline_query) => BPT::$update->inline_query->from->last_name ?? '',
572
                    isset(BPT::$update->callback_query) => BPT::$update->callback_query->from->last_name ?? '',
573
                    isset(BPT::$update->chat_join_request) => BPT::$update->chat_join_request->from->last_name ?? '',
574
                    default => false
575
                };
576
            case 'username' :
577
                return match(true) {
578
                    isset(BPT::$update->message) => BPT::$update->message->from->username ?? '',
579
                    isset(BPT::$update->edited_message) => BPT::$update->edited_message->from->username ?? '',
580
                    isset(BPT::$update->inline_query) => BPT::$update->inline_query->from->username ?? '',
581
                    isset(BPT::$update->callback_query) => BPT::$update->callback_query->from->username ?? '',
582
                    isset(BPT::$update->chat_join_request) => BPT::$update->chat_join_request->from->username ?? '',
583
                    default => false
584
                };
585
            case 'group_name' :
586
                return match(true) {
587
                    isset(BPT::$update->message) => BPT::$update->message->chat->first_name,
588
                    isset(BPT::$update->edited_message) => BPT::$update->edited_message->chat->first_name,
589
                    isset(BPT::$update->callback_query) => BPT::$update->callback_query->message->chat->first_name,
590
                    isset(BPT::$update->chat_join_request) => BPT::$update->chat_join_request->chat->first_name,
591
                    default => false
592
                };
593
            case 'group_username' :
594
                return match(true) {
595
                    isset(BPT::$update->message) => BPT::$update->message->chat->username,
596
                    isset(BPT::$update->edited_message) => BPT::$update->edited_message->chat->username,
597
                    isset(BPT::$update->callback_query) => BPT::$update->callback_query->message->chat->username,
598
                    isset(BPT::$update->chat_join_request) => BPT::$update->chat_join_request->chat->username,
599
                    default => false
600
                };
601
            case 'update_type' :
602
                return match(true) {
603
                    isset(BPT::$update->message) => 'message',
604
                    isset(BPT::$update->edited_message) => 'edited_message',
605
                    isset(BPT::$update->inline_query) => 'inline_query',
606
                    isset(BPT::$update->callback_query) => 'callback_query',
607
                    isset(BPT::$update->chat_join_request) => 'chat_join_request',
608
                    isset(BPT::$update->my_chat_member) => 'my_chat_member',
609
                    isset(BPT::$update->chat_member) => 'chat_member',
610
                    isset(BPT::$update->channel_post) => 'channel_post',
611
                    isset(BPT::$update->edited_channel_post) => 'edited_channel_post',
612
                    isset(BPT::$update->chosen_inline_result) => 'chosen_inline_result',
613
                    isset(BPT::$update->shipping_query) => 'shipping_query',
614
                    isset(BPT::$update->pre_checkout_query) => 'pre_checkout_query',
615
                    isset(BPT::$update->poll) => 'poll',
616
                    isset(BPT::$update->poll_answer) => 'poll_answer',
617
                    default => false
618
                };
619
            case 'url' :
620
                return 'https://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
621
            default:
622
                return false;
623
        }
624
    }
625
}