AnnotateTokenParser::parse()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 2
Metric Value
cc 3
eloc 13
c 3
b 1
f 2
nc 3
nop 1
dl 0
loc 21
rs 9.8333
1
<?php
2
/**
3
 * @author Gerard van Helden <[email protected]>
4
 * @copyright Zicht Online <http://zicht.nl>
5
 */
6
namespace Zicht\Bundle\FrameworkExtraBundle\Twig\Meta;
7
8
use Twig_Token;
9
10
/**
11
 * Class AnnotateTokenParser
12
 *
13
 * @package Zicht\Bundle\FrameworkExtraBundle\Twig\Meta
14
 */
15
class AnnotateTokenParser extends \Twig_TokenParser
16
{
17
    /**
18
     * Parses a token and returns a node.
19
     *
20
     * @param Twig_Token $token A Twig_Token instance
21
     *
22
     * @return AnnotateNode A Twig_NodeInterface instance
23
     */
24
    public function parse(Twig_Token $token)
25
    {
26
        $stream = $this->parser->getStream();
27
28
        $info = array();
29
        $first = $this->parser->getExpressionParser()->parseExpression();
30
31
        if ($stream->test(Twig_Token::BLOCK_END_TYPE)) {
32
            $info['expr']= $first;
33
        } else {
34
            $info['name']= $first;
35
            $info['expr']= $this->parser->getExpressionParser()->parseExpression();
36
            if (!$stream->test(Twig_Token::BLOCK_END_TYPE)) {
37
                $info['prio']= $this->parser->getExpressionParser()->parseExpression();
38
            }
39
        }
40
41
        $node = new AnnotateNode($info);
42
        $stream->expect(\Twig_Token::BLOCK_END_TYPE);
43
44
        return $node;
45
    }
46
47
    /**
48
     * Gets the tag name associated with this token parser.
49
     *
50
     * @return string The tag name
51
     */
52
    public function getTag()
53
    {
54
        return 'annotate';
55
    }
56
}
57