Passed
Pull Request — master (#3021)
by Jesse
05:24
created

FormFieldNode   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 37
ccs 0
cts 13
cp 0
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A compile() 0 8 1
1
<?php
2
3
namespace Frontend\Core\Engine;
4
5
/**
6
 * Twig node for writing out the compiled version of form field.
7
 */
8
class FormFieldNode extends \Twig_Node
0 ignored issues
show
Deprecated Code introduced by
The class Twig_Node has been deprecated: since Twig 2.7, use "Twig\Node\Node" instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

8
class FormFieldNode extends /** @scrutinizer ignore-deprecated */ \Twig_Node
Loading history...
9
{
10
    /**
11
     * @var string
12
     */
13
    private $form;
14
15
    /**
16
     * @var string
17
     */
18
    private $field;
19
20
    /**
21
     * @param string $form Name of the template var holding the form this field
22
     *                     belongs to.
23
     * @param string $field Name of the field to render.
24
     * @param int $lineNumber Line number in the template source file.
25
     * @param string $tag
26
     */
27
    public function __construct(string $form, string $field, int $lineNumber, string $tag)
28
    {
29
        parent::__construct([], [], $lineNumber, $tag);
30
        $this->form = $form;
31
        $this->field = $field;
32
    }
33
34
    /**
35
     * @param \Twig_Compiler $compiler
36
     */
37
    public function compile(\Twig_Compiler $compiler): void
38
    {
39
        $form = "\$context['form_{$this->form}']";
40
        $parseField = $form . "->getField('{$this->field}')->parse()";
41
42
        $compiler
43
            ->addDebugInfo($this)
44
            ->write("echo $parseField;\n")
45
        ;
46
    }
47
}
48