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

XlsCenterNode::getAllowedParents()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 7
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace MewesK\TwigExcelBundle\Twig\Node;
4
5
use Twig_Compiler;
6
use Twig_Node;
7
8
/**
9
 * Class XlsCenterNode
10
 *
11
 * @package MewesK\TwigExcelBundle\Twig\Node
12
 */
13
class XlsCenterNode extends XlsNode
14
{
15
    /**
16
     * @param Twig_Node $body
17
     * @param int $line
18
     * @param string $tag
19
     */
20
    public function __construct(Twig_Node $body, $line = 0, $tag = 'xlscenter')
21
    {
22
        parent::__construct(['body' => $body], [], $line, $tag);
23
    }
24
25
    /**
26
     * @param Twig_Compiler $compiler
27
     */
28
    public function compile(Twig_Compiler $compiler)
29
    {
30
        $compiler->addDebugInfo($this)
31
            ->write('$context[\'phpExcel\']->startAlignment(\'center\');' . PHP_EOL)
32
            ->write("ob_start();\n")
33
            ->subcompile($this->getNode('body'))
34
            ->write('$centerValue = trim(ob_get_clean());' . PHP_EOL)
35
            ->write('$context[\'phpExcel\']->endAlignment($centerValue);' . PHP_EOL)
36
            ->write('unset($centerValue);' . PHP_EOL);
37
    }
38
39
    /**
40
     * @return string[]
41
     */
42
    public function getAllowedParents()
43
    {
44
        return [
45
            'MewesK\TwigExcelBundle\Twig\Node\XlsFooterNode',
46
            'MewesK\TwigExcelBundle\Twig\Node\XlsHeaderNode'
47
        ];
48
    }
49
50
    /**
51
     * @return bool
52
     */
53
    public function canContainText()
54
    {
55
        return true;
56
    }
57
}
58