From 77bec6ed02cc8bb41bbd4362e79cdd1f62053d99 Mon Sep 17 00:00:00 2001 From: Gaurav Date: Wed, 9 Mar 2022 13:06:40 +0530 Subject: [PATCH] fix: make PHPStan happy by protecting against some rare scenarios --- src/PriceFormatter.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/PriceFormatter.php b/src/PriceFormatter.php index de243cc..2bff95b 100644 --- a/src/PriceFormatter.php +++ b/src/PriceFormatter.php @@ -35,6 +35,10 @@ class PriceFormatter $removeNonDigits = preg_replace('/[^\d'.preg_quote($currency->decimalSeparator()).']/', '', $formatted); + if (!is_string($removeNonDigits)) { + throw new \Exception('The formatted string could not be resolved to a valid number.'); + } + return (float) str_replace($currency->decimalSeparator(), '.', $removeNonDigits); } }