ChatMemberUpdated::promote()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 27
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 27
rs 9.7998
cc 1
nc 1
nop 11

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
4
namespace Sysbot\Telegram\ExtendedTypes;
5
6
7
use GuzzleHttp\Promise\PromiseInterface;
8
9
trait ChatMemberUpdated
10
{
11
    use BaseType;
12
13
    public function ban(?int $untilDate = null, ?bool $revokeMessages = null): PromiseInterface
14
    {
15
        return $this->api->banChatMember(
16
            chatId: $this->chat->id,
17
            userId: $this->newChatMember->user->id,
18
            untilDate: $untilDate,
19
            revokeMessages: $revokeMessages
20
        );
21
    }
22
23
    public function unban(?bool $onlyIfBanned = null): PromiseInterface
24
    {
25
        return $this->api->unbanChatMember(
26
            chatId: $this->chat->id,
27
            userId: $this->newChatMember->user->id,
28
            onlyIfBanned: $onlyIfBanned
29
        );
30
    }
31
32
    public function promote(
33
        ?bool $isAnonymous = null,
34
        ?bool $canManageChat = null,
35
        ?bool $canPostMessages = null,
36
        ?bool $canEditMessages = null,
37
        ?bool $canDeleteMessages = null,
38
        ?bool $canManageVoiceChats = null,
39
        ?bool $canRestrictMembers = null,
40
        ?bool $canPromoteMembers = null,
41
        ?bool $canChangeInfo = null,
42
        ?bool $canInviteUsers = null,
43
        ?bool $canPinMessages = null
44
    ): PromiseInterface {
45
        return $this->api->promoteChatMember(
46
            chatId: $this->chat->id,
47
            userId: $this->newChatMember->user->id,
48
            isAnonymous: $isAnonymous,
49
            canManageChat: $canManageChat,
50
            canPostMessages: $canPostMessages,
51
            canEditMessages: $canEditMessages,
52
            canDeleteMessages: $canDeleteMessages,
53
            canManageVoiceChats: $canManageVoiceChats,
54
            canRestrictMembers: $canRestrictMembers,
55
            canPromoteMembers: $canPromoteMembers,
56
            canChangeInfo: $canChangeInfo,
57
            canInviteUsers: $canInviteUsers,
58
            canPinMessages: $canPinMessages
59
        );
60
    }
61
62
    public function demote(): PromiseInterface
63
    {
64
        return $this->promote();
65
    }
66
67
    public function restrict(
68
        \Sysbot\Telegram\Types\ChatPermissions $permissions,
69
        ?int $untilDate = null
70
    ): PromiseInterface {
71
        return $this->api->restrictChatMember(
72
            chatId: $this->chat->id,
73
            userId: $this->newChatMember->user->id,
74
            permissions: $permissions,
75
            untilDate: $untilDate
76
        );
77
    }
78
79
    public function unrestrict(): PromiseInterface
80
    {
81
        return $this->promote();
82
    }
83
84
}