Completed
Push — master ( 959e53...d74161 )
by Vladimir
12:00
created

TemplateRenderer   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 32
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
renderKeyboard() 0 1 ?
A render() 0 13 2
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 TemplateRenderer
11
{
12
    /**
13
     * Render keyboard.
14
     *
15
     * @param Keyboard $keyboard
16
     *
17
     * @return Type|null
18
     */
19
    abstract protected function renderKeyboard(Keyboard $keyboard): ?Type;
20
21
    /**
22
     * Compile template.
23
     *
24
     * @param Template $template
25
     *
26
     * @return Type|mixed|null
27
     */
28 2
    public function render(Template $template)
29
    {
30
        // Otherwise, we look for a compile method
31 2
        $method = 'render'.ucfirst($template->getName());
32 2
        if (!method_exists($this, $method)) {
33 1
            return null;
34
        }
35
36
        /** @var Type $type */
37 1
        $type = $this->$method($template);
38
39 1
        return $type->toNative() ?? $type;
40
    }
41
}
42