XlsRowTokenParser::parse()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 2
nop 1
1
<?php
2
3
namespace MewesK\TwigExcelBundle\Twig\TokenParser;
4
5
use MewesK\TwigExcelBundle\Twig\Node\XlsRowNode;
6
use Twig_Node_Expression_Constant;
7
use Twig_Token;
8
9
/**
10
 * Class XlsRowTokenParser
11
 *
12
 * @package MewesK\TwigExcelBundle\Twig\TokenParser
13
 */
14
class XlsRowTokenParser extends AbstractTokenParser
15
{
16
    /**
17
     * @param Twig_Token $token
18
     *
19
     * @return XlsRowNode
20
     * @throws \Twig_Error_Syntax
21
     */
22
    public function parse(Twig_Token $token)
23
    {
24
        // parse attributes
25
        $index = new Twig_Node_Expression_Constant(null, $token->getLine());
26
        if (!$this->parser->getStream()->test(Twig_Token::BLOCK_END_TYPE)) {
27
            $index = $this->parser->getExpressionParser()->parseExpression();
28
        }
29
        $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
30
31
        // parse body
32
        $body = $this->parseBody();
33
34
        // return node
35
        return new XlsRowNode($index, $body, $token->getLine(), $this->getTag());
36
    }
37
38
    /**
39
     * @return string
40
     */
41
    public function getTag()
42
    {
43
        return 'xlsrow';
44
    }
45
}
46