Completed
Pull Request — develop (#457)
by
unknown
03:35 queued 54s
created

EchoCommand::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 17
ccs 0
cts 14
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 10
nc 2
nop 0
crap 6
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 "/echo" command
18
 */
19
class EchoCommand extends UserCommand
20
{
21
    /**
22
     * @var string
23
     */
24
    protected $name = 'echo';
25
26
    /**
27
     * @var string
28
     */
29
    protected $description = 'Show text';
30
31
    /**
32
     * @var string
33
     */
34
    protected $usage = '/echo <text>';
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
        $chat_id = $message->getChat()->getId();
51
        $text    = trim($message->getText(true));
52
53
        if ($text === '') {
54
            $text = 'Command usage: ' . $this->getUsage();
55
        }
56
57
        $data = [
58
            'chat_id' => $chat_id,
59
            'text'    => $text,
60
        ];
61
62
        return Request::sendMessage($data);
63
    }
64
}
65