Issues (36)

src/Entities/InlineKeyboardButton.php (8 issues)

1
<?php
2
3
/**
4
 * This file is part of the TelegramBot package.
5
 *
6
 * (c) Avtandil Kikabidze aka LONGMAN <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Longman\TelegramBot\Entities;
13
14
use Longman\TelegramBot\Entities\Games\CallbackGame;
15
use Longman\TelegramBot\Exception\TelegramException;
16
17
/**
18
 * Class InlineKeyboardButton
19
 *
20
 * @link https://core.telegram.org/bots/api#inlinekeyboardbutton
21
 *
22
 * @method string       getText()                         Label text on the button
23
 * @method string       getUrl()                          Optional. HTTP url to be opened when button is pressed
24
 * @method LoginUrl     getLoginUrl()                     Optional. An HTTP URL used to automatically authorize the user. Can be used as a replacement for the Telegram Login Widget.
25
 * @method string       getCallbackData()                 Optional. Data to be sent in a callback query to the bot when button is pressed, 1-64 bytes
26
 * @method WebAppInfo   getWebApp()                       Optional. Description of the Web App that will be launched when the user presses the button. The Web App will be able to send an arbitrary message on behalf of the user using the method answerWebAppQuery. Available only in private chats between a user and the bot.
27
 * @method string       getSwitchInlineQuery()            Optional. If set, pressing the button will prompt the user to select one of their chats, open that chat and insert the bot's username and the specified inline query in the input field. Can be empty, in which case just the bot’s username will be inserted.
28
 * @method string       getSwitchInlineQueryCurrentChat() Optional. If set, pressing the button will insert the bot‘s username and the specified inline query in the current chat's input field. Can be empty, in which case only the bot’s username will be inserted.
29
 * @method SwitchInlineQueryChosenChat getSwitchInlineQueryChosenChat() Optional. If set, pressing the button will prompt the user to select one of their chats of the specified type, open that chat and insert the bot's username and the specified inline query in the input field
30
 * @method CallbackGame getCallbackGame()                 Optional. Description of the game that will be launched when the user presses the button.
31
 * @method bool         getPay()                          Optional. Specify True, to send a Pay button.
32
 *
33
 * @method $this setText(string $text)                                                     Label text on the button
34
 * @method $this setUrl(string $url)                                                       Optional. HTTP url to be opened when button is pressed
35
 * @method $this setLoginUrl(LoginUrl $login_url)                                          Optional. HTTP url to be opened when button is pressed
36
 * @method $this setCallbackData(string $callback_data)                                    Optional. Data to be sent in a callback query to the bot when button is pressed, 1-64 bytes
37
 * @method $this setWebApp(WebAppInfo $web_app)                                            Optional. Description of the Web App that will be launched when the user presses the button. The Web App will be able to send an arbitrary message on behalf of the user using the method answerWebAppQuery. Available only in private chats between a user and the bot.
38
 * @method $this setSwitchInlineQuery(string $switch_inline_query)                         Optional. If set, pressing the button will prompt the user to select one of their chats, open that chat and insert the bot's username and the specified inline query in the input field. Can be empty, in which case just the bot’s username will be inserted.
39
 * @method $this setSwitchInlineQueryCurrentChat(string $switch_inline_query_current_chat) Optional. If set, pressing the button will insert the bot‘s username and the specified inline query in the current chat's input field. Can be empty, in which case only the bot’s username will be inserted.
40
 * @method $this setSwitchInlineQueryChosenChat(SwitchInlineQueryChosenChat $switch_inline_query_chosen_chat) Optional. If set, pressing the button will prompt the user to select one of their chats of the specified type, open that chat and insert the bot's username and the specified inline query in the input field
41
 * @method $this setCallbackGame(CallbackGame $callback_game)                              Optional. Description of the game that will be launched when the user presses the button.
42
 * @method $this setPay(bool $pay)                                                         Optional. Specify True, to send a Pay button.
43
 */
44
class InlineKeyboardButton extends KeyboardButton
45
{
46
    /**
47
     * Check if the passed data array could be an InlineKeyboardButton.
48
     *
49
     * @param array $data
50
     *
51
     * @return bool
52
     */
53 1
    public static function couldBe(array $data): bool
54
    {
55 1
        return array_key_exists('text', $data) && (
56 1
                array_key_exists('url', $data) ||
57 1
                array_key_exists('login_url', $data) ||
58 1
                array_key_exists('callback_data', $data) ||
59 1
                array_key_exists('web_app', $data) ||
60 1
                array_key_exists('switch_inline_query', $data) ||
61 1
                array_key_exists('switch_inline_query_current_chat', $data) ||
62 1
                array_key_exists('switch_inline_query_chosen_chat', $data) ||
63 1
                array_key_exists('callback_game', $data) ||
64 1
                array_key_exists('pay', $data)
65 1
            );
66
    }
67
68
    /**
69
     * {@inheritdoc}
70
     */
71 5
    public function __call($method, $args)
72
    {
73
        // Only 1 of these can be set, so clear the others when setting a new one.
74 5
        if (in_array($method, ['setUrl', 'setLoginUrl', 'setCallbackData', 'setWebApp', 'setSwitchInlineQuery', 'setSwitchInlineQueryCurrentChat', 'setSwitchInlineQueryChosenChat', 'setCallbackGame', 'setPay'], true)) {
75
            unset($this->url, $this->login_url, $this->callback_data, $this->web_app, $this->switch_inline_query, $this->switch_inline_query_current_chat, $this->switch_inline_query_chosen_chat, $this->callback_game, $this->pay);
0 ignored issues
show
Bug Best Practice introduced by
The property switch_inline_query_chosen_chat does not exist on Longman\TelegramBot\Entities\InlineKeyboardButton. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug Best Practice introduced by
The property pay does not exist on Longman\TelegramBot\Entities\InlineKeyboardButton. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug Best Practice introduced by
The property switch_inline_query does not exist on Longman\TelegramBot\Entities\InlineKeyboardButton. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug Best Practice introduced by
The property callback_game does not exist on Longman\TelegramBot\Entities\InlineKeyboardButton. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug Best Practice introduced by
The property switch_inline_query_current_chat does not exist on Longman\TelegramBot\Entities\InlineKeyboardButton. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug Best Practice introduced by
The property url does not exist on Longman\TelegramBot\Entities\InlineKeyboardButton. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug Best Practice introduced by
The property login_url does not exist on Longman\TelegramBot\Entities\InlineKeyboardButton. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug Best Practice introduced by
The property callback_data does not exist on Longman\TelegramBot\Entities\InlineKeyboardButton. Since you implemented __get, consider adding a @property annotation.
Loading history...
76
        }
77
78 5
        return parent::__call($method, $args);
79
    }
80
}
81