Passed
Push — main ( 1f3d08...95c480 )
by Miaad
10:28
created

chatMemberUpdated::isOldAdmin()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 1
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 2
rs 10
1
<?php
2
3
namespace BPT\types;
4
5
use BPT\constants\chatMemberStatus;
6
use BPT\settings;
7
use stdClass;
8
9
/**
10
 * This object represents changes in the status of a chat member.
11
 */
12
class chatMemberUpdated 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...
13
    /** Keep all of properties which has sub properties */
14
    private const subs = [
15
        'chat' => 'BPT\types\chat',
16
        'from' => 'BPT\types\user',
17
        'old_chat_member' => 'BPT\types\chatMember',
18
        'new_chat_member' => 'BPT\types\chatMember',
19
        'invite_link' => 'BPT\types\chatInviteLink',
20
    ];
21
22
    /** Chat the user belongs to */
23
    public chat $chat;
24
25
    /** Performer of the action, which resulted in the change */
26
    public user $from;
27
28
    /** Date the change was done in Unix time */
29
    public int $date;
30
31
    /** Previous information about the chat member */
32
    public chatMember $old_chat_member;
33
34
    /** New information about the chat member */
35
    public chatMember $new_chat_member;
36
37
    /**
38
     * Optional. Chat invite link, which was used by the user to join the chat; for joining by invite link events
39
     * only.
40
     */
41
    public null|chatInviteLink $invite_link = null;
42
43
44
    public function __construct(stdClass|null $object = null) {
45
        if ($object != null) {
46
            parent::__construct($object, self::subs);
47
        }
48
    }
49
50
    public function isUnBlockedMe(): bool {
51
        return $this->chat->isPrivate() && $this->isMe() && $this->isJoined();
52
    }
53
54
    public function isBlockedMe(): bool {
55
        return $this->chat->isPrivate() && $this->isMe() && $this->isKicked();
56
    }
57
58
    public function isMe (): bool {
59
        return $this->new_chat_member->user->id == settings::$bot_id;
60
    }
61
62
    public function isAdded(): bool {
63
        return $this->isJoined() && $this->from->id !== $this->new_chat_member->user->id;
64
    }
65
66
    public function isJoined(): bool {
67
        return $this->new_chat_member->status === chatMemberStatus::MEMBER;
68
    }
69
70
    public function isJoinedByLink(): bool {
71
        return $this->isJoined() && !empty($this->invite_link);
72
    }
73
74
    public function isLeaved (): bool {
75
        return $this->new_chat_member->status === chatMemberStatus::LEFT;
76
    }
77
78
    public function isKicked (): bool {
79
        return $this->new_chat_member->status === chatMemberStatus::KICKED;
80
    }
81
82
    public function isOldAdmin (): bool {
83
        return $this->old_chat_member->status === chatMemberStatus::ADMINISTRATOR && $this->isJoined();
84
    }
85
86
    public function isNewAdmin (): bool {
87
        return $this->new_chat_member->status === chatMemberStatus::ADMINISTRATOR;
88
    }
89
}
90