Completed
Push — master ( 8e6a11...bb5baa )
by Kirill
02:44
created

UpdateReceiver::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
3
namespace AppBundle\UpdateReceiver;
4
5
use Shaygan\TelegramBotApiBundle\TelegramBotApi;
6
use Shaygan\TelegramBotApiBundle\Type\Update;
7
use Shaygan\TelegramBotApiBundle\UpdateReceiver\UpdateReceiverInterface;
8
9
10
class UpdateReceiver implements UpdateReceiverInterface
11
{
12
13
	private $config;
14
	private $telegramBotApi;
15
16
	public function __construct(TelegramBotApi $telegramBotApi, $config)
17
	{
18
		$this->telegramBotApi = $telegramBotApi;
19
		$this->config = $config;
20
	}
21
22
	public function handleUpdate(Update $update)
23
	{
24
		$message = json_decode(json_encode($update->message), true);
25
26
		switch ($message['text']) {
27
			case "/about":
28
			case "/about@{$this->config['bot_name']}":
29
				$text = "I'm a Buktopuha Telegram Bot";
30
				break;
31
			case "/help":
32
			case "/help@{$this->config['bot_name']}":
33
			default :
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a DEFAULT statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in the default statement.

switch ($expr) {
    default : //wrong
        doSomething();
        break;
}

switch ($expr) {
    default: //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
34
				$text = "Command List:\n";
35
				$text .= "/about - About this bot\n";
36
				$text .= "/help - show this help message\n";
37
				break;
38
		}
39
40
		$this->telegramBotApi->sendMessage($message['chat']['id'], $text);
41
	}
42
}
43