GenericCommand   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 3
c 0
b 0
f 0
lcom 1
cbo 6
dl 0
loc 45
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A execute() 0 21 3
1
<?php
2
/**
3
 * This file is part of the TelegramBot package.
4
 *
5
 * (c) Avtandil Kikabidze aka LONGMAN <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Longman\TelegramBot\Commands\SystemCommands;
12
13
use Longman\TelegramBot\Commands\SystemCommand;
14
use Longman\TelegramBot\Request;
15
16
/**
17
 * Generic command
18
 */
19
class GenericCommand extends SystemCommand
20
{
21
    /**
22
     * @var string
23
     */
24
    protected $name = 'Generic';
25
26
    /**
27
     * @var string
28
     */
29
    protected $description = 'Handles generic commands or is executed by default when a command is not found';
30
31
    /**
32
     * @var string
33
     */
34
    protected $version = '1.1.0';
35
36
    /**
37
     * Command execute method
38
     *
39
     * @return mixed
40
     * @throws \Longman\TelegramBot\Exception\TelegramException
41
     */
42
    public function execute()
43
    {
44
        $message = $this->getMessage();
45
46
        //You can use $command as param
47
        $chat_id = $message->getChat()->getId();
48
        $user_id = $message->getFrom()->getId();
49
        $command = $message->getCommand();
50
51
        //If the user is and admin and the command is in the format "/whoisXYZ", call the /whois command
52
        if (stripos($command, 'whois') === 0 && $this->telegram->isAdmin($user_id)) {
53
            return $this->telegram->executeCommand('whois');
54
        }
55
56
        $data = [
57
            'chat_id' => $chat_id,
58
            'text'    => 'Command /' . $command . ' not found.. :(',
59
        ];
60
61
        return Request::sendMessage($data);
62
    }
63
}
64