Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
5 / 5
CRAP
100.00% covered (success)
100.00%
1 / 1
AppExtension
100.00% covered (success)
100.00%
10 / 10
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%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
 hasImage
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 previewImage
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
 waypointCount
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace App\Twig;
6
7use Override;
8use App\Entity\Maxfield;
9use App\Entity\Waypoint;
10use App\Service\MaxFieldHelper;
11use App\Service\WayPointHelper;
12use Twig\Extension\AbstractExtension;
13use Twig\TwigFunction;
14
15class AppExtension extends AbstractExtension
16{
17    public function __construct(
18        private readonly WayPointHelper $wayPointHelper,
19        private readonly MaxFieldHelper $maxFieldHelper,
20    ) {}
21
22    #[Override]
23    public function getFunctions(): array
24    {
25        return [
26            new TwigFunction('hasImage', $this->hasImage(...)),
27            new TwigFunction('previewImage', $this->previewImage(...)),
28            new TwigFunction('waypointCount', $this->waypointCount(...)),
29        ];
30    }
31
32    public function hasImage(Waypoint $waypoint): bool
33    {
34        return (bool)$this->wayPointHelper->findImage($waypoint->getGuid());
35    }
36
37    public function previewImage(Maxfield $maxfield): string
38    {
39        return $this->maxFieldHelper->getPreviewImage($maxfield->getPath() ?? '')
40            ?: 'images/no-preview.jpg';
41    }
42
43    public function waypointCount(Maxfield $maxfield): int
44    {
45        return $this->maxFieldHelper->getWaypointCount($maxfield->getPath() ?? '');
46    }
47}