1
0
Fork 0
mirror of https://github.com/archtechx/money.git synced 2025-12-12 19:34:02 +00:00

text: exception message and docblock updates

This commit is contained in:
Gaurav 2022-04-05 09:49:36 +05:30
parent 34740e66a6
commit 5952ace37e
3 changed files with 12 additions and 6 deletions

View file

@ -180,11 +180,11 @@ $fromFormatted = Money::fromFormatted($formatted);
$fromFormatted->is($money); // true $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 ```php
$money = money(1000); $money = money(1000);
$formatted = $money->formatted(); // $10.00 $formatted = $money->formatted(['prefix' => '$ ', 'suffix' => ' USD']); // $ 10.00 USD
$fromFormatted = Money::fromFormatted($formatted, USD::class, ['decimalSeparator' => ',', 'prefix' => '$ ', 'suffix' => ' USD']); $fromFormatted = Money::fromFormatted($formatted, USD::class, ['prefix' => '$ ', 'suffix' => ' USD']);
$fromFormatted->is($money); // true $fromFormatted->is($money); // true
``` ```

View file

@ -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 public static function fromFormatted(string $formatted, Currency|string $currency = null, mixed ...$overrides): self
{ {
$currency = isset($currency) $currency = isset($currency)

View file

@ -56,13 +56,13 @@ class PriceFormatter
&& str_ends_with($formatted, $currency->suffix()) && str_ends_with($formatted, $currency->suffix())
) { ) {
if ($possibleCurrency) { 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; $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'.");
} }
} }