Passed
Push — master ( 1145e4...3a5c01 )
by Alexey
03:43
created

IncomingUpdateDispatcher   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 42
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 42
ccs 0
cts 17
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;
6
use unreal4u\TelegramAPI\Telegram\Types\Message;
7
use unreal4u\TelegramAPI\Telegram\Types\Update;
8
9
/**
10
 * Dispatches incoming messages processing to corresponding services
11
 */
12
class IncomingUpdateDispatcher
13
{
14
    const CHAT_TYPE_PRIVATE = 'private';
15
    const CHAT_TYPE_GROUP = 'group';
16
17
    /**
18
     * @var InlineQueryProcessor
19
     */
20
    private $inlineQueryProcessor;
21
22
    /**
23
     * @var PrivateMessageProcessor
24
     */
25
    private $privateMessageProcessor;
26
27
28
    public function __construct(PrivateMessageProcessor $privateMessageProcessor, InlineQueryProcessor $inlineQueryProcessor)
29
    {
30
        $this->privateMessageProcessor = $privateMessageProcessor;
31
        $this->inlineQueryProcessor = $inlineQueryProcessor;
32
    }
33
34
    /**
35
     * Processes update and delegates it to corresponding service
36
     *
37
     * @param Update $update
38
     */
39
    public function process(Update $update)
40
    {
41
        if ($update->message && $update->message instanceof Message) {
42
            $chatType = $update->message->chat->type;
43
44
            if (self::CHAT_TYPE_PRIVATE === $chatType) {
45
                $this->privateMessageProcessor->process($update->message);
46
            } elseif (self::CHAT_TYPE_GROUP === $chatType) {
1 ignored issue
show
Unused Code introduced by
This elseif statement is empty, and could be removed.

This check looks for the bodies of elseif statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These elseif bodies can be removed. If you have an empty elseif but statements in the else branch, consider inverting the condition.

Loading history...
47
                // @todo implement
48
            }
49
        } elseif ($update->inline_query && $update->inline_query instanceof Query) {
50
            $this->inlineQueryProcessor->process($update->inline_query);
51
        }
52
    }
53
}