XlsDocumentNode   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 62
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A compile() 0 16 3
A getAllowedParents() 0 4 1
A canContainText() 0 4 1
1
<?php
2
3
namespace MewesK\TwigExcelBundle\Twig\Node;
4
5
use Twig_Compiler;
6
use Twig_Node;
7
use Twig_Node_Expression;
8
9
/**
10
 * Class XlsDocumentNode
11
 *
12
 * @package MewesK\TwigExcelBundle\Twig\Node
13
 */
14
class XlsDocumentNode extends Twig_Node implements SyntaxAwareNodeInterface
15
{
16
    /**
17
     * @var bool
18
     */
19
    private $preCalculateFormulas;
20
    /**
21
     * @var null|string
22
     */
23
    private $diskCachingDirectory;
24
25
    /**
26
     * @param Twig_Node_Expression $properties
27
     * @param Twig_Node $body
28
     * @param int $line
29
     * @param string $tag
30
     * @param bool $preCalculateFormulas
31
     * @param null|string $diskCachingDirectory
32
     */
33
    public function __construct(Twig_Node_Expression $properties, Twig_Node $body, $line = 0, $tag = 'xlsdocument', $preCalculateFormulas = true, $diskCachingDirectory = null)
34
    {
35
        parent::__construct(['properties' => $properties, 'body' => $body], [], $line, $tag);
36
        $this->preCalculateFormulas = $preCalculateFormulas;
37
        $this->diskCachingDirectory = $diskCachingDirectory;
38
    }
39
40
    /**
41
     * @param Twig_Compiler $compiler
42
     */
43
    public function compile(Twig_Compiler $compiler)
44
    {
45
        $compiler->addDebugInfo($this)
46
            ->write('$documentProperties = ')
47
            ->subcompile($this->getNode('properties'))
48
            ->raw(';' . PHP_EOL)
49
            ->write('$context[\'phpExcel\'] = new MewesK\TwigExcelBundle\Wrapper\PhpExcelWrapper($context, $this->env);' . PHP_EOL)
50
            ->write('$context[\'phpExcel\']->startDocument($documentProperties);' . PHP_EOL)
51
            ->write('unset($documentProperties);' . PHP_EOL)
52
            ->subcompile($this->getNode('body'))
53
            ->addDebugInfo($this)
54
            ->write('$context[\'phpExcel\']->endDocument(' .
55
                ($this->preCalculateFormulas ? 'true' : 'false') . ', ' .
56
                ($this->diskCachingDirectory ? '\'' . $this->diskCachingDirectory . '\'' : 'null') . ');' . PHP_EOL)
57
            ->write('unset($context[\'phpExcel\']);' . PHP_EOL);
58
    }
59
60
    /**
61
     * @return string[]
62
     */
63
    public function getAllowedParents()
64
    {
65
        return [];
66
    }
67
68
    /**
69
     * @return bool
70
     */
71
    public function canContainText()
72
    {
73
        return false;
74
    }
75
}
76