From 4e8732aeb3ea186c884c35caa159c52894b916f0 Mon Sep 17 00:00:00 2001
From: Henning <leutz@pcsg.de>
Date: Thu, 20 Mar 2025 10:51:21 +0100
Subject: [PATCH] fix: usage of user interface in eventhandler

- Updated PHPStan version from 1.11.8 to 1.12.13 in phars.xml
- Changed User class interfaces in the event handlers from QUI\Users\User to
QUI\Interfaces\Users\User
- Also, added additional checks and updated function parameters for type consistency.
---
 .phive/phars.xml                      |  2 +-
 src/QUI/ERP/Customer/EventHandler.php | 23 ++++++++++++++---------
 2 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/.phive/phars.xml b/.phive/phars.xml
index 5bfa092..cccdab5 100644
--- a/.phive/phars.xml
+++ b/.phive/phars.xml
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <phive xmlns="https://phar.io/phive">
-  <phar name="phpstan" version="1.11.8" installed="1.11.8" location="./tools/phpstan" copy="false"/>
+  <phar name="phpstan" version="1.*" installed="1.12.13" location="./tools/phpstan" copy="false"/>
   <phar name="phpunit" version="^10.5.20" installed="10.5.20" location="./tools/phpunit" copy="false"/>
   <phar name="phpcs" version="^3.10.1" installed="3.10.1" location="./tools/phpcs" copy="false"/>
   <phar name="phpcbf" version="^3.10.1" installed="3.10.1" location="./tools/phpcbf" copy="false"/>
diff --git a/src/QUI/ERP/Customer/EventHandler.php b/src/QUI/ERP/Customer/EventHandler.php
index b150c1a..6a1f095 100644
--- a/src/QUI/ERP/Customer/EventHandler.php
+++ b/src/QUI/ERP/Customer/EventHandler.php
@@ -196,7 +196,7 @@ protected static function readAttributesFromUserXML(string $file): array
         return $attributes;
     }
 
-    public static function onUserSaveBegin(QUI\Users\User $User): void
+    public static function onUserSaveBegin(QUI\Interfaces\Users\User $User): void
     {
         if (!QUI::getUsers()->isUser($User)) {
             return;
@@ -234,10 +234,14 @@ public static function onUserSaveBegin(QUI\Users\User $User): void
     }
 
     /**
-     * @param QUI\Users\User $User
+     * @param QUI\Interfaces\Users\User $User
      */
-    public static function onUserSaveEnd(QUI\Users\User $User): void
+    public static function onUserSaveEnd(QUI\Interfaces\Users\User $User): void
     {
+        if (!QUI::getUsers()->isUser($User)) {
+            return;
+        }
+
         $attributes = $User->getAttributes();
         $data = [];
 
@@ -297,15 +301,15 @@ public static function onUserSaveEnd(QUI\Users\User $User): void
     }
 
     /**
-     * @param QUI\Users\User $User
+     * @param QUI\Interfaces\Users\User $User
      * @param bool|string $code
      * @param null|QUI\Interfaces\Users\User $PermissionUser
      *
      * @throws QUI\Users\Exception|QUI\Exception
      */
     public static function onUserActivateBegin(
-        QUI\Users\User $User,
-        bool|string $code,
+        QUI\Interfaces\Users\User $User,
+        bool | string $code,
         ?QUI\Interfaces\Users\User $PermissionUser
     ): void {
         $Group = Utils::getInstance()->getCustomerGroup();
@@ -342,6 +346,7 @@ public static function onUserActivateBegin(
      * - set the user to the customer group
      *
      * @param QUI\ERP\Order\Controls\OrderProcess\CustomerData $Step
+     * @throws QUI\Exception
      */
     public static function onQuiqqerOrderCustomerDataSaveEnd(
         QUI\ERP\Order\Controls\OrderProcess\CustomerData $Step
@@ -378,15 +383,15 @@ public static function onQuiqqerOrderCustomerDataSaveEnd(
      * Handle the frontend user data event
      *
      * @param Collector $Collector - The collector object
-     * @param QUI\Users\User $User - The user object
+     * @param QUI\Interfaces\Users\User $User - The user object
      * @param mixed $Address - The address data
      * @return void
      * @throws Exception
      */
     public static function onFrontendUserDataMiddle(
         Collector $Collector,
-        QUI\Users\User $User,
-        $Address
+        QUI\Interfaces\Users\User $User,
+        mixed $Address
     ): void {
         $Engine = QUI::getTemplateManager()->getEngine();
         $canEdit = QUI\Permissions\Permission::hasPermission('quiqqer.customer.FrontendUsers.contactPerson.edit');
-- 
GitLab