Completed
Push — master ( 2ed8e9...bac0b2 )
by Dev
07:05
created

AppExtension::checkPath()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 3
nc 2
nop 1
1
<?php
2
3
namespace PiedWeb\CMSBundle\Twig;
4
5
use Twig\Extension\AbstractExtension;
6
use Twig\TwigFilter;
7
use Symfony\Component\HttpFoundation\RequestStack;
8
use PiedWeb\RenderAttributes\AttributesTrait;
9
use PiedWeb\CMSBundle\Service\PageCanonicalService;
10
use Twig\TwigFunction;
11
12
class AppExtension extends AbstractExtension
13
{
14
    use AttributesTrait;
15
16
    public function __construct(PageCanonicalService $pageCanonical)
17
    {
18
        $this->pageCanonical = $pageCanonical;
1 ignored issue
show
Bug Best Practice introduced by
The property pageCanonical does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
19
    }
20
21
    public function getFunctions()
22
    {
23
        return [
24
            new TwigFunction('homepage', [$this->pageCanonical, 'generatePathForHomepage']),
25
            new TwigFunction('page', [$this->pageCanonical, 'generatePathForPage']),
26
            new TwigFunction('jslink', [AppExtension::class, 'renderJavascriptLink']),
27
        ];
28
    }
29
30
    public static function renderJavascriptLink($anchor, $path, $attr = [])
31
    {
32
        return '<span'.self::mergeAndMapAttributes($attr, ['data-href' => $path]).'>'.$anchor.'</span>';
33
    }
34
}
35