From 9233e394b840d75a52bce1283d123ac5661a10d2 Mon Sep 17 00:00:00 2001
From: Henning <leutz@pcsg.de>
Date: Sat, 22 Feb 2025 11:56:10 +0100
Subject: [PATCH] fix(phpstan): optimize attribute checks and method calls in
 erp classes

In this commit, several changes have been made to streamline the Manufacturer and Process classes
within the ERP module:

- Replaced the non-empty check for 'firstname' and 'lastname' attributes in the User class with an
`empty()` function, resulting in cleaner code without changing the functionality.
- Replaced the argument in `User->activate()` from `false` to `''` for consistency.
- Removed unnecessary annotations and some unused `protected` properties from the Process class.
- Altered the procedure to retrieve `salesOrder` from the Entity in the Process class. Now, the
method first tries to retrieve it via `getPaymentDataEntry()`, and if unavailable, it attempts to
fetch it using `getCustomDataEntry()`. This ensures a more robust and reliable retrieval of the
'salesOrder' property.
- Added `@phpstan-ignore-next-line` in the Processes class to prevent phpstan from throwing
unwarranted warnings regarding the following code line in specific scenarios.

Related: quiqqer/erp#103
---
 src/QUI/ERP/Manufacturers.php |  6 +++---
 src/QUI/ERP/Process.php       | 17 +++++------------
 src/QUI/ERP/Processes.php     |  2 ++
 3 files changed, 10 insertions(+), 15 deletions(-)

diff --git a/src/QUI/ERP/Manufacturers.php b/src/QUI/ERP/Manufacturers.php
index 33073a2..9b64886 100644
--- a/src/QUI/ERP/Manufacturers.php
+++ b/src/QUI/ERP/Manufacturers.php
@@ -159,11 +159,11 @@ public static function createManufacturer(
 
             $Address->save();
 
-            if (!$User->getAttribute('firstname') || $User->getAttribute('firstname') === '') {
+            if (empty($User->getAttribute('firstname'))) {
                 $User->setAttribute('firstname', $address['firstname']);
             }
 
-            if (!$User->getAttribute('lastname') || $User->getAttribute('lastname') === '') {
+            if (empty($User->getAttribute('lastname'))) {
                 $User->setAttribute('lastname', $address['lastname']);
             }
         }
@@ -183,7 +183,7 @@ public static function createManufacturer(
 
         // Set random password and activate
         $User->setPassword(QUI\Security\Password::generateRandom(), $SystemUser);
-        $User->activate(false, $SystemUser);
+        $User->activate('', $SystemUser);
 
         return $User;
     }
diff --git a/src/QUI/ERP/Process.php b/src/QUI/ERP/Process.php
index cddd76a..dcf28e6 100644
--- a/src/QUI/ERP/Process.php
+++ b/src/QUI/ERP/Process.php
@@ -31,19 +31,8 @@ class Process
      */
     const PROCESS_ACTIVE_DATE = '2024-08-01 00:00:00';
 
-    /**
-     * @var string
-     */
     protected string $processId;
-
-    /**
-     * @var null|array
-     */
     protected ?array $transactions = null;
-
-    /**
-     * @var null|QUI\ERP\Comments
-     */
     protected ?Comments $History = null;
 
     /**
@@ -166,7 +155,11 @@ class_exists('QUI\ERP\Accounting\Invoice\Invoice')
                     $groups[$uuid][] = $Entity;
 
                     if (class_exists('QUI\ERP\SalesOrders\Handler')) {
-                        $salesOrder = $Entity->getPaymentData('salesOrder');
+                        $salesOrder = $Entity->getPaymentDataEntry('salesOrder');
+
+                        if (empty($salesOrder)) {
+                            $salesOrder = $Entity->getCustomDataEntry('salesOrder');
+                        }
 
                         if ($salesOrder) {
                             try {
diff --git a/src/QUI/ERP/Processes.php b/src/QUI/ERP/Processes.php
index ecb9a86..a7c66bb 100644
--- a/src/QUI/ERP/Processes.php
+++ b/src/QUI/ERP/Processes.php
@@ -43,6 +43,7 @@ public function getEntity($entityHash, $entityPlugin = false): ErpEntityInterfac
         if ($entityPlugin === false || $entityPlugin === 'quiqqer/booking') {
             try {
                 // @todo quiqqer/booking
+                // @phpstan-ignore-next-line
             } catch (\Exception) {
             }
         }
@@ -70,6 +71,7 @@ public function getEntity($entityHash, $entityPlugin = false): ErpEntityInterfac
         if ($entityPlugin === false || $entityPlugin === 'quiqqer/delivery-notes') {
             try {
                 // @todo quiqqer/delivery-notes
+                // @phpstan-ignore-next-line
             } catch (\Exception) {
             }
         }
-- 
GitLab