BotCommand   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A remove() 0 10 1
A add() 0 6 1
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
use Sysbot\Telegram\Types\BotCommandScope;
10
11
trait BotCommand
12
{
13
14
    public function __construct(protected ?API $api)
15
    {
16
    }
17
18
    public function add(?BotCommandScope $scope = null, ?string $languageCode = null): ?PromiseInterface
19
    {
20
        return $this->api?->getMyCommands(scope: $scope, languageCode: $languageCode)->then(
21
            function (array $commands) use ($scope, $languageCode) {
22
                $commands = array_merge($commands, [$this]);
23
                return $this->api->setMyCommands(commands: $commands, scope: $scope, languageCode: $languageCode);
0 ignored issues
show
Bug introduced by
The method setMyCommands() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

23
                return $this->api->/** @scrutinizer ignore-call */ setMyCommands(commands: $commands, scope: $scope, languageCode: $languageCode);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
24
            }
25
        );
26
    }
27
28
    public function remove(?BotCommandScope $scope = null, ?string $languageCode = null): ?PromiseInterface
29
    {
30
        return $this->api?->getMyCommands(scope: $scope, languageCode: $languageCode)->then(
31
            function (array $commands) use ($scope, $languageCode) {
32
                $commands = array_udiff(
33
                    $commands,
34
                    [$this],
35
                    fn(BotCommand $a, BotCommand $b) => $a->command <=> $b->command
36
                );
37
                return $this->api->setMyCommands(commands: $commands, scope: $scope, languageCode: $languageCode);
38
            }
39
        );
40
    }
41
42
}