/**
* Format the given monetary amount (and currency) for display
*
- * @param float $amount
+ * @param string|int|float $amount
* The monetary amount up for display.
* @param string|null $currency
* The (optional) currency.
/**
* Get formatted money
*
- * @param string $amount
+ * @param string|int|float $amount
* @param string|null $currency
* Currency, defaults to site currency if not provided.
* @param string|null $locale
* @noinspection PhpDocMissingThrowsInspection
* @noinspection PhpUnhandledExceptionInspection
*/
- public function money(string $amount, ?string $currency = NULL, ?string $locale = NULL): string {
+ public function money($amount, ?string $currency = NULL, ?string $locale = NULL): string {
+ // Empty value => empty string
+ if (is_null($amount) || $amount === '' || $amount === FALSE) {
+ return '';
+ }
+ // Verify the amount is a number or numeric string/object
+ elseif ($amount === TRUE || !is_numeric((string) $amount)) {
+ throw new \CRM_Core_Exception('Invalid value for type money');
+ }
if (!$currency) {
$currency = Civi::settings()->get('defaultCurrency');
}