Passed
Push — master ( fbc72e...fd2e1d )
by Alexey
04:39
created

WebHookController::receiveUpdateAction()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 9
nc 2
nop 2
1
<?php
2
3
namespace Skobkin\Bundle\PointToolsBundle\Controller\Telegram;
4
5
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
6
use Symfony\Component\HttpFoundation\JsonResponse;
7
use Symfony\Component\HttpFoundation\Request;
8
use unreal4u\TelegramAPI\Telegram\Types\Update;
9
10
/**
11
 * {@inheritdoc}
12
 */
13
class WebHookController extends Controller
14
{
15
    public function receiveUpdateAction(Request $request, $token)
16
    {
17
        if ($token !== $savedToken = $this->getParameter('telegram_token')) {
18
            throw $this->createNotFoundException();
19
        }
20
21
        $content = json_decode($request->getContent(), true);
22
23
        $update = new Update(
24
            $content,
25
            $this->get('logger')
26
        );
27
28
        $this->get('point_tools.telegram.update_processor')->process($update);
29
30
        return new JsonResponse('received');
31
    }
32
}
33