CacheTagExtension   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 80%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 45
ccs 8
cts 10
cp 0.8
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getFunctions() 0 6 1
A addTag() 0 4 1
A getName() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the FOSHttpCacheBundle package.
5
 *
6
 * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
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 FOS\HttpCacheBundle\Twig;
13
14
use FOS\HttpCache\ResponseTagger;
15
use Twig\Extension\AbstractExtension;
16
use Twig\TwigFunction;
17
18
/**
19
 * A Twig extension to allow adding cache tags from twig templates.
20
 */
21
class CacheTagExtension extends AbstractExtension
22
{
23
    /**
24
     * @var ResponseTagger
25
     */
26
    private $responseTagger;
27
28 3
    public function __construct(ResponseTagger $responseTagger)
29
    {
30 3
        $this->responseTagger = $responseTagger;
31 3
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36 2
    public function getFunctions()
37
    {
38
        return [
39 2
            new TwigFunction('fos_httpcache_tag', [$this, 'addTag']),
40
        ];
41
    }
42
43
    /**
44
     * Add a single tag or an array of tags to the response.
45
     *
46
     * The tag string is *not* further processed, you can't use a comma
47
     * separated string to pass several tags but need to build a twig array.
48
     *
49
     * Calling this twig function adds nothing to the output.
50
     *
51
     * @param string|array $tag
52
     */
53 1
    public function addTag($tag)
54
    {
55 1
        $this->responseTagger->addTags((array) $tag);
56 1
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61
    public function getName()
62
    {
63
        return 'fos_httpcache_tag_extension';
64
    }
65
}
66