From 4fbeb22983d5ed4905695425e279189dbcf4f744 Mon Sep 17 00:00:00 2001
From: Henning <leutz@pcsg.de>
Date: Mon, 10 Feb 2025 14:33:55 +0100
Subject: [PATCH] fix(phpstan): added exception handling for missing html2pdf
 module in OutputTemplate

In OutputTemplate.php, a check has been added to ensure the existence of the
'QUI\\HtmlToPdf\\Document' class before using it. If the class does not exist, an error message is
logged, and an exception is thrown indicating that the html2pdf module is missing. This fix is
aimed at avoiding potential errors that may occur due to the absence of the required module.
---
 src/QUI/ERP/Output/OutputTemplate.php | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/QUI/ERP/Output/OutputTemplate.php b/src/QUI/ERP/Output/OutputTemplate.php
index 8e7fc31..2d9e5d0 100644
--- a/src/QUI/ERP/Output/OutputTemplate.php
+++ b/src/QUI/ERP/Output/OutputTemplate.php
@@ -168,6 +168,14 @@ public function getHTML(bool $preview = false): string
      */
     public function getPDFDocument(): QUI\HtmlToPdf\Document
     {
+        if (!class_exists('QUI\HtmlToPdf\Document')) {
+            QUI\System\Log::addError('Missing html2pdf module. Please install the html2pdf module.');
+
+            throw new QUI\Exception(
+                'An error has occurred. Please try again or contact support if the issue persists.'
+            );
+        }
+
         $Locale = $this->OutputProvider::getLocale($this->entityId);
         QUI::getLocale()->setTemporaryCurrent($Locale->getCurrent());
 
-- 
GitLab