Passed
Pull Request — master (#116)
by Arnaud
03:38
created

FieldExtension::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace LAG\AdminBundle\Bridge\Twig\Extension;
4
5
use LAG\AdminBundle\Field\FieldInterface;
6
use LAG\AdminBundle\Field\Render\FieldRendererInterface;
7
use LAG\AdminBundle\View\ViewInterface;
8
use Twig\Extension\AbstractExtension;
9
use Twig_SimpleFunction;
10
11
class FieldExtension extends AbstractExtension
12
{
13
    /**
14
     * @var FieldRendererInterface
15
     */
16
    private $renderer;
17
18
    public function __construct(FieldRendererInterface $renderer)
19
    {
20
        $this->renderer = $renderer;
21
    }
22
23
    public function getFunctions(): array
24
    {
25
        return [
26
            new Twig_SimpleFunction('admin_field', [$this, 'renderField']),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFunction has been deprecated: since Twig 2.7, use "Twig\TwigFunction" instead ( Ignorable by Annotation )

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

26
            /** @scrutinizer ignore-deprecated */ new Twig_SimpleFunction('admin_field', [$this, 'renderField']),
Loading history...
27
            new Twig_SimpleFunction('admin_field_header', [$this, 'renderFieldHeader']),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFunction has been deprecated: since Twig 2.7, use "Twig\TwigFunction" instead ( Ignorable by Annotation )

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

27
            /** @scrutinizer ignore-deprecated */ new Twig_SimpleFunction('admin_field_header', [$this, 'renderFieldHeader']),
Loading history...
28
        ];
29
    }
30
31
    public function renderField(FieldInterface $field, $entity): string
32
    {
33
        return $this->renderer->render($field, $entity);
34
    }
35
36
    /**
37
     * Return the field header label.
38
     *
39
     * @param ViewInterface  $admin
40
     * @param FieldInterface $field
41
     *
42
     * @return string
43
     */
44
    public function renderFieldHeader(ViewInterface $admin, FieldInterface $field)
45
    {
46
        return $this->renderer->renderHeader($admin, $field);
47
    }
48
}
49