Completed
Push — master ( f08a7c...72129a )
by Tobias
10:06
created

TranslationExtension::setRequestStack()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
/*
4
 * This file is part of the PHP Translation package.
5
 *
6
 * (c) PHP Translation team <[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 Translation\Bundle\Twig;
13
14
use Symfony\Component\HttpFoundation\RequestStack;
15
use Translation\Bundle\EditInPlace\ActivatorInterface;
16
17
/**
18
 * Override the `trans` functions `is_safe` option to allow HTML output from the
19
 * translator. This extension is used by for the EditInPlace feature.
20
 *
21
 * @author Damien Alexandre <[email protected]>
22
 */
23
class TranslationExtension extends \Symfony\Bridge\Twig\Extension\TranslationExtension
24
{
25
    /**
26
     * @var ActivatorInterface
27
     */
28
    private $activator;
29
30
    /**
31
     * @var RequestStack
32
     */
33
    private $requestStack;
34
35
    /**
36
     * {@inheritdoc}
37
     */
38 1
    public function getFilters()
39
    {
40
        return [
41 1
            new \Twig_SimpleFilter('trans', [$this, 'trans'], ['is_safe_callback' => [$this, 'isSafe']]),
42 1
            new \Twig_SimpleFilter('transchoice', [$this, 'transchoice'], ['is_safe_callback' => [$this, 'isSafe']]),
43 1
        ];
44
    }
45
46
    /**
47
     * Escape output if the EditInPlace is disabled.
48
     *
49
     * @return array
50
     */
51 1
    public function isSafe($node)
0 ignored issues
show
Unused Code introduced by
The parameter $node is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
52
    {
53 1
        return $this->activator->checkRequest($this->requestStack->getMasterRequest()) ? [] : ['html'];
54
    }
55
56
    /**
57
     * @param ActivatorInterface $activator
58
     */
59 3
    public function setActivator(ActivatorInterface $activator)
60
    {
61 3
        $this->activator = $activator;
62 3
    }
63
64
    /**
65
     * @param RequestStack $requestStack
66
     */
67 3
    public function setRequestStack(RequestStack $requestStack)
68
    {
69 3
        $this->requestStack = $requestStack;
70 3
    }
71
72
    /**
73
     * {@inheritdoc}
74
     */
75
    public function getName()
76
    {
77
        return self::class;
78
    }
79
}
80