Chat   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 37.5%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 0
loc 52
rs 10
c 0
b 0
f 0
ccs 3
cts 8
cp 0.375

4 Methods

Rating   Name   Duplication   Size   Complexity  
execRequest() 0 1 ?
A getMe() 0 4 1
A getChat() 0 8 1
A getChatAdministrators() 0 8 1
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\Core;
20
21
/**
22
 * \class Chat
23
 * \brief All API Methods that involve chats data and info.
24
 */
25
trait Chat
26
{
27
    abstract protected function execRequest(string $url);
28
29
    /**
30
     * \addtogroup Api Api Methods
31
     * @{
32
     */
33
34
    /**
35
     * \brief A simple method for testing bot's auth token.
36
     * \details Requires no parameters. Returns basic [information about the bot](https://core.telegram.org/bots/api#getme)
37
     * @return Array|false Bot info
38
     */
39
    public function getMe()
40
    {
41
        return $this->execRequest('getMe?');
42
    }
43
44
    /**
45
     * \brief Get info about a chat.
46
     * \details Use this method to get information about the chat (current name of the user for one-on-one conversations, current username of a user, group or channel, etc.). [API reference](https://core.telegram.org/bots/api#getchat)
47
     * @param int|string $chat_id Unique identifier for the target chat or username of the target supergroup or channel (in the format <code>@channelusername</code>)
48
     * @return Array|false Information about the chat.
49
     */
50 1
    public function getChat($chat_id)
51
    {
52
        $parameters = [
53 1
            'chat_id' => $chat_id,
54
        ];
55
56 1
        return $this->execRequest('getChat?' . http_build_query($parameters));
57
    }
58
59
    /**
60
     * \brief Use this method to get the list of chat's administrators.
61
     * @param string $chat_id Unique identifier for the target chat or username of the target supergroup or channel (in the format <code>@channelusername</code>)
62
     * @return Array|false On success, returns an Array of ChatMember objects that contains information about all chat administrators except other bots. If the chat is a group or a supergroup and no administrators were appointed, only the creator will be returned.
63
     */
64
    public function getChatAdministrators($chat_id)
65
    {
66
        $parameters = [
67
            'chat_id' => $chat_id,
68
        ];
69
70
        return $this->execRequest('getChatAdministrators?' . http_build_query($parameters));
71
    }
72
73
    /** @} */
74
75
    /** @} */
76
}
77