IncomingUpdateDispatcher   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 5
dl 0
loc 38
ccs 0
cts 12
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
B process() 0 14 7
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
}