Passed
Push — master ( 8ef4d4...d6939e )
by Victor
46s queued 11s
created

OptionalNode   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 34
rs 10
c 0
b 0
f 0
ccs 18
cts 18
cp 1
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A compile() 0 17 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Shoot\Shoot\Twig\Node;
5
6
use Twig_Compiler as Compiler;
7
use Twig_Node as Node;
8
9
final class OptionalNode extends Node
10
{
11
    /**
12
     * @param Node   $body       The body of the suppressed tag.
13
     * @param int    $lineNumber The line number at which the tag occurs in the template.
14
     * @param string $tag        The name of the tag.
15
     */
16 2
    public function __construct(Node $body, int $lineNumber, string $tag)
17
    {
18 2
        parent::__construct(['body' => $body], [], $lineNumber, $tag);
19 2
    }
20
21
    /**
22
     * @param Compiler $compiler
23
     *
24
     * @return void
25
     */
26 2
    public function compile(Compiler $compiler)
27
    {
28
        $compiler
29 2
            ->write("try {\n")
30 2
            ->indent()
31 2
            ->subcompile($this->getNode('body'))
32 2
            ->outdent()
33 2
            ->write("} catch (\\Twig_Error_Runtime \$exception) {\n")
34 2
            ->indent()
35 2
            ->write("if (\$exception->getPrevious() === null) {\n")
36 2
            ->indent()
37 2
            ->write("throw \$exception;\n")
38 2
            ->outdent()
39 2
            ->write("}\n\n")
40 2
            ->write("\$suppressedException = new \\Shoot\\Shoot\\SuppressedException(\$exception->getPrevious());\n")
41 2
            ->outdent()
42 2
            ->write("}\n\n");
43 2
    }
44
}
45