Chat::isGroupChat()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
c 0
b 0
f 0
rs 10
cc 2
nc 2
nop 0
1
<?php
2
3
namespace TelegramBot\Entities;
4
5
use TelegramBot\Entity;
6
7
/**
8
 * Class Chat
9
 *
10
 * @link https://core.telegram.org/bots/api#chat
11
 *
12
 * @property string type Type of chat, can be either "private ", "group", "supergroup" or "channel"
13
 *
14
 * @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.
15
 * @method string          getType()                    Type of chat, can be either "private ", "group", "supergroup" or "channel"
16
 * @method string          getTitle()                   Optional. Title, for channels and group chats
17
 * @method string          getUsername()                Optional. Username, for private chats, supergroups and channels if available
18
 * @method string          getFirstName()               Optional. First name of the other party in a private chat
19
 * @method string          getLastName()                Optional. Last name of the other party in a private chat
20
 * @method ChatPhoto       getPhoto()                   Optional. Chat photo. Returned only in getChat.
21
 * @method string          getBio()                     Optional. Bio of the other party in a private chat. Returned only in getChat.
22
 * @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.
23
 * @method string          getDescription()             Optional. Description, for groups, supergroups and channel chats. Returned only in getChat.
24
 * @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.
25
 * @method Message         getPinnedMessage()           Optional. Pinned message, for groups, supergroups and channels. Returned only in getChat.
26
 * @method ChatPermissions getPermissions()             Optional. Default chat member permissions, for groups and supergroups. Returned only in getChat.
27
 * @method int             getSlowModeDelay()           Optional. For supergroups, the minimum allowed delay between consecutive messages sent by each unpriviledged user. Returned only in getChat.
28
 * @method int             getMessageAutoDeleteTime()   Optional. The time after which all messages sent to the chat will be automatically deleted;
29
 * in seconds. Returned only in getChat.
30
 * @method bool            getHasProtectedContent()     Optional. True, if messages from the chat can't be forwarded to other chats. Returned only in getChat.
31
 * @method string          getStickerSetName()          Optional. For supergroups, name of group sticker set. Returned only in getChat.
32
 * @method bool            getCanSetStickerSet()        Optional. True, if the bot can change the group sticker set. Returned only in getChat.
33
 * @method int             getLinkedChatId()            Optional. Unique identifier for the linked chat. Returned only in getChat.
34
 * @method ChatLocation    getLocation()                Optional. For supergroups, the location to which the supergroup is connected. Returned only in getChat.
35
 */
36
class Chat extends Entity
37
{
38
39
    public function __construct($data)
40
    {
41
        parent::__construct($data);
42
43
        $id = $this->getId();
44
        $type = $this->getType();
45
        if (!$type) {
46
            $id > 0 && $this->type = 'private';
47
            $id < 0 && $this->type = 'group';
48
        }
49
    }
50
51
    /**
52
     * Check if this is a group chat
53
     *
54
     * @return bool
55
     */
56
    public function isGroupChat(): bool
57
    {
58
        return $this->getType() === 'group' || $this->getId() < 0;
59
    }
60
61
    /**
62
     * Check if this is a private chat
63
     *
64
     * @return bool
65
     */
66
    public function isPrivateChat(): bool
67
    {
68
        return $this->getType() === 'private';
69
    }
70
71
    /**
72
     * Check if this is a super group
73
     *
74
     * @return bool
75
     */
76
    public function isSuperGroup(): bool
77
    {
78
        return $this->getType() === 'supergroup';
79
    }
80
81
    /**
82
     * Check if this is a channel
83
     *
84
     * @return bool
85
     */
86
    public function isChannel(): bool
87
    {
88
        return $this->getType() === 'channel';
89
    }
90
91
    /**
92
     * Optional. True if a group has 'All Members Are Admins' enabled.
93
     *
94
     * @return bool|null
95
     * @see Chat::getPermissions()
96
     *
97
     * @deprecated
98
     */
99
    public function getAllMembersAreAdministrators(): ?bool
100
    {
101
        return $this->getProperty('all_members_are_administrators');
102
    }
103
104
    /**
105
     * {@inheritdoc}
106
     */
107
    protected function subEntities(): array
108
    {
109
        return [
110
            'photo' => ChatPhoto::class,
111
            'pinned_message' => Message::class,
112
            'permissions' => ChatPermissions::class,
113
            'location' => ChatLocation::class,
114
        ];
115
    }
116
117
}
118