SlapCommand   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 2
c 0
b 0
f 0
lcom 0
cbo 5
dl 0
loc 53
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B execute() 0 24 2
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\UserCommands;
12
13
use Longman\TelegramBot\Commands\UserCommand;
14
use Longman\TelegramBot\Request;
15
16
/**
17
 * User "/slap" command
18
 */
19
class SlapCommand extends UserCommand
20
{
21
    /**
22
     * @var string
23
     */
24
    protected $name = 'slap';
25
26
    /**
27
     * @var string
28
     */
29
    protected $description = 'Slap someone with their username';
30
31
    /**
32
     * @var string
33
     */
34
    protected $usage = '/slap <@user>';
35
36
    /**
37
     * @var string
38
     */
39
    protected $version = '1.1.0';
40
41
    /**
42
     * Command execute method
43
     *
44
     * @return mixed
45
     * @throws \Longman\TelegramBot\Exception\TelegramException
46
     */
47
    public function execute()
48
    {
49
        $message = $this->getMessage();
50
51
        $chat_id = $message->getChat()->getId();
52
        $text    = $message->getText(true);
53
54
        $sender = '@' . $message->getFrom()->getUsername();
55
56
        //username validation
57
        $test = preg_match('/@[\w_]{5,}/', $text);
58
        if ($test === 0) {
59
            $text = $sender . ' sorry no one to slap around..';
60
        } else {
61
            $text = $sender . ' slaps ' . $text . ' around a bit with a large trout';
62
        }
63
64
        $data = [
65
            'chat_id' => $chat_id,
66
            'text'    => $text,
67
        ];
68
69
        return Request::sendMessage($data);
70
    }
71
}
72