mirror of
https://github.com/archtechx/money.git
synced 2025-12-12 11:24:03 +00:00
text: exception message and docblock updates
This commit is contained in:
parent
34740e66a6
commit
5952ace37e
3 changed files with 12 additions and 6 deletions
|
|
@ -180,11 +180,11 @@ $fromFormatted = Money::fromFormatted($formatted);
|
|||
$fromFormatted->is($money); // true
|
||||
```
|
||||
|
||||
Optional overrides for the [currency specification](#currency-logic) are accepted too.
|
||||
If you had passed overrides while [formatting the money instance](#formatting-money), the same can passed to this method.
|
||||
```php
|
||||
$money = money(1000);
|
||||
$formatted = $money->formatted(); // $10.00
|
||||
$fromFormatted = Money::fromFormatted($formatted, USD::class, ['decimalSeparator' => ',', 'prefix' => '$ ', 'suffix' => ' USD']);
|
||||
$formatted = $money->formatted(['prefix' => '$ ', 'suffix' => ' USD']); // $ 10.00 USD
|
||||
$fromFormatted = Money::fromFormatted($formatted, USD::class, ['prefix' => '$ ', 'suffix' => ' USD']);
|
||||
$fromFormatted->is($money); // true
|
||||
```
|
||||
|
||||
|
|
|
|||
|
|
@ -171,7 +171,13 @@ final class Money implements JsonSerializable, Arrayable, Wireable
|
|||
]));
|
||||
}
|
||||
|
||||
/** Create a Money instance from a formatted string. */
|
||||
/**
|
||||
* Create a Money instance from a formatted string.
|
||||
*
|
||||
* @param string $formatted The string formatted using the `formatted()` or `rawFormatted()` method.
|
||||
* @param Currency|string|null $currency The currency to use when passing the overrides. If not provided, the currency of the formatted string is used.
|
||||
* @param array ...$overrides The overrides used when formatting the money instance.
|
||||
*/
|
||||
public static function fromFormatted(string $formatted, Currency|string $currency = null, mixed ...$overrides): self
|
||||
{
|
||||
$currency = isset($currency)
|
||||
|
|
|
|||
|
|
@ -56,13 +56,13 @@ class PriceFormatter
|
|||
&& str_ends_with($formatted, $currency->suffix())
|
||||
) {
|
||||
if ($possibleCurrency) {
|
||||
throw new CannotExtractCurrencyException('Multiple currencies are using the same prefix and suffix. Please specify the currency of the formatted string.');
|
||||
throw new CannotExtractCurrencyException("Multiple currencies are using the same prefix and suffix as '$formatted'. Please specify the currency of the formatted string.");
|
||||
}
|
||||
|
||||
$possibleCurrency = $currency;
|
||||
}
|
||||
}
|
||||
|
||||
return $possibleCurrency ?? throw new CannotExtractCurrencyException('None of the currencies are using the prefix and suffix that would match with the formatted string.');
|
||||
return $possibleCurrency ?? throw new CannotExtractCurrencyException("None of the currencies are using the prefix and suffix that would match with the formatted string '$formatted'.");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue