ListExtension   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 46
ccs 12
cts 12
cp 1
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A listView() 0 7 1
A __construct() 0 3 1
A getFunctions() 0 7 1
1
<?php
2
3
namespace Povs\ListerTwigBundle\Twig\Extension;
4
5
use Povs\ListerTwigBundle\Service\ListRenderer;
6
use Closure;
7
use Povs\ListerBundle\View\ViewInterface;
8
use Twig\Extension\AbstractExtension;
9
use Twig\TwigFunction;
10
11
/**
12
 * @author Povilas Margaiatis <[email protected]>
13
 */
14
class ListExtension extends AbstractExtension
15
{
16
    /**
17
     * @var ListRenderer
18
     */
19
    private $renderer;
20
21
    /**
22
     * ListExtension constructor.
23
     *
24
     * @param ListRenderer $renderer
25
     */
26 2
    public function __construct(ListRenderer $renderer)
27
    {
28 2
        $this->renderer = $renderer;
29
    }
30
31
    /**
32
     * @inheritdoc
33
     */
34 1
    public function getFunctions(): array
35
    {
36 1
        return [
37 1
            new TwigFunction(
38 1
                'list_view',
39 1
                Closure::fromCallable([$this, 'listView']),
40 1
                ['is_safe' => ['html'], 'needs_context' => true]
41 1
            ),
42 1
        ];
43
    }
44
45
    /**
46
     * @param array         $context
47
     * @param ViewInterface $view
48
     * @param string        $blockName
49
     * @param bool          $rewritable
50
     *
51
     * @return string
52
     */
53 1
    public function listView(
54
        array $context,
55
        ViewInterface $view,
56
        string $blockName = 'list_parent',
57
        bool $rewritable = true
58
    ): string {
59 1
        return $this->renderer->render($view, $blockName, $context, $rewritable);
60
    }
61
}
62