AnswerCallbackQueryMethod   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
eloc 12
dl 0
loc 62
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A create() 0 9 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace TgBotApi\BotApiBase\Method;
6
7
use TgBotApi\BotApiBase\Method\Interfaces\AnswerMethodAliasInterface;
8
use TgBotApi\BotApiBase\Method\Traits\FillFromArrayTrait;
9
10
/**
11
 * Class AnswerCallbackQueryMethod.
12
 *
13
 * Use this method to send answers to callback queries sent from inline keyboards.
14
 * The answer will be displayed to the user as a notification at the top of the chat screen or as an alert.
15
 * On success, True is returned.
16
 *
17
 * @see https://core.telegram.org/bots/api#answercallbackquery
18
 */
19
class AnswerCallbackQueryMethod implements AnswerMethodAliasInterface
20
{
21
    use FillFromArrayTrait;
22
    /**
23
     * Unique identifier for the query to be answered.
24
     *
25
     * @var string
26
     */
27
    public $callbackQueryId;
28
29
    /**
30
     * Optional. Text of the notification. If not specified, nothing will be shown to the user, 0-200 characters.
31
     *
32
     * @var string|null
33
     */
34
    public $text;
35
36
    /**
37
     * Optional. If true, an alert will be shown by the client instead of a notification at the top of the chat screen.
38
     * Defaults to false.
39
     *
40
     * @var bool|null
41
     */
42
    public $showAlert;
43
44
    /**
45
     * Optional. URL that will be opened by the user's client.
46
     * If you have created a Game and accepted the conditions via @Botfather,
47
     * specify the URL that opens your game – note that this will only work
48
     * if the query comes from a callback_game button.
49
     *
50
     * Otherwise, you may use links like t.me/your_bot?start=XXXX that open your bot with a parameter.
51
     *
52
     * @var string|null
53
     */
54
    public $url;
55
56
    /**
57
     * Optional. The maximum amount of time in seconds that the result of the callback query may be cached client-side.
58
     * Telegram apps will support caching starting in version 3.14. Defaults to 0.
59
     *
60
     * @var \DateTimeInterface|null
61
     */
62
    public $cacheTime;
63
64
    /**
65
     * @param string     $callbackQueryId
66
     * @param array|null $data
67
     *
68
     * @throws \TgBotApi\BotApiBase\Exception\BadArgumentException
69
     *
70
     * @return AnswerCallbackQueryMethod
71
     */
72 3
    public static function create(string $callbackQueryId, array $data = null): AnswerCallbackQueryMethod
73
    {
74 3
        $instance = new static();
75 3
        $instance->callbackQueryId = $callbackQueryId;
76 3
        if ($data) {
77 2
            $instance->fill($data);
78
        }
79
80 3
        return $instance;
81
    }
82
}
83