Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
18 / 18
100.00% covered (success)
100.00%
5 / 5
CRAP
100.00% covered (success)
100.00%
1 / 1
Legacy
100.00% covered (success)
100.00%
18 / 18
100.00% covered (success)
100.00%
5 / 5
6
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getFunctions
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
1
 getFilters
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 getPage
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 renderShifts
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace Engelsystem\Renderer\Twig\Extensions;
6
7use Engelsystem\Helpers\ShiftsRenderer;
8use Engelsystem\Http\Request;
9use Illuminate\Database\Eloquent\Collection;
10use Twig\Extension\AbstractExtension as TwigExtension;
11use Twig\TwigFilter;
12use Twig\TwigFunction;
13
14class Legacy extends TwigExtension
15{
16    public function __construct(protected Request $request)
17    {
18    }
19
20    /**
21     * @return TwigFunction[]
22     */
23    public function getFunctions(): array
24    {
25        $isSafeHtml = ['is_safe' => ['html']];
26        return [
27            new TwigFunction('menu', 'make_navigation', $isSafeHtml),
28            new TwigFunction('menuUserShiftState', 'User_shift_state_render', $isSafeHtml),
29            new TwigFunction('menuUserHints', 'header_render_hints', $isSafeHtml),
30            new TwigFunction('menuLanguages', 'make_language_select', $isSafeHtml),
31            new TwigFunction('renderShifts', [$this, 'renderShifts'], $isSafeHtml),
32            new TwigFunction('page', [$this, 'getPage']),
33        ];
34    }
35
36    /**
37     * @return TwigFilter[]
38     */
39    public function getFilters(): array
40    {
41        return [
42            new TwigFilter('dateWithEventDay', 'dateWithEventDay'),
43        ];
44    }
45
46    public function getPage(): string
47    {
48        if ($this->request->has('p')) {
49            return $this->request->get('p');
50        }
51
52        return $this->request->path();
53    }
54
55    public function renderShifts(array | Collection $shifts): string
56    {
57        /** @var ShiftsRenderer $renderer */
58        $renderer = app()->make(ShiftsRenderer::class);
59        return $renderer->render($shifts);
60    }
61}