Add exception code for bad values.

This commit is contained in:
James Cole 2022-05-04 20:32:51 +02:00
parent 3d1233314a
commit 610bc9f4bc
2 changed files with 10 additions and 4 deletions

View File

@ -614,10 +614,9 @@ class OperatorQuerySearch implements SearchInterface
// amount
//
case 'amount_is':
// strip comma's, make dots.
Log::debug(sprintf('Original value "%s"', $value));
$value = str_replace(',', '.', (string) $value);
$amount = app('steam')->positive($value);
Log::debug(sprintf('Set "%s" using collector with value "%s"', $operator, $amount));
$this->collector->amountIs($amount);

View File

@ -34,6 +34,7 @@ use JsonException;
use Log;
use stdClass;
use Str;
use ValueError;
/**
* Class Steam.
@ -627,8 +628,14 @@ class Steam
if ('' === $amount) {
return '0';
}
if (bccomp($amount, '0') === -1) {
$amount = bcmul($amount, '-1');
try {
if (bccomp($amount, '0') === -1) {
$amount = bcmul($amount, '-1');
}
} catch (ValueError $e) {
Log::error(sprintf('ValueError in Steam::positive("%s"): %s', $amount, $e->getMessage()));
Log::error($e->getTraceAsString());
return '0';
}
return $amount;