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

TemplateCompiler::compile()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
ccs 5
cts 5
cp 1
crap 2
rs 9.6666
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FondBot\Drivers;
6
7
use RuntimeException;
8
use FondBot\Contracts\Template;
9
use FondBot\Templates\Keyboard;
10
use FondBot\Templates\Keyboard\UrlButton;
11
use FondBot\Templates\Keyboard\ReplyButton;
12
use FondBot\Templates\Keyboard\PayloadButton;
13
14
abstract class TemplateCompiler
15
{
16
    abstract public function compileKeyboard(Keyboard $keyboard);
17
18
    abstract public function compilePayloadButton(PayloadButton $button);
19
20
    abstract public function compileReplyButton(ReplyButton $button);
21
22
    abstract public function compileUrlButton(UrlButton $button);
23
24
    /**
25
     * Compile template.
26
     *
27
     * @param Template $template
28
     *
29
     * @return mixed
30
     *
31
     * @throws RuntimeException
32
     */
33 2
    public function compile(Template $template)
34
    {
35 2
        $method = 'compile'.ucfirst($template->getName());
36 2
        if (!method_exists($this, $method)) {
37 1
            throw new RuntimeException('No compile method for "'.$template->getName().'".');
38
        }
39
40 1
        return $this->$method($template);
41
    }
42
}
43