From 233c5e85500118d0bb2c60a5fcd95e65ddaea86a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Sun, 15 Feb 2026 00:49:12 +0100 Subject: [PATCH] Fixed phpunit and phpstan issues --- .../LabelSystem/SandboxedTwigFactory.php | 17 ++++++++++++----- src/Twig/UserRepoExtension.php | 5 +++-- templates/parts/lists/_info_card.html.twig | 4 ++-- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/Services/LabelSystem/SandboxedTwigFactory.php b/src/Services/LabelSystem/SandboxedTwigFactory.php index d5e09fa5..b4f1d9f6 100644 --- a/src/Services/LabelSystem/SandboxedTwigFactory.php +++ b/src/Services/LabelSystem/SandboxedTwigFactory.php @@ -70,12 +70,14 @@ use App\Twig\Sandbox\SandboxedLabelExtension; use App\Twig\TwigCoreExtension; use InvalidArgumentException; use Twig\Environment; +use Twig\Extension\AttributeExtension; use Twig\Extension\SandboxExtension; use Twig\Extra\Html\HtmlExtension; use Twig\Extra\Intl\IntlExtension; use Twig\Extra\Markdown\MarkdownExtension; use Twig\Extra\String\StringExtension; use Twig\Loader\ArrayLoader; +use Twig\RuntimeLoader\FactoryRuntimeLoader; use Twig\Sandbox\SecurityPolicyInterface; /** @@ -186,13 +188,18 @@ final class SandboxedTwigFactory $twig->addExtension(new StringExtension()); $twig->addExtension(new HtmlExtension()); - //Add Part-DB specific extension - $twig->addExtension($this->formatExtension); - $twig->addExtension($this->barcodeExtension); - $twig->addExtension($this->entityExtension); - $twig->addExtension($this->twigCoreExtension); $twig->addExtension($this->sandboxedLabelExtension); + //Our other extensions are using attributes, we need a bit more work to load them + $dynamicExtensions = [$this->formatExtension, $this->barcodeExtension, $this->entityExtension, $this->twigCoreExtension]; + $dynamicExtensionsMap = []; + + foreach ($dynamicExtensions as $extension) { + $twig->addExtension(new AttributeExtension($extension::class)); + $dynamicExtensionsMap[$extension::class] = static fn () => $extension; + } + $twig->addRuntimeLoader(new FactoryRuntimeLoader($dynamicExtensionsMap)); + return $twig; } diff --git a/src/Twig/UserRepoExtension.php b/src/Twig/UserRepoExtension.php index 51ac113c..1dcc6706 100644 --- a/src/Twig/UserRepoExtension.php +++ b/src/Twig/UserRepoExtension.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace App\Twig; use App\Entity\Base\AbstractDBElement; +use App\Entity\LogSystem\AbstractLogEntry; use App\Entity\UserSystem\User; use App\Repository\LogEntryRepository; use Doctrine\ORM\EntityManagerInterface; @@ -42,7 +43,7 @@ final readonly class UserRepoExtension #[AsTwigFunction('creating_user')] public function creatingUser(AbstractDBElement $element): ?User { - return $this->entityManager->getRepository(LogEntryRepository::class)->getCreatingUser($element); + return $this->entityManager->getRepository(AbstractLogEntry::class)->getCreatingUser($element); } /** @@ -51,6 +52,6 @@ final readonly class UserRepoExtension #[AsTwigFunction('last_editing_user')] public function lastEditingUser(AbstractDBElement $element): ?User { - return $this->entityManager->getRepository(LogEntryRepository::class)->getLastEditingUser($element); + return $this->entityManager->getRepository(AbstractLogEntry::class)->getLastEditingUser($element); } } diff --git a/templates/parts/lists/_info_card.html.twig b/templates/parts/lists/_info_card.html.twig index 876bd31b..a35e2862 100644 --- a/templates/parts/lists/_info_card.html.twig +++ b/templates/parts/lists/_info_card.html.twig @@ -84,7 +84,7 @@ - {% if entity is instanceof("App\\Entity\\Parts\\Storelocation") %} + {% if entity is instanceof("App\\Entity\\Parts\\StorageLocation") %} {{ dropdown.profile_dropdown('storelocation', entity.id, true, 'btn-secondary w-100 mt-2') }} {% endif %} @@ -136,4 +136,4 @@ {% if filterForm is defined %} {% include "parts/lists/_filter.html.twig" %} {% endif %} - \ No newline at end of file +