Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
10 / 10 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
| AppExtension | |
100.00% |
10 / 10 |
|
100.00% |
5 / 5 |
6 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getFunctions | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
| hasImage | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| previewImage | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
| waypointCount | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace App\Twig; |
| 6 | |
| 7 | use Override; |
| 8 | use App\Entity\Maxfield; |
| 9 | use App\Entity\Waypoint; |
| 10 | use App\Service\MaxFieldHelper; |
| 11 | use App\Service\WayPointHelper; |
| 12 | use Twig\Extension\AbstractExtension; |
| 13 | use Twig\TwigFunction; |
| 14 | |
| 15 | class 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 | } |