IncomingUpdateDispatcher::process()   B
last analyzed

Complexity

Conditions 7
Paths 5

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 56

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 0
cts 7
cp 0
rs 8.8333
c 0
b 0
f 0
cc 7
nc 5
nop 1
crap 56
1
<?php
2
3
namespace Skobkin\Bundle\PointToolsBundle\Service\Telegram;
4
5
use unreal4u\TelegramAPI\Telegram\Types\{Inline\Query, Message, Update};
6
7
/**
8
 * Dispatches incoming messages processing to corresponding services
9
 */
10
class IncomingUpdateDispatcher
11
{
12
    const CHAT_TYPE_PRIVATE = 'private';
13
    const CHAT_TYPE_GROUP = 'group';
14
15
    /** @var InlineQueryProcessor */
16
    private $inlineQueryProcessor;
17
18
    /** @var PrivateMessageProcessor */
19
    private $privateMessageProcessor;
20
21
22
    public function __construct(PrivateMessageProcessor $privateMessageProcessor, InlineQueryProcessor $inlineQueryProcessor)
23
    {
24
        $this->privateMessageProcessor = $privateMessageProcessor;
25
        $this->inlineQueryProcessor = $inlineQueryProcessor;
26
    }
27
28
    /**
29
     * Processes update and delegates it to corresponding service
30
     *
31
     * @param Update $update
32
     */
33
    public function process(Update $update): void
34
    {
35
        if ($update->message && $update->message instanceof Message) {
36
            $chatType = $update->message->chat->type;
37
38
            if (self::CHAT_TYPE_PRIVATE === $chatType) {
39
                $this->privateMessageProcessor->process($update->message);
40
            } elseif (self::CHAT_TYPE_GROUP === $chatType) {
41
                // @todo implement
42
            }
43
        } elseif ($update->inline_query && $update->inline_query instanceof Query) {
44
            $this->inlineQueryProcessor->process($update->inline_query);
45
        }
46
    }
47
}