From cf368687fc492fe53fef461cb9a8401de7a2de13 Mon Sep 17 00:00:00 2001
From: Henning <leutz@pcsg.de>
Date: Mon, 24 Mar 2025 15:26:46 +0100
Subject: [PATCH] fix(phpstan): update phive and refactor ERP Currency Handler

- Updated the version of phive to ^2.0.4 in the phars.xml file
- Refactored the ERP Currency Handler in the following ways:
  - Rearranged the argument order and types in createCurrency function
  - Removed unused languageData in createCurrency function
  - Updated createCurrency, deleteCurrency, updateCurrency to return void
  - Updated getDefaultCurrency to return Currency|null
  - Fixed getCurrency to handle `isset($currency['code'])`
  - Updated getCurrencies to handle `null | QUI\\Locale`
  - Standardized exception catch statements to `QUI\\Exception` without variable
  - Minor cleanups and formatting for increased readability
---
 .phive/phars.xml                 |  2 +-
 src/QUI/ERP/Currency/Handler.php | 41 ++++++++++++++++----------------
 2 files changed, 21 insertions(+), 22 deletions(-)

diff --git a/.phive/phars.xml b/.phive/phars.xml
index 5bfa092..4ff573d 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="^2.0.4" installed="2.0.4" 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/Currency/Handler.php b/src/QUI/ERP/Currency/Handler.php
index 719c614..1b71cc2 100644
--- a/src/QUI/ERP/Currency/Handler.php
+++ b/src/QUI/ERP/Currency/Handler.php
@@ -57,19 +57,22 @@ public static function table(): string
      * Create a new currency
      *
      * @param string $currency - currency code
-     * @param integer|float $rate - currency exchange rate, default = 1
+     * @param float|integer $rate - currency exchange rate, default = 1
      * @param string $type (optional) - Currency type
      * @throws QUI\Exception
      */
-    public static function createCurrency(string $currency, $rate = 1, string $type = self::CURRENCY_TYPE_DEFAULT)
-    {
+    public static function createCurrency(
+        string $currency,
+        float | int | string $rate = 1,
+        string $type = self::CURRENCY_TYPE_DEFAULT
+    ): void {
         QUI\Permissions\Permission::checkPermission('currency.create');
 
         $Currency = null;
 
         try {
             $Currency = self::getCurrency($currency);
-        } catch (QUI\Exception $Exception) {
+        } catch (QUI\Exception) {
         }
 
         if (!is_null($Currency)) {
@@ -94,10 +97,6 @@ public static function createCurrency(string $currency, $rate = 1, string $type
         ]);
 
         // create translations
-        $languageData = [
-            'datatype' => 'js,php'
-        ];
-
         $localeGroup = 'quiqqer/currency';
         $localeText = 'currency.' . $currency . '.text';
         $localeSign = 'currency.' . $currency . '.sign';
@@ -123,7 +122,7 @@ public static function createCurrency(string $currency, $rate = 1, string $type
                 'currency.' . $currency . '.text',
                 'quiqqer/currency'
             );
-        } catch (QUI\Exception $e) {
+        } catch (QUI\Exception) {
         }
 
         if (!empty($textData)) {
@@ -142,7 +141,7 @@ public static function createCurrency(string $currency, $rate = 1, string $type
                 'currency.' . $currency . '.sign',
                 'quiqqer/currency'
             );
-        } catch (QUI\Exception $e) {
+        } catch (QUI\Exception) {
         }
 
 
@@ -164,7 +163,7 @@ public static function createCurrency(string $currency, $rate = 1, string $type
      * @param string $currency - currency code
      * @throws QUI\Exception
      */
-    public static function deleteCurrency(string $currency)
+    public static function deleteCurrency(string $currency): void
     {
         QUI\Permissions\Permission::checkPermission('currency.delete');
 
@@ -188,7 +187,7 @@ public static function deleteCurrency(string $currency)
     /**
      * Return the default currency
      *
-     * @return Currency
+     * @return Currency|null
      * @throws QUI\Exception
      */
     public static function getDefaultCurrency(): ?Currency
@@ -200,7 +199,7 @@ public static function getDefaultCurrency(): ?Currency
                 self::$Default = self::getCurrency(
                     $Config->getValue('currency', 'defaultCurrency')
                 );
-            } catch (QUI\Exception $Exception) {
+            } catch (QUI\Exception) {
                 QUI\System\Log::addWarning('Default currency is missing');
 
                 try {
@@ -321,7 +320,7 @@ public static function getAllowedCurrencies(): array
         foreach ($allowed as $currency) {
             try {
                 $list[] = self::getCurrency($currency);
-            } catch (QUI\Exception $Exception) {
+            } catch (QUI\Exception) {
             }
         }
 
@@ -378,7 +377,7 @@ public static function getCurrency(Currency | string | array $currency): Currenc
 
         if (is_string($currency)) {
             $code = $currency;
-        } elseif (is_array($currency) && isset($currency['code'])) {
+        } elseif (isset($currency['code'])) {
             $code = $currency['code'];
         }
 
@@ -415,10 +414,10 @@ public static function existCurrency(string $currency): bool
     /**
      * Return all currency entries
      *
-     * @param Locale|boolean $Locale - optional, for translation
+     * @param Locale|null $Locale - optional, for translation
      * @return array
      */
-    public static function getCurrencies($Locale = false): array
+    public static function getCurrencies(null | QUI\Locale $Locale = null): array
     {
         if (!$Locale) {
             $Locale = QUI::getLocale();
@@ -429,12 +428,12 @@ public static function getCurrencies($Locale = false): array
 
         try {
             return QUI\Cache\Manager::get($cacheNameLang);
-        } catch (QUI\Exception $Exception) {
+        } catch (QUI\Exception) {
         }
 
         try {
             $currencies = QUI\Cache\Manager::get($cacheName);
-        } catch (QUI\Exception $Exception) {
+        } catch (QUI\Exception) {
             $currencies = [];
             $data = self::getData();
 
@@ -448,7 +447,7 @@ public static function getCurrencies($Locale = false): array
         foreach ($currencies as $currency) {
             try {
                 $Currency = self::getCurrency($currency);
-            } catch (QUI\Exception $Exception) {
+            } catch (QUI\Exception) {
                 continue;
             }
 
@@ -465,7 +464,7 @@ public static function getCurrencies($Locale = false): array
      * @throws QUI\Database\Exception
      * @throws QUI\Exception
      */
-    public static function updateCurrency($currency, $data)
+    public static function updateCurrency($currency, $data): void
     {
         QUI\Permissions\Permission::checkPermission('currency.edit');
 
-- 
GitLab