AnswerInlineQueryMethod   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 97
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 17
dl 0
loc 97
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 10 2
A addResult() 0 5 1
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
use TgBotApi\BotApiBase\Type\InlineQueryResult\InlineQueryResultType;
10
11
/**
12
 * Class AnswerInlineQueryMethod.
13
 *
14
 * Use this method to send answers to an inline query. On success, True is returned.
15
 * No more than 50 results per query are allowed.
16
 *
17
 * @see https://core.telegram.org/bots/api#answerinlinequery
18
 */
19
class AnswerInlineQueryMethod implements AnswerMethodAliasInterface
20
{
21
    use FillFromArrayTrait;
22
23
    /**
24
     * Unique identifier for the answered query.
25
     *
26
     * @var string
27
     */
28
    public $inlineQueryId;
29
30
    /**
31
     * A JSON-serialized array of results for the inline query.
32
     *
33
     * @var InlineQueryResultType[]
34
     */
35
    public $results;
36
37
    /**
38
     * Optional. The maximum amount of time in seconds that the result of the inline query may be cached on the server.
39
     * Defaults to 300.
40
     *
41
     * @var \DateTimeInterface|null
42
     */
43
    public $cacheTime;
44
45
    /**
46
     * Optional. Pass True, if results may be cached on the server side only for the user that sent the query.
47
     * By default, results may be returned to any user who sends the same query.
48
     *
49
     * @var bool|null
50
     */
51
    public $isPersonal;
52
53
    /**
54
     * Optional. Pass the offset that a client should send in the next query with the same text to receive more results.
55
     * Pass an empty string if there are no more results or if you don‘t support pagination.
56
     * Offset length can’t exceed 64 bytes.
57
     *
58
     * @var string|null
59
     */
60
    public $nextOffset;
61
62
    /**
63
     * Optional. If passed, clients will display a button with specified text that switches the user to a private
64
     * chat with the bot and sends the bot a start message with the parameter switch_pm_parameter.
65
     *
66
     * @var string|null
67
     */
68
    public $switchPmText;
69
70
    /**
71
     * String    Optional. Deep-linking parameter for the /start message sent to the bot when user presses the switch
72
     * button. 1-64 characters, only A-Z, a-z, 0-9, _ and - are allowed.
73
     *
74
     * Example: An inline bot that sends YouTube videos can ask the user to connect the bot to their YouTube account
75
     * to adapt search results accordingly. To do this, it displays a ‘Connect your YouTube account’
76
     * button above the results, or even before showing any. The user presses the button, switches to a private chat
77
     * with the bot and, in doing so, passes a start parameter that instructs the bot to return an oauth link.
78
     * Once done, the bot can offer a switch_inline button so that the user can easily return to the chat where
79
     * they wanted to use the bot's inline capabilities.
80
     *
81
     * @var string|null
82
     */
83
    public $switchPmParameter;
84
85
    /**
86
     * @param string                  $inlineQueryId
87
     * @param InlineQueryResultType[] $results
88
     * @param array|null              $data
89
     *
90
     * @throws \TgBotApi\BotApiBase\Exception\BadArgumentException
91
     *
92
     * @return AnswerInlineQueryMethod
93
     */
94 2
    public static function create(string $inlineQueryId, array $results, array $data = null): AnswerInlineQueryMethod
95
    {
96 2
        $instance = new static();
97 2
        $instance->inlineQueryId = $inlineQueryId;
98 2
        $instance->results = $results;
99 2
        if ($data) {
100 2
            $instance->fill($data);
101
        }
102
103 2
        return $instance;
104
    }
105
106
    /**
107
     * @param InlineQueryResultType $result
108
     *
109
     * @return AnswerInlineQueryMethod
110
     */
111 2
    public function addResult(InlineQueryResultType $result): AnswerInlineQueryMethod
112
    {
113 2
        $this->results[] = $result;
114
115 2
        return $this;
116
    }
117
}
118