|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Erelke\TwigSpreadsheetBundle\Twig\Node; |
|
4
|
|
|
|
|
5
|
|
|
use Erelke\TwigSpreadsheetBundle\Wrapper\HeaderFooterWrapper; |
|
6
|
|
|
use InvalidArgumentException; |
|
7
|
|
|
use Twig\Compiler as Twig_Compiler; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Class HeaderFooterNode. |
|
11
|
|
|
*/ |
|
12
|
|
|
class HeaderFooterNode extends BaseNode |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @var string |
|
16
|
|
|
*/ |
|
17
|
|
|
private $baseType; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* HeaderFooterNode constructor. |
|
21
|
|
|
* |
|
22
|
|
|
* @param array $nodes |
|
23
|
|
|
* @param array $attributes |
|
24
|
|
|
* @param int $lineNo |
|
25
|
|
|
* @param string|null $tag |
|
26
|
|
|
* @param string $baseType |
|
27
|
|
|
* |
|
28
|
|
|
* @throws InvalidArgumentException |
|
29
|
|
|
*/ |
|
30
|
|
|
public function __construct(array $nodes = [], array $attributes = [], int $lineNo = 0, string $tag = null, string $baseType = HeaderFooterWrapper::BASETYPE_HEADER) |
|
31
|
|
|
{ |
|
32
|
|
|
parent::__construct($nodes, $attributes, $lineNo, $tag); |
|
33
|
|
|
|
|
34
|
|
|
$this->baseType = HeaderFooterWrapper::validateBaseType(strtolower($baseType)); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @param Twig_Compiler $compiler |
|
39
|
|
|
*/ |
|
40
|
|
View Code Duplication |
public function compile(Twig_Compiler $compiler) |
|
|
|
|
|
|
41
|
|
|
{ |
|
42
|
|
|
$compiler->addDebugInfo($this) |
|
43
|
|
|
->write(self::CODE_FIX_CONTEXT) |
|
44
|
|
|
->write(self::CODE_INSTANCE.'->startHeaderFooter(') |
|
45
|
|
|
->repr($this->baseType)->raw(', ') |
|
46
|
|
|
->subcompile($this->getNode('type'))->raw(', ') |
|
47
|
|
|
->subcompile($this->getNode('properties')) |
|
48
|
|
|
->raw(');'.PHP_EOL) |
|
49
|
|
|
->subcompile($this->getNode('body')) |
|
50
|
|
|
->addDebugInfo($this) |
|
51
|
|
|
->write(self::CODE_INSTANCE.'->endHeaderFooter();'.PHP_EOL); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* {@inheritdoc} |
|
56
|
|
|
*/ |
|
57
|
|
|
public function getAllowedParents(): array |
|
58
|
|
|
{ |
|
59
|
|
|
return [ |
|
60
|
|
|
SheetNode::class, |
|
61
|
|
|
]; |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.