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

XlsSheetNode   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 6
Bugs 0 Features 2
Metric Value
wmc 5
c 6
b 0
f 2
lcom 0
cbo 2
dl 0
loc 54
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A compile() 0 18 2
A getAllowedParents() 0 6 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 XlsSheetNode
11
 *
12
 * @package MewesK\TwigExcelBundle\Twig\Node
13
 */
14
class XlsSheetNode extends XlsNode
15
{
16
    /**
17
     * @param Twig_Node_Expression $index
18
     * @param Twig_Node_Expression $properties
19
     * @param Twig_Node $body
20
     * @param int $line
21
     * @param string $tag
22
     */
23
    public function __construct(Twig_Node_Expression $index, Twig_Node_Expression $properties, Twig_Node $body, $line = 0, $tag = 'xlssheet')
24
    {
25
        parent::__construct(['index' => $index, 'properties' => $properties, 'body' => $body], [], $line, $tag);
26
    }
27
28
    /**
29
     * @param Twig_Compiler $compiler
30
     */
31
    public function compile(Twig_Compiler $compiler)
32
    {
33
        $compiler->addDebugInfo($this)
34
            ->write('$sheetIndex = ')
35
            ->subcompile($this->getNode('index'))
36
            ->raw(';' . PHP_EOL)
37
            ->write('$sheetProperties = ')
38
            ->subcompile($this->getNode('properties'))
39
            ->raw(';' . PHP_EOL)
40
            ->write('$context[\'phpExcel\']->startSheet($sheetIndex, $sheetProperties);' . PHP_EOL)
41
            ->write('unset($sheetIndex, $sheetProperties);' . PHP_EOL);
42
43
        if ($this->hasNode('body')) {
44
            $compiler->subcompile($this->getNode('body'));
45
        }
46
47
        $compiler->addDebugInfo($this)->write('$context[\'phpExcel\']->endSheet();' . PHP_EOL);
48
    }
49
50
    /**
51
     * @return string[]
52
     */
53
    public function getAllowedParents()
54
    {
55
        return [
56
            'MewesK\TwigExcelBundle\Twig\Node\XlsDocumentNode'
57
        ];
58
    }
59
60
    /**
61
     * @return bool
62
     */
63
    public function canContainText()
64
    {
65
        return false;
66
    }
67
}
68