AmpExtension::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the takeit/AmpHtmlBundle package.
5
 *
6
 * (c) Rafał Muszyński <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Takeit\Bundle\AmpHtmlBundle\Twig;
13
14
use Twig\Extension\AbstractExtension;
15
use Twig\TwigFilter;
16
17
18
use Takeit\Bundle\AmpHtmlBundle\Generator\AmpUrlGeneratorInterface;
19
20
/**
21
 * AMP Twig Extension.
22
 */
23
class AmpExtension extends AbstractExtension
24
{
25
    /**
26
     * @var AmpUrlGeneratorInterface
27
     */
28
    private $ampUrlGenerator;
29
30
    /**
31
     * @param AmpUrlGeneratorInterface $ampUrlGenerator
32
     */
33
    public function __construct(AmpUrlGeneratorInterface $ampUrlGenerator)
34
    {
35
        $this->ampUrlGenerator = $ampUrlGenerator;
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function getFilters()
42
    {
43
        return array(
44
            new TwigFilter('amp', array($this, 'ampFilter')),
45
        );
46
    }
47
48
    /**
49
     * Returns an AMP URL.
50
     *
51
     * @param $url URL
52
     *
53
     * @return string
54
     */
55
    public function ampFilter($url)
56
    {
57
        return $this->ampUrlGenerator->generate($url);
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63
    public function getName()
64
    {
65
        return 'takeit_amp_extension';
66
    }
67
}
68