Passed
Push — master ( 3bfee0...112fc6 )
by Nikolay
02:02
created

AnswerInlineQueryMethod::addResult()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

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