ChatPermissions   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 8
c 1
b 0
f 0
dl 0
loc 18
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A applyOn() 0 11 2
A __construct() 0 2 1
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
}