Completed
Push — master ( 59b9fb...b4679f )
by Vladimir
02:55
created

CommandHandler::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
ccs 3
cts 3
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FondBot\Drivers;
6
7
use RuntimeException;
8
use FondBot\Drivers\Commands\SendMessage;
9
use FondBot\Drivers\Commands\SendRequest;
10
use FondBot\Drivers\Commands\SendAttachment;
11
12
abstract class CommandHandler
13
{
14
    protected $driver;
15
16 2
    public function __construct(Driver $driver)
17
    {
18 2
        $this->driver = $driver;
19 2
    }
20
21
    abstract public function handleSendMessage(SendMessage $command): void;
22
23
    abstract public function handleSendAttachment(SendAttachment $command): void;
24
25
    abstract public function handleSendRequest(SendRequest $command): void;
26
27
    /**
28
     * @param Command $command
29
     *
30
     * @throws RuntimeException
31
     */
32 2
    public function handle(Command $command): void
33
    {
34 2
        $method = 'handle'.ucfirst($command->getName());
35
36 2
        if (!method_exists($this, $method)) {
37 1
            throw new RuntimeException('No handle method for "'.$command->getName().'".');
38
        }
39
40 1
        $this->$method($command);
41 1
    }
42
}
43