LexerManager   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 65
ccs 19
cts 19
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getDefaultLexer() 0 4 1
A updateLexer() 0 4 1
A rollbackLexer() 0 4 1
A getNewLexer() 0 10 1
1
<?php
2
3
namespace Chris\Bundle\FrontRenderBundle\Twig;
4
5
use Twig_Environment;
6
use Twig_Lexer;
7
8
class LexerManager
9
{
10
    /**
11
     * @var Twig_Environment
12
     */
13
    protected $twig;
14
15
    /**
16
     * @var Twig_Lexer
17
     */
18
    protected $defaultLexer;
19
20
    /**
21
     * LexerManager constructor.
22
     *
23
     * @param Twig_Environment $twig
24
     */
25 12
    public function __construct(Twig_Environment $twig)
26
    {
27 12
        $this->defaultLexer = $twig->getLexer();
28 12
        $this->twig         = $twig;
29 12
    }
30
31
    /**
32
     * Get DefaultLexer
33
     *
34
     * @return Twig_Lexer
35
     */
36 2
    public function getDefaultLexer()
37
    {
38 2
        return $this->defaultLexer;
39
    }
40
41
    /**
42
     * Set the custom twig lexer to display custom tags on the front
43
     */
44 1
    public function updateLexer()
45
    {
46 1
        $this->twig->setLexer($this->getNewLexer());
47 1
    }
48
49
    /**
50
     * Rollback the lexer of twig
51
     */
52 2
    public function rollbackLexer()
53
    {
54 2
        $this->twig->setLexer($this->getDefaultLexer());
55 2
    }
56
57
    /**
58
     * Retrieve the custom twig lexer for the front
59
     *
60
     * @return Twig_Lexer
61
     */
62 9
    public function getNewLexer()
63
    {
64 9
        $lexer = new Twig_Lexer($this->twig, [
65 9
            'tag_comment'  => ['{*', '*}'],
66 9
            'tag_block'    => ['{@', '@}'],
67 9
            'tag_variable' => ['{$', '$}'],
68 9
        ]);
69
70 9
        return $lexer;
71
    }
72
}
73