Chat::isChannel()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
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
 * @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.
26
 * @method   string getType()                        Type of chat, can be either "private ", "group", "supergroup" or "channel"
27
 * @method   string getTitle()                       Optional. Title, for channels and group chats
28
 * @method   string getUsername()                    Optional. Username, for private chats, supergroups and channels if available
29
 * @method   string getFirstName()                   Optional. First name of the other party in a private chat
30
 * @method   string getLastName()                    Optional. Last name of the other party in a private chat
31
 * @method   bool   getAllMembersAreAdministrators() Optional. True if a group has ‘All Members Are Admins’ enabled.
32
 */
33
class Chat extends Entity
34
{
35 17
    public function __construct($data)
36
    {
37 17
        parent::__construct($data);
38
39 17
        $id   = $this->getId();
40 17
        $type = $this->getType();
41 17
        if (!$type) {
42 5
            $id > 0 && $this->type = 'private';
43 5
            $id < 0 && $this->type = 'group';
44
        }
45 17
    }
46
47
    /**
48
     * Try to mention the user of this chat, else return the title
49
     *
50
     * @param bool $escape_markdown
51
     *
52
     * @return string|null
53
     */
54 1
    public function tryMention($escape_markdown = false)
55
    {
56 1
        if ($this->isPrivateChat()) {
57 1
            return parent::tryMention($escape_markdown);
58
        }
59
60 1
        return $this->getTitle();
61
    }
62
63
    /**
64
     * Check if this is a group chat
65
     *
66
     * @return bool
67
     */
68 1
    public function isGroupChat()
69
    {
70 1
        return $this->getType() === 'group' || $this->getId() < 0;
71
    }
72
73
    /**
74
     * Check if this is a private chat
75
     *
76
     * @return bool
77
     */
78 2
    public function isPrivateChat()
79
    {
80 2
        return $this->getType() === 'private';
81
    }
82
83
    /**
84
     * Check if this is a super group
85
     *
86
     * @return bool
87
     */
88 1
    public function isSuperGroup()
89
    {
90 1
        return $this->getType() === 'supergroup';
91
    }
92
93
    /**
94
     * Check if this is a channel
95
     *
96
     * @return bool
97
     */
98 1
    public function isChannel()
99
    {
100 1
        return $this->getType() === 'channel';
101
    }
102
}
103