Passed
Push — master ( f3fe5e...097177 )
by Armando
05:18 queued 02:03
created

Chat::getAllMembersAreAdministrators()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
/**
4
 * This file is part of the TelegramBot package.
5
 *
6
 * (c) Avtandil Kikabidze aka LONGMAN <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Longman\TelegramBot\Entities;
13
14
/**
15
 * Class Chat
16
 *
17
 * @link https://core.telegram.org/bots/api#chat
18
 *
19
 * @property string type Type of chat, can be either "private ", "group", "supergroup" or "channel"
20
 *
21
 * @method int             getId()                                 Unique identifier for this chat. This number may be greater than 32 bits and some programming languages may have difficulty/silent defects in interpreting it. But it smaller than 52 bits, so a signed 64 bit integer or double-precision float type are safe for storing this identifier.
22
 * @method string          getType()                               Type of chat, can be either "private ", "group", "supergroup" or "channel"
23
 * @method string          getTitle()                              Optional. Title, for channels and group chats
24
 * @method string          getUsername()                           Optional. Username, for private chats, supergroups and channels if available
25
 * @method string          getFirstName()                          Optional. First name of the other party in a private chat
26
 * @method string          getLastName()                           Optional. Last name of the other party in a private chat
27
 * @method ChatPhoto       getPhoto()                              Optional. Chat photo. Returned only in getChat.
28
 * @method string          getBio()                                Optional. Bio of the other party in a private chat. Returned only in getChat.
29
 * @method bool            getHasPrivateForwards()                 Optional. True, if privacy settings of the other party in the private chat allows to use tg://user?id=<user_id> links only in chats with the user. Returned only in getChat.
30
 * @method bool            getHasRestrictedVoiceAndVideoMessages() Optional. True, if the privacy settings of the other party restrict sending voice and video note messages in the private chat. Returned only in getChat.
31
 * @method bool            getJoinToSendMessages()                 Optional. True, if users need to join the supergroup before they can send messages. Returned only in getChat.
32
 * @method bool            getJoinByRequest()                      Optional. True, if all users directly joining the supergroup need to be approved by supergroup administrators. Returned only in getChat.
33
 * @method string          getDescription()                        Optional. Description, for groups, supergroups and channel chats. Returned only in getChat.
34
 * @method string          getInviteLink()                         Optional. Chat invite link, for groups, supergroups and channel chats. Each administrator in a chat generates their own invite links, so the bot must first generate the link using exportChatInviteLink. Returned only in getChat.
35
 * @method Message         getPinnedMessage()                      Optional. Pinned message, for groups, supergroups and channels. Returned only in getChat.
36
 * @method ChatPermissions getPermissions()                        Optional. Default chat member permissions, for groups and supergroups. Returned only in getChat.
37
 * @method int             getSlowModeDelay()                      Optional. For supergroups, the minimum allowed delay between consecutive messages sent by each unpriviledged user. Returned only in getChat.
38
 * @method int             getMessageAutoDeleteTime()              Optional. The time after which all messages sent to the chat will be automatically deleted; in seconds. Returned only in getChat.
39
 * @method bool            getHasProtectedContent()                Optional. True, if messages from the chat can't be forwarded to other chats. Returned only in getChat.
40
 * @method string          getStickerSetName()                     Optional. For supergroups, name of group sticker set. Returned only in getChat.
41
 * @method bool            getCanSetStickerSet()                   Optional. True, if the bot can change the group sticker set. Returned only in getChat.
42
 * @method int             getLinkedChatId()                       Optional. Unique identifier for the linked chat. Returned only in getChat.
43
 * @method ChatLocation    getLocation()                           Optional. For supergroups, the location to which the supergroup is connected. Returned only in getChat.
44
 */
45
class Chat extends Entity
46
{
47
    /**
48
     * {@inheritdoc}
49
     */
50 12
    protected function subEntities(): array
51
    {
52
        return [
53 12
            'photo'          => ChatPhoto::class,
54
            'pinned_message' => Message::class,
55
            'permissions'    => ChatPermissions::class,
56
            'location'       => ChatLocation::class,
57
        ];
58
    }
59
60 12
    public function __construct($data)
61
    {
62 12
        parent::__construct($data);
63
64 12
        $id   = $this->getId();
65 12
        $type = $this->getType();
66 12
        if (!$type) {
67 5
            $id > 0 && $this->type = 'private';
68 5
            $id < 0 && $this->type = 'group';
69
        }
70
    }
71
72
    /**
73
     * Try to mention the user of this chat, else return the title
74
     *
75
     * @param bool $escape_markdown
76
     *
77
     * @return string
78
     */
79 1
    public function tryMention($escape_markdown = false): string
80
    {
81 1
        if ($this->isPrivateChat()) {
82 1
            return parent::tryMention($escape_markdown);
83
        }
84
85 1
        return $this->getTitle();
86
    }
87
88
    /**
89
     * Check if this is a group chat
90
     *
91
     * @return bool
92
     */
93 1
    public function isGroupChat(): bool
94
    {
95 1
        return $this->getType() === 'group';
96
    }
97
98
    /**
99
     * Check if this is a private chat
100
     *
101
     * @return bool
102
     */
103 2
    public function isPrivateChat(): bool
104
    {
105 2
        return $this->getType() === 'private';
106
    }
107
108
    /**
109
     * Check if this is a super group
110
     *
111
     * @return bool
112
     */
113 1
    public function isSuperGroup(): bool
114
    {
115 1
        return $this->getType() === 'supergroup';
116
    }
117
118
    /**
119
     * Check if this is a channel
120
     *
121
     * @return bool
122
     */
123 1
    public function isChannel(): bool
124
    {
125 1
        return $this->getType() === 'channel';
126
    }
127
}
128