CallbackQuery::getChatID()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 2
eloc 2
nc 2
nop 0
crap 6
1
<?php
2
3
/*
4
 * This file is part of the PhpBotFramework.
5
 *
6
 * PhpBotFramework is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU Lesser General Public License as
8
 * published by the Free Software Foundation, version 3.
9
 *
10
 * PhpBotFramework is distributed in the hope that it will be useful, but
11
 * WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
 * Lesser General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU Lesser General Public License
16
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
 */
18
19
namespace PhpBotFramework\Entities;
20
21
/**
22
 * \addtogroup Entities Entities
23
 * \brief Telegram Entities.
24
 * @{
25
 */
26
27
/** \class CallbackQuery
28
 * \brief This object represents an incoming callback query from a callback button in an inline keyboard.
29
 * \details If the button that originated the query was attached to a message sent by the bot,
30
 * the <code>field</code> message will be present.
31
 * If the button was attached to a message sent via the bot (in inline mode),
32
 * the field inline_message_id will be present.
33
 *
34
 * Exactly one of the fields data or <code>game_short_name</code> will be present.
35
 */
36
class CallbackQuery implements \ArrayAccess
37
{
38
39
    /** @} */
40
41
    use EntityAccess;
42
43
    /**
44
     * \brief Get data parameter if it is set.
45
     * @return string $data if set or empty string otherwise.
46
     */
47
    public function getData() : string
48
    {
49
        return isset($this->container['data']) ? $this->container['data'] : null;
50
    }
51
52
    /**
53
     * \brief Get chat ID of the chat where the message comes from.
54
     * @return $chat_id Chat ID.
0 ignored issues
show
Documentation introduced by
The doc-type $chat_id could not be parsed: Unknown type name "$chat_id" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
55
     */
56
    public function getChatID()
57
    {
58
        return isset($this->container['message']) ? $this->container['message']['chat']['id'] : null;
59
    }
60
61
    /**
62
     * \brief Get message attached to this callback.
63
     * @return Message $message Message object attached to this callback.
64
     */
65
    public function getMessage()
66
    {
67
68
        if (!is_a($this->container, 'PhpBotFramework\Entities\Message')) {
69
            $this->container['message'] = new Message($this->container['message']);
70
        }
71
72
        return $this->container['message'];
73
    }
74
75
    /**
76
     * \brief (<i>Internal</i>) Get parameter to set to the bot.
77
     * \details Each time the bot receive a callback query the parameter _callback_query_id
78
     * will be set to the ID of this callback.
79
     * @return array Array with the parameter name as "var" index, and the id in "id" index.
80
     */
81
    public function getBotParameter() : array
82
    {
83
84
        return ['var' => '_callback_query_id', 'id' => $this->container['id']];
85
    }
86
87
    /**
88
     * \brief Get ID of this callback query.
89
     * @return int $id ID of the callback.
90
     */
91
    public function getID() : int
92
    {
93
94
        return $this->container['id'];
95
    }
96
}
97