GridExtension   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 24
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A renderGrid() 0 3 1
A renderCell() 0 3 1
A getFunctions() 0 5 1
A __construct() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LAG\AdminBundle\Twig\Extension;
6
7
use LAG\AdminBundle\Grid\Cell;
8
use LAG\AdminBundle\Grid\Grid;
9
use LAG\AdminBundle\Grid\View\CellRendererInterface;
10
use LAG\AdminBundle\Grid\View\GridRendererInterface;
11
use LAG\AdminBundle\Metadata\Operation;
12
use Twig\Extension\AbstractExtension;
13
use Twig\TwigFunction;
14
15
class GridExtension extends AbstractExtension
16
{
17
    public function __construct(
18
        private GridRendererInterface $gridRenderer,
19
        private CellRendererInterface $cellRenderer,
20
    ) {
21
    }
22
23
    public function getFunctions(): array
24
    {
25
        return [
26
            new TwigFunction('lag_admin_grid', [$this, 'renderGrid'], ['is_safe' => ['html']]),
27
            new TwigFunction('lag_admin_grid_cell', [$this, 'renderCell'], ['is_safe' => ['html']]),
28
        ];
29
    }
30
31
    public function renderGrid(Grid $grid, Operation $operation): string
32
    {
33
        return $this->gridRenderer->render($grid, $operation);
34
    }
35
36
    public function renderCell(Cell $cell): string
37
    {
38
        return $this->cellRenderer->render($cell);
39
    }
40
}
41