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

FieldExtension   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 36
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getFunctions() 0 5 1
A __construct() 0 3 1
A renderField() 0 3 1
A renderFieldHeader() 0 3 1
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