Completed
Pull Request — master (#9)
by Eugene
03:48
created

DeferredBlockNode::compile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 22
rs 9.568
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Twig\DeferredExtension;
4
5
use Twig\Compiler;
6
use Twig\Node\BlockNode;
7
8
final class DeferredBlockNode extends BlockNode
9
{
10
    public function compile(Compiler $compiler): void
11
    {
12
        $name = $this->getAttribute('name');
13
14
        $compiler
15
            ->write("public function block_$name(\$context, array \$blocks = [])\n", "{\n")
16
            ->indent()
17
            ->write("\$this->env->getExtension('".DeferredExtension::class."')->defer(\$this, '$name');\n")
18
            ->outdent()
19
            ->write("}\n\n")
20
        ;
21
22
        $compiler
23
            ->addDebugInfo($this)
24
            ->write("public function block_{$name}_deferred(\$context, array \$blocks = [])\n", "{\n")
25
            ->indent()
26
            ->subcompile($this->getNode('body'))
27
            ->write("\$this->env->getExtension('".DeferredExtension::class."')->resolve(\$this, \$context, \$blocks);\n")
28
            ->outdent()
29
            ->write("}\n\n")
30
        ;
31
    }
32
}
33