NewchatmemberCommand::execute()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 19
rs 9.4285
cc 2
eloc 11
nc 2
nop 0
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
 * New chat member command
18
 */
19
class NewchatmemberCommand extends SystemCommand
20
{
21
    /**
22
     * @var string
23
     */
24
    protected $name = 'Newchatmember';
25
26
    /**
27
     * @var string
28
     */
29
    protected $description = 'New Chat Member';
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
        $chat_id = $message->getChat()->getId();
47
        $member  = $message->getNewChatMember();
48
        $text    = 'Hi there!';
49
50
        if (!$message->botAddedInChat()) {
51
            $text = 'Hi ' . $member->tryMention() . '!';
52
        }
53
54
        $data = [
55
            'chat_id' => $chat_id,
56
            'text'    => $text,
57
        ];
58
59
        return Request::sendMessage($data);
60
    }
61
}
62