Completed
Push — master ( 6d1075...fae82d )
by Armando
20:31 queued 14:28
created

Chat::subEntities()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 2
cts 2
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * This file is part of the TelegramBot package.
4
 *
5
 * (c) Avtandil Kikabidze aka LONGMAN <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Longman\TelegramBot\Entities;
12
13
/**
14
 * Class Chat
15
 *
16
 * @link https://core.telegram.org/bots/api#chat
17
 *
18
 * @property int       $id                              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.
19
 * @property string    $type                            Type of chat, can be either "private", "group", "supergroup" or "channel"
20
 * @property string    $title                           Optional. Title, for channels and group chats
21
 * @property string    $username                        Optional. Username, for private chats, supergroups and channels if available
22
 * @property string    $first_name                      Optional. First name of the other party in a private chat
23
 * @property string    $last_name                       Optional. Last name of the other party in a private chat
24
 * @property bool      $all_members_are_administrators  Optional. True if a group has ‘All Members Are Admins’ enabled.
25
 * @property ChatPhoto $photo                           Optional. Chat photo. Returned only in getChat.
26
 * @property string    $description                     Optional. Description, for supergroups and channel chats. Returned only in getChat.
27
 * @property string    $invite_link                     Optional. Chat invite link, for supergroups and channel chats. Returned only in getChat.
28
 * @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.
29
 * @method   string    getType()                        Type of chat, can be either "private ", "group", "supergroup" or "channel"
30
 * @method   string    getTitle()                       Optional. Title, for channels and group chats
31
 * @method   string    getUsername()                    Optional. Username, for private chats, supergroups and channels if available
32
 * @method   string    getFirstName()                   Optional. First name of the other party in a private chat
33
 * @method   string    getLastName()                    Optional. Last name of the other party in a private chat
34
 * @method   bool      getAllMembersAreAdministrators() Optional. True if a group has ‘All Members Are Admins’ enabled.
35
 * @method   ChatPhoto getPhoto()                       Optional. Chat photo. Returned only in getChat.
36
 * @method   string    getDescription()                 Optional. Description, for supergroups and channel chats. Returned only in getChat.
37
 * @method   string    getInviteLink()                  Optional. Chat invite link, for supergroups and channel chats. Returned only in getChat.
38
 */
39
class Chat extends Entity
40
{
41
    /**
42
     * {@inheritdoc}
43
     */
44 11
    public function subEntities()
45
    {
46
        return [
47 11
            'photo' => ChatPhoto::class,
48
        ];
49
    }
50
51 11
    public function __construct($data)
52
    {
53 11
        parent::__construct($data);
54
55 11
        $id   = $this->getId();
56 11
        $type = $this->getType();
57 11
        if (!$type) {
58 5
            $id > 0 && $this->type = 'private';
59 5
            $id < 0 && $this->type = 'group';
60
        }
61 11
    }
62
63
    /**
64
     * Try to mention the user of this chat, else return the title
65
     *
66
     * @param bool $escape_markdown
67
     *
68
     * @return string|null
69
     */
70 1
    public function tryMention($escape_markdown = false)
71
    {
72 1
        if ($this->isPrivateChat()) {
73 1
            return parent::tryMention($escape_markdown);
74
        }
75
76 1
        return $this->getTitle();
77
    }
78
79
    /**
80
     * Check if this is a group chat
81
     *
82
     * @return bool
83
     */
84 1
    public function isGroupChat()
85
    {
86 1
        return $this->getType() === 'group' || $this->getId() < 0;
87
    }
88
89
    /**
90
     * Check if this is a private chat
91
     *
92
     * @return bool
93
     */
94 2
    public function isPrivateChat()
95
    {
96 2
        return $this->getType() === 'private';
97
    }
98
99
    /**
100
     * Check if this is a super group
101
     *
102
     * @return bool
103
     */
104 1
    public function isSuperGroup()
105
    {
106 1
        return $this->getType() === 'supergroup';
107
    }
108
109
    /**
110
     * Check if this is a channel
111
     *
112
     * @return bool
113
     */
114 1
    public function isChannel()
115
    {
116 1
        return $this->getType() === 'channel';
117
    }
118
}
119