XlsCellNode::compile()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 14
nc 1
nop 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 XlsCellNode
11
 *
12
 * @package MewesK\TwigExcelBundle\Twig\Node
13
 */
14
class XlsCellNode extends Twig_Node implements SyntaxAwareNodeInterface
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 = 'xlscell')
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('$context[\'phpExcel\']->setCellIndex(')
35
            ->subcompile($this->getNode('index'))
36
            ->raw(');' . PHP_EOL)
37
            ->write("ob_start();\n")
38
            ->subcompile($this->getNode('body'))
39
            ->write('$cellValue = trim(ob_get_clean());' . PHP_EOL)
40
            ->write('$cellProperties = ')
41
            ->subcompile($this->getNode('properties'))
42
            ->raw(';' . PHP_EOL)
43
            ->write('$context[\'phpExcel\']->startCell($cellValue, $cellProperties);' . PHP_EOL)
44
            ->write('unset($cellIndex, $cellValue, $cellProperties);' . PHP_EOL)
45
            ->write('$context[\'phpExcel\']->endCell();' . PHP_EOL);
46
    }
47
48
    /**
49
     * @return string[]
50
     */
51
    public function getAllowedParents()
52
    {
53
        return [
54
            'MewesK\TwigExcelBundle\Twig\Node\XlsRowNode'
55
        ];
56
    }
57
58
    /**
59
     * @return bool
60
     */
61
    public function canContainText()
62
    {
63
        return true;
64
    }
65
}
66