Passed
Push — master ( df4cce...a240aa )
by
02:18
created

CommandHandler   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 43
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handle() 0 18 3
1
<?php
2
3
/*
4
 * This file is part of the LineMob package.
5
 *
6
 * (c) Ishmael Doss <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace LineMob\Core;
13
14
use LineMob\Core\Command\AbstractCommand;
15
use LineMob\Core\Factory\MessageFactoryInterface;
16
use LineMob\Core\Sender\SenderInterface;
17
18
/**
19
 * @author Ishmael Doss <[email protected]>
20
 */
21
class CommandHandler implements CommandHandlerInterface
22
{
23
    /**
24
     * @var SenderInterface
25
     */
26
    protected $sender;
27
28
    /**
29
     * @var MessageFactoryInterface
30
     */
31
    protected $factory;
32
33
    /**
34
     * @param SenderInterface $sender
35
     * @param MessageFactoryInterface $factory
36
     */
37
    public function __construct(SenderInterface $sender, MessageFactoryInterface $factory)
38
    {
39
        $this->sender = $sender;
40
        $this->factory = $factory;
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    public function handle(AbstractCommand $command)
47
    {
48
        $message = $this->factory->createMessage($command);
49
50
        switch ($command->mode) {
51
            case Constants::MODE_MULTICAST:
52
                $result = $this->sender->multicast($command->tos, $message);
53
                break;
54
55
            case Constants::MODE_PUSH:
56
                $result = $this->sender->pushMessage($command->to, $message);
57
                break;
58
59
            default:
60
                $result = $this->sender->replyMessage($command->input->replyToken, $message);
61
        }
62
63
        return $result;
64
    }
65
}
66