Completed
Push — master ( fa1d47...a128d4 )
by Vladimir
04:16
created

TemplateCompiler::compile()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 10
ccs 5
cts 5
cp 1
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FondBot\Drivers;
6
7
use FondBot\Contracts\Template;
8
use FondBot\Templates\Keyboard;
9
10
abstract class TemplateCompiler
11
{
12
    /**
13
     * Compile keyboard.
14
     *
15
     * @param Keyboard $keyboard
16
     *
17
     * @return Type|null
18
     */
19
    abstract protected function compileKeyboard(Keyboard $keyboard): ?Type;
20
21
    /**
22
     * Compile template.
23
     *
24
     * @param Template $template
25
     *
26
     * @return Type|null
27
     */
28 2
    public function compile(Template $template): ?Type
29
    {
30
        // Otherwise, we look for a compile method
31 2
        $method = 'compile'.ucfirst($template->getName());
32 2
        if (!method_exists($this, $method)) {
33 1
            return null;
34
        }
35
36 1
        return $this->$method($template);
37
    }
38
}
39