chat::isPrivate()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 2
rs 10
1
<?php
2
3
namespace BPT\types;
4
5
use BPT\constants\chatType;
6
use BPT\telegram\telegram;
7
use CURLFile;
8
use stdClass;
9
10
/**
11
 * This object represents a chat.
12
 */
13
class chat extends types {
0 ignored issues
show
Bug introduced by
The type BPT\types\types was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
    /** Keep all properties which has sub properties */
15
    private const subs = [];
16
17
    /**
18
     * Unique identifier for this chat. This number may have more than 32 significant bits and some programming
19
     * languages may have difficulty/silent defects in interpreting it. But it has at most 52 significant bits, so a
20
     * signed 64-bit integer or double-precision float type are safe for storing this identifier.
21
     */
22
    public int $id;
23
24
    /** Type of the chat, can be either “private”, “group”, “supergroup” or “channel” */
25
    public string $type;
26
27
    /** Optional. Title, for supergroups, channels and group chats */
28
    public null|string $title = null;
29
30
    /** Optional. Username, for private chats, supergroups and channels if available */
31
    public null|string $username = null;
32
33
    /** Optional. First name of the other party in a private chat */
34
    public null|string $first_name = null;
35
36
    /** Optional. Last name of the other party in a private chat */
37
    public null|string $last_name = null;
38
39
    /** Optional. True, if the supergroup chat is a forum (has topics enabled) */
40
    public null|bool $is_forum = null;
41
42
    public function __construct(stdClass|null $object = null) {
43
        if ($object != null) {
44
            parent::__construct($object, self::subs);
45
        }
46
    }
47
48
    /**
49
     * Is this chat is private or not
50
     *
51
     * @return bool
52
     */
53
    public function isPrivate (): bool {
54
        return $this->type === chatType::PRIVATE;
55
    }
56
57
    /**
58
     * Is this chat is normal group or not
59
     *
60
     * @return bool
61
     */
62
    public function isGroup (): bool {
63
        return $this->type === chatType::GROUP;
64
    }
65
66
    /**
67
     * Is this chat is suprtgroup or not
68
     *
69
     * @return bool
70
     */
71
    public function isSuperGroup (): bool {
72
        return $this->type === chatType::SUPERGROUP;
73
    }
74
75
    /**
76
     * Is this chat is channel or not
77
     *
78
     * @return bool
79
     */
80
    public function isChannel (): bool {
81
        return $this->type === chatType::CHANNEL;
82
    }
83
84
    /**
85
     * Leave this chat if it's not private
86
     *
87
     * @return responseError|bool
88
     */
89
    public function leave(): responseError|bool {
90
        if ($this->isPrivate()) {
91
            return false;
92
        }
93
        return telegram::leave($this->id);
94
    }
95
96
    /**
97
     * Set this chat photo if it's not private
98
     *
99
     * @param CURLFile|array $photo
100
     * @param null|bool      $answer
101
     *
102
     * @return responseError|bool
103
     */
104
    public function setPhoto(CURLFile|array $photo, bool $answer = null): responseError|bool {
105
        if ($this->isPrivate()) {
106
            return false;
107
        }
108
        return telegram::setChatPhoto($photo, $this->id, answer: $answer);
109
    }
110
111
    /**
112
     * Delete this chat photo if it's not private
113
     *
114
     * @param null|bool $answer
115
     *
116
     * @return responseError|bool
117
     */
118
    public function delPhoto(bool $answer = null): responseError|bool {
119
        if ($this->isPrivate()) {
120
            return false;
121
        }
122
        return telegram::deleteChatPhoto($this->id, answer: $answer);
123
    }
124
125
    /**
126
     * Set this chat title if it's not private
127
     *
128
     * @param string|array $title
129
     * @param bool|null    $answer
130
     *
131
     * @return responseError|bool
132
     */
133
    public function setTitle(string|array $title, bool $answer = null): responseError|bool {
134
        if ($this->isPrivate()) {
135
            return false;
136
        }
137
        return telegram::setChatTitle($title, $this->id, answer: $answer);
138
    }
139
140
    /**
141
     * Set this chat description if it's not private
142
     *
143
     * @param null|string $description
144
     * @param bool|null   $answer
145
     *
146
     * @return responseError|bool
147
     */
148
    public function setDescription(string|null $description = null, bool $answer = null): responseError|bool {
149
        if ($this->isPrivate()) {
150
            return false;
151
        }
152
        return telegram::setChatDescription($this->id, $description, answer: $answer);
153
    }
154
155
    /**
156
     * Get this chat admins if it's not private
157
     *
158
     * @param bool|null $answer
159
     *
160
     * @return bool|responseError|array
161
     */
162
    public function getAdmins(bool $answer = null): bool|responseError|array {
163
        if ($this->isPrivate()) {
164
            return false;
165
        }
166
        return telegram::getChatAdministrators($this->id, answer: $answer);
167
    }
168
169
    /**
170
     * Get this chat members count if it's not private
171
     *
172
     * @param bool|null $answer
173
     *
174
     * @return bool|responseError|int
175
     */
176
    public function getMembersCount(bool $answer = null): bool|responseError|int {
177
        if ($this->isPrivate()) {
178
            return false;
179
        }
180
        return telegram::getChatMemberCount($this->id, answer: $answer);
181
    }
182
183
    /**
184
     * Get member info in this chat if it's not private
185
     *
186
     * @param null|int  $user_id
187
     * @param bool|null $answer
188
     *
189
     * @return chatMember|bool|responseError
190
     */
191
    public function getMember(int|null $user_id = null, bool $answer = null): chatMember|bool|responseError {
192
        if ($this->isPrivate()) {
193
            return false;
194
        }
195
        return telegram::getChatMember($this->id, $user_id, answer: $answer);
196
    }
197
}
198