From a1e943ad731ed5080e7014e125e68393f2d64577 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Malte=20H=C3=BCbner?= Date: Mon, 13 Jul 2026 16:32:39 +0200 Subject: [PATCH] fix: remove dev-only DomCrawler from the production TemplateController path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit TemplateController::staticAction (routes /privacy, /impress, /grenzwerte) extracted the page title by rendering the template a second time and parsing its

with Symfony\Component\DomCrawler\Crawler + ->filter() (css-selector). Both symfony/dom-crawler and symfony/css-selector are only require-dev dependencies (pulled via symfony/browser-kit), so a production build with `composer install --no-dev` fatals with "Class Symfony\Component\DomCrawler\Crawler not found" on those routes. Replace the H2 parsing with an explicit `title` route default (Datenschutzerklärung / Impressum / Übersicht über Schadstoffe und Grenzwerte), matching the previous H2 text. This also removes: - the double full render of every static template per request, - the EntrypointLookup reset workaround (and the now-unused EntrypointLookupCollectionInterface constructor dependency), - the always-true ternary (`$h2 ? $h2->text() : null`) and its phpstan-baseline entry. dom-crawler/css-selector stay dev-only (still used by browser-kit in tests); no production code references them anymore. Co-Authored-By: Claude Opus 4.8 (1M context) --- config/routing/1_static.yaml | 3 +++ phpstan-baseline.neon | 5 ----- src/Controller/TemplateController.php | 30 +-------------------------- 3 files changed, 4 insertions(+), 34 deletions(-) diff --git a/config/routing/1_static.yaml b/config/routing/1_static.yaml index 7ef1703d..6859e90f 100644 --- a/config/routing/1_static.yaml +++ b/config/routing/1_static.yaml @@ -3,18 +3,21 @@ privacy: defaults: _controller: App\Controller\TemplateController::staticAction templateName: privacy + title: 'Datenschutzerklärung' impress: path: /impress defaults: _controller: App\Controller\TemplateController::staticAction templateName: impress + title: 'Impressum' limits: path: /grenzwerte defaults: _controller: App\Controller\TemplateController::staticAction templateName: limits + title: 'Übersicht über Schadstoffe und Grenzwerte' pollutant_pm10: path: /schadstoffe/feinstaub diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index eea77dac..903901bf 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -190,11 +190,6 @@ parameters: count: 1 path: src/Controller/TemplateController.php - - - message: "#^Ternary operator condition is always true\\.$#" - count: 1 - path: src/Controller/TemplateController.php - - message: "#^Call to an undefined method Doctrine\\\\Persistence\\\\ObjectRepository\\\\:\\:findActiveStations\\(\\)\\.$#" count: 1 diff --git a/src/Controller/TemplateController.php b/src/Controller/TemplateController.php index a8a4f3c4..b34b7f3b 100644 --- a/src/Controller/TemplateController.php +++ b/src/Controller/TemplateController.php @@ -4,23 +4,12 @@ use App\Air\SeoPage\SeoPage; use App\Entity\City; -use Doctrine\Persistence\ManagerRegistry; -use Symfony\Component\DomCrawler\Crawler; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\RouterInterface; -use Symfony\WebpackEncoreBundle\Asset\EntrypointLookupCollectionInterface; use WhiteOctober\BreadcrumbsBundle\Model\Breadcrumbs; class TemplateController extends AbstractController { - public function __construct( - protected EntrypointLookupCollectionInterface $entrypointLookupCollection, - ManagerRegistry $managerRegistry - ) - { - parent::__construct($managerRegistry); - } - public function cityListAction(): Response { return $this->render( @@ -30,10 +19,8 @@ public function cityListAction(): Response ); } - public function staticAction(string $templateName, Breadcrumbs $breadcrumbs, RouterInterface $router, SeoPage $seoPage): Response + public function staticAction(string $templateName, string $title, Breadcrumbs $breadcrumbs, RouterInterface $router, SeoPage $seoPage): Response { - $title = $this->readH2Tag($templateName); - $templateFilename = sprintf('Static/%s.html.twig', $templateName); $seoPage->setTitle($title); @@ -44,19 +31,4 @@ public function staticAction(string $templateName, Breadcrumbs $breadcrumbs, Rou return $this->render($templateFilename); } - - protected function readH2Tag(string $templateName): ?string - { - $templateFilename = sprintf('Static/%s.html.twig', $templateName); - - $templateContent = $this->renderView($templateFilename); - - $crawler = new Crawler($templateContent); - $h2 = $crawler->filter('h2')->first(); - - /** @see https://github.com/symfony/webpack-encore-bundle/issues/73#issuecomment-514649426 */ - $this->entrypointLookupCollection->getEntrypointLookup()->reset(); - - return $h2 ? $h2->text() : null; - } }