Completed
Push — master ( 3af88c...d76c98 )
by Mewes
05:10
created

XlsDocumentTokenParser::removeTextNodesRecursively()   B

Complexity

Conditions 9
Paths 4

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

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