StrictTokenParser   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 39
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A parse() 0 14 1
A decideEnd() 0 3 1
A getTag() 0 3 1
1
<?php
2
/**
3
 * @author Gerard van Helden <[email protected]>
4
 * @copyright Zicht Online <http://zicht.nl>
5
 */
6
namespace Zicht\Bundle\FrameworkExtraBundle\Twig\ControlStructures;
7
8
use Twig_TokenParser;
9
use Twig_Token;
10
11
/**
12
 * The token parser for a StrictNode node. See StrictNode for more info.
13
 */
14
class StrictTokenParser extends Twig_TokenParser
15
{
16
    /**
17
     * @{inheritDoc}
18
     */
19
    public function getTag()
20
    {
21
        return 'strict';
22
    }
23
24
    /**
25
     * @{inheritDoc}
26
     */
27
    public function parse(Twig_Token $token)
28
    {
29
        $lineno = $token->getLine();
30
31
        $strictExpr = $this->parser->getExpressionParser()->parseExpression();
32
33
        /** @var $stream \Twig_TokenStream */
34
        $stream = $this->parser->getStream();
35
        $stream->expect(Twig_Token::BLOCK_END_TYPE);
36
37
        $body = $this->parser->subparse(array($this, 'decideEnd'), true);
38
        $stream->expect(Twig_Token::BLOCK_END_TYPE);
39
40
        return new StrictNode(['body' => $body, 'expr' => $strictExpr], [], $lineno);
41
    }
42
43
44
    /**
45
     * Checks if the token is part of the current control structure.
46
     *
47
     * @param Twig_Token $token
48
     * @return mixed
49
     */
50
    public function decideEnd($token)
51
    {
52
        return $token->test(array('endstrict'));
53
    }
54
}
55