From e0d42d286240d826f7fe28aa213f82cd8a1575e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Fri, 23 Feb 2024 19:09:28 -0300 Subject: [PATCH] Remove trigger_error from Template class MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This will remove the error: > Error while working with template cache: Unable to create the cache directory This does not fix the cache issue, but removes the warning. The current behavior is to disable the cache when there's an issue with it. However this has bad performance. The issue is that sometimes Twig generates a different cache key than the warmed up one and tries to write a new cache, but that's not the desired behavior. Signed-off-by: MaurĂ­cio Meneghini Fauth --- phpstan-baseline.neon | 5 ----- src/Template.php | 24 ++++-------------------- 2 files changed, 4 insertions(+), 25 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 90866cd703..e8e48b5bbf 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -14425,11 +14425,6 @@ parameters: count: 1 path: src/Table/Table.php - - - message: "#^Dead catch \\- RuntimeException is never thrown in the try block\\.$#" - count: 1 - path: src/Template.php - - message: "#^Call to function in_array\\(\\) requires parameter \\#3 to be set\\.$#" count: 1 diff --git a/src/Template.php b/src/Template.php index f32006a0ad..f8bce6c28d 100644 --- a/src/Template.php +++ b/src/Template.php @@ -26,12 +26,6 @@ use Twig\Loader\FilesystemLoader; use Twig\RuntimeLoader\ContainerRuntimeLoader; use Twig\TemplateWrapper; -use function __; -use function sprintf; -use function trigger_error; - -use const E_USER_WARNING; - /** * Handle front end templating */ @@ -106,23 +100,13 @@ class Template } try { - $template = static::$twig->load($templateName . '.twig'); - } catch (RuntimeException $e) { + return static::$twig->load($templateName . '.twig'); + } catch (RuntimeException) { // @phpstan-ignore-line thrown by Twig\Cache\FilesystemCache /* Retry with disabled cache */ static::$twig->setCache(false); - $template = static::$twig->load($templateName . '.twig'); - // The trigger error is intentionally after second load - // to avoid triggering error when disabling cache does not solve it. - trigger_error( - sprintf( - __('Error while working with template cache: %s'), - $e->getMessage(), - ), - E_USER_WARNING, - ); - } - return $template; + return static::$twig->load($templateName . '.twig'); + } } /**