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

PageExtension::getFunctions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1.0028

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 0
dl 0
loc 11
ccs 6
cts 7
cp 0.8571
crap 1.0028
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
5
namespace Xervice\Atomic\Business\Twig\Extension;
6
7
8
class PageExtension extends \Twig_Extension
9
{
10
    protected const FUNCTION_NAME = 'page';
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 $pageName, string $pageModule = self::MODULE) {
23
                    return $this->twigPage($pageName, $pageModule);
24 1
                },
25
                [
26 1
                    $this,
27 1
                    self::FUNCTION_NAME
28
                ]
29
            )
30
        ];
31
    }
32
33
    /**
34
     * @param $pageName
35
     * @param $pageModule
36
     *
37
     * @return string
38
     */
39
    private function twigPage(string $pageName, string $pageModule): string
40
    {
41
        return '@' . $pageModule . '/pages/' . $pageName . '/' . $pageName . '.twig';
42
    }
43
44
}