XlsDocumentTokenParser::parse()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 1
1
<?php
2
3
namespace MewesK\TwigExcelBundle\Twig\TokenParser;
4
5
use MewesK\TwigExcelBundle\Twig\Node\XlsDocumentNode;
6
use MewesK\TwigExcelBundle\Twig\NodeHelper;
7
use Twig_Token;
8
9
/**
10
 * Class XlsDocumentTokenParser
11
 *
12
 * @package MewesK\TwigExcelBundle\Twig\TokenParser
13
 */
14
class XlsDocumentTokenParser extends AbstractTokenParser
15
{
16
    /**
17
     * @var bool
18
     */
19
    private $preCalculateFormulas;
20
    /**
21
     * @var null|string
22
     */
23
    private $diskCachingDirectory;
24
25
    /**
26
     * @param bool $preCalculateFormulas
27
     * @param null|string $diskCachingDirectory
28
     */
29
    public function __construct($preCalculateFormulas = true, $diskCachingDirectory = null)
30
    {
31
        $this->preCalculateFormulas = $preCalculateFormulas;
32
        $this->diskCachingDirectory = $diskCachingDirectory;
33
    }
34
35
    /**
36
     * @param Twig_Token $token
37
     *
38
     * @return XlsDocumentNode
39
     * @throws \Twig_Error_Syntax
40
     */
41
    public function parse(Twig_Token $token)
42
    {
43
        // parse attributes
44
        $properties = $this->parseProperties($token);
45
        $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
46
47
        // parse body
48
        $body = $this->parseBody();
49
        NodeHelper::removeTextNodesRecursively($body, $this->parser);
50
        NodeHelper::fixMacroCallsRecursively($body);
51
52
        // return node
53
        return new XlsDocumentNode($properties, $body, $token->getLine(), $this->getTag(), $this->preCalculateFormulas, $this->diskCachingDirectory);
54
    }
55
56
    /**
57
     * @return string
58
     */
59
    public function getTag()
60
    {
61
        return 'xlsdocument';
62
    }
63
}
64