Completed
Push — master ( c391fd...ad5ea5 )
by Kirill
02:54
created

UpdateReceiver::findGame()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 17
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
c 0
b 0
f 0
rs 9.4285
cc 3
eloc 12
nc 3
nop 1
1
<?php
2
3
namespace Chrl\AppBundle\UpdateReceiver;
4
5
use Chrl\AppBundle\BuktopuhaBotApi;
6
use Chrl\AppBundle\Service\GameService;
7
use Chrl\AppBundle\Type\Update;
8
use Doctrine\ORM\EntityManagerInterface;
9
10
class UpdateReceiver implements UpdateReceiverInterface
11
{
12
13
    private $config;
14
    private $telegramBotApi;
15
    private $entityManager;
16
17
    private $gameService;
18
19
    public function __construct(
20
        BuktopuhaBotApi $telegramBotApi,
21
        $config,
22
        EntityManagerInterface $entityManager,
23
        GameService $gameService
24
    ) {
25
    
26
        $this->telegramBotApi = $telegramBotApi;
27
        $this->config = $config;
28
        $this->entityManager = $entityManager;
29
        $this->gameService = $gameService;
30
    }
31
32
    public function handleUpdate(Update $update)
33
    {
34
        $message = json_decode(json_encode($update->message), true);
35
        $user = $this->gameService->getCurrentUser($message);
36
        $this->telegramBotApi->sendMessage(
37
            $message['chat']['id'],
38
            '@'.$user->getAlias().', hello from '.$this->config['bot_name']
39
        );
40
    }
41
}
42