Completed
Push — master ( 02086d...3ba854 )
by Mike
03:44 queued 01:47
created

TemplateExtension   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 66.67%

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 34
ccs 6
cts 9
cp 0.6667
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A twigTemplate() 0 3 1
A getFunctions() 0 11 1
1
<?php
2
declare(strict_types=1);
3
4
5
namespace Xervice\Atomic\Business\Twig\Extension;
6
7
8
class TemplateExtension extends \Twig_Extension
9
{
10
    protected const FUNCTION_NAME = 'template';
11
12
    protected const MODULE = 'Atomic';
13
14
    /**
15
     * @return array|\Twig_Function[]
16
     */
17 1
    public function getFunctions(): array
18
    {
19
        return [
20 1
            new \Twig_SimpleFunction(
21 1
                self::FUNCTION_NAME,
22
                function (string $templateName, string $templateModule = self::MODULE) {
23
                    return $this->twigTemplate($templateName, $templateModule);
24 1
                },
25
                [
26 1
                    $this,
27 1
                    self::FUNCTION_NAME
28
                ]
29
            )
30
        ];
31
    }
32
33
    /**
34
     * @param $templateName
35
     * @param $templateModule
36
     *
37
     * @return string
38
     */
39
    private function twigTemplate(string $templateName, string $templateModule): string
40
    {
41
        return '@' . $templateModule . '/templates/' . $templateName . '/' . $templateName . '.twig';
42
    }
43
44
}