ChatPermissions::applyOn()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 11
rs 10
cc 2
nc 2
nop 3
1
<?php
2
3
4
namespace Sysbot\Telegram\ExtendedTypes;
5
6
7
use GuzzleHttp\Promise\PromiseInterface;
8
use Sysbot\Telegram\API;
9
10
trait ChatPermissions
11
{
12
13
    public function __construct(protected ?API $api)
14
    {
15
    }
16
17
    public function applyOn(int|string $chatId, ?int $userId = null, ?int $untilDate = null): ?PromiseInterface
18
    {
19
        /** @var \Sysbot\Telegram\Types\ChatPermissions $this */
20
        if (empty($userId)) {
21
            return $this->api?->setChatPermissions(chatId: $chatId, permissions: $this);
22
        }
23
        return $this->api?->restrictChatMember(
24
            chatId: $chatId,
25
            userId: $userId,
26
            permissions: $this,
27
            untilDate: $untilDate
28
        );
29
    }
30
31
}