EspoCRM – Open Source CRM Application
PHP calendarcontactscrmcrm-platformcrm-systemcustomer-portalcustomer-supportcustomizabledocumentsemail-marketingkanbanleadsopen-sourcephpplatformsales-automationsingle-page-applicationsupport
ref
Yuri Kuznetsovf18ed3a53130
diff --git a/application/Espo/Core/Currency/CalculatorUtil.php b/application/Espo/Core/Currency/CalculatorUtil.phpindex 9e1fca6062..1a76a51be6 100644--- a/application/Espo/Core/Currency/CalculatorUtil.php+++ b/application/Espo/Core/Currency/CalculatorUtil.php@@ -35,6 +35,11 @@ class CalculatorUtil{private const SCALE = 14;+ /**+ * @param numeric-string $arg1+ * @param numeric-string $arg2+ * @return numeric-string+ */public static function add(string $arg1, string $arg2): string{if (!function_exists('bcadd')) {@@ -50,6 +55,11 @@ class CalculatorUtil);}+ /**+ * @param numeric-string $arg1+ * @param numeric-string $arg2+ * @return numeric-string+ */public static function subtract(string $arg1, string $arg2): string{if (!function_exists('bcsub')) {@@ -65,6 +75,11 @@ class CalculatorUtil);}+ /**+ * @param numeric-string $arg1+ * @param numeric-string $arg2+ * @return numeric-string+ */public static function multiply(string $arg1, string $arg2): string{if (!function_exists('bcmul')) {@@ -80,6 +95,11 @@ class CalculatorUtil);}+ /**+ * @param numeric-string $arg1+ * @param numeric-string $arg2+ * @return numeric-string+ */public static function divide(string $arg1, string $arg2): string{if (!function_exists('bcdiv')) {@@ -88,20 +108,23 @@ class CalculatorUtil);}- /** @var ?string $result */$result = bcdiv($arg1,$arg2,self::SCALE);- if ($result === null) {+ if ($result === null) { /** @phpstan-ignore-line */throw new DivisionByZeroError();}return $result;}+ /**+ * @param numeric-string $arg+ * @return numeric-string+ */public static function round(string $arg, int $precision = 0): string{if (!function_exists('bcadd')) {@@ -114,6 +137,8 @@ class CalculatorUtil$addition = '-' . $addition;}+ assert(is_numeric($addition));+return bcadd($arg,$addition,@@ -121,6 +146,10 @@ class CalculatorUtil);}+ /**+ * @param numeric-string $arg1+ * @param numeric-string $arg2+ */public static function compare(string $arg1, string $arg2): int{if (!function_exists('bccomp')) {diff --git a/application/Espo/Core/Currency/Converter.php b/application/Espo/Core/Currency/Converter.phpindex 37ee09199b..2dafa9082b 100644--- a/application/Espo/Core/Currency/Converter.php+++ b/application/Espo/Core/Currency/Converter.php@@ -100,6 +100,10 @@ class Converterreturn $this->convert($value, $targetCurrencyCode);}+ /**+ * @param numeric-string $amount+ * @return numeric-string+ */private function convertAmount(string $amount, float $rate, float $targetRate): string{return CalculatorUtil::divide(diff --git a/application/Espo/Core/Field/Currency.php b/application/Espo/Core/Field/Currency.phpindex 7b14ac1c6c..b5d733b10d 100644--- a/application/Espo/Core/Field/Currency.php+++ b/application/Espo/Core/Field/Currency.php@@ -39,11 +39,12 @@ use InvalidArgumentException;*/class Currency{+ /** @var numeric-string */private string $amount;private string $code;/**- * @param string|float $amount An amount.+ * @param numeric-string|float $amount An amount.* @param string $code A currency code.* @throws RuntimeException*/@@ -67,6 +68,8 @@ class Currency/*** Get an amount as string.+ *+ * @return numeric-string*/public function getAmountAsString(): string{@@ -194,7 +197,7 @@ class Currency/*** Create from an amount and code.*- * @param string|float $amount An amount.+ * @param numeric-string|float $amount An amount.* @param string $code A currency code.* @throws RuntimeException*/diff --git a/application/Espo/Core/Formula/Functions/ExtGroup/CurrencyGroup/ConvertType.php b/application/Espo/Core/Formula/Functions/ExtGroup/CurrencyGroup/ConvertType.phpindex 5b6a31499e..cbf1b9d7ca 100644--- a/application/Espo/Core/Formula/Functions/ExtGroup/CurrencyGroup/ConvertType.php+++ b/application/Espo/Core/Formula/Functions/ExtGroup/CurrencyGroup/ConvertType.php@@ -70,6 +70,8 @@ class ConvertType implements Functhrow BadArgumentType::create(3, 'string');}+ assert(is_numeric($amount));+$value = Currency::create($amount, $fromCode);$convertedValue = $this->converter->convert($value, $toCode);