AnnotationsTokenParser::parse()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 6
c 1
b 0
f 1
nc 1
nop 1
dl 0
loc 10
rs 10
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 AnnotationsTokenParser
12
 *
13
 * @package Zicht\Bundle\FrameworkExtraBundle\Twig\Meta
14
 */
15
class AnnotationsTokenParser 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 AnnotationsNode A Twig_NodeInterface instance
23
     */
24
    public function parse(Twig_Token $token)
25
    {
26
        $stream = $this->parser->getStream();
27
28
        $stream->expect(Twig_Token::BLOCK_END_TYPE);
29
        $body = $this->parser->subparse(array($this, 'decideEndAnnotations'));
30
        $stream->expect('endannotations');
31
        $stream->expect(Twig_Token::BLOCK_END_TYPE);
32
33
        return new AnnotationsNode(array('body' => $body));
34
    }
35
36
    /**
37
     * Gets the tag name associated with this token parser.
38
     *
39
     * @return string The tag name
40
     */
41
    public function getTag()
42
    {
43
        return 'annotations';
44
    }
45
46
    /**
47
     * Decide end annotations
48
     *
49
     * @param string $token
50
     * @return mixed
51
     */
52
    public function decideEndAnnotations($token)
53
    {
54
        return $token->test('endannotations');
55
    }
56
}
57