Skip to content

Commit b156a5c

Browse files
committed
Expand PHPDocs notations to show throwable exceptions
1 parent 99e4dbd commit b156a5c

File tree

6 files changed

+26
-0
lines changed

6 files changed

+26
-0
lines changed

src/Calculators/Calculator.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public function subtract(string $amount, string $subtrahend): string;
1212

1313
public function multiply(string $amount, string $multiplier): string;
1414

15+
/** @throws \InvalidArgumentException */
1516
public function divide(string $amount, string $divisor): string;
1617

1718
public function ceil(string $amount): string;

src/Currency.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public function __construct(array $currency)
4242
$this->display = CurrencyDisplay::Symbol;
4343
}
4444

45+
/** @throws CurrencyDoesNotExistException */
4546
public static function code(string $code): ?self
4647
{
4748
if (is_numeric($code)) {
@@ -64,6 +65,7 @@ public static function code(string $code): ?self
6465
return $currency;
6566
}
6667

68+
/** @throws CurrencyDoesNotExistException */
6769
public static function get(Currency|string|null $currency): ?self
6870
{
6971
if (is_string($currency)) {
@@ -73,6 +75,7 @@ public static function get(Currency|string|null $currency): ?self
7375
return $currency;
7476
}
7577

78+
/** @throws CurrencyDoesNotExistException */
7679
public static function getOrDefault(Currency|string|null $currency): self
7780
{
7881
return self::get($currency) ?? self::getDefault();

src/Money.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ class Money implements MoneyInterface, JsonSerializable
2525

2626
private Currency $currency;
2727

28+
/**
29+
* @throws InvalidArgumentException
30+
* @throws \PostScripton\Money\Exceptions\CurrencyDoesNotExistException
31+
*/
2832
public function __construct(string $amount, Currency|string|null $currency = null)
2933
{
3034
if (! is_numeric($amount)) {

src/PHPDocs/MoneyInterface.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public function getCurrency(): Currency;
2222
* For converting between currencies use `convertInto()` method
2323
* @param Currency|string $currency
2424
* @return self
25+
* @throws \PostScripton\Money\Exceptions\CurrencyDoesNotExistException
2526
*/
2627
public function setCurrency(Currency|string $currency): self;
2728

@@ -73,6 +74,7 @@ public function multiply(string $multiplier): self;
7374
* @param string $divisor <p>
7475
* A number on which the money will be divided </p>
7576
* @return self
77+
* @throws \InvalidArgumentException
7678
*/
7779
public function divide(string $divisor): self;
7880

@@ -203,6 +205,7 @@ public function equals(Money $money, bool $strict = true): bool;
203205
* @param Carbon|null $date <p>
204206
* Historical mode. Pass the date you want to get rate of </p>
205207
* @return Money
208+
* @throws \PostScripton\Money\Exceptions\CurrencyDoesNotExistException
206209
* @throws \PostScripton\Money\Exceptions\CurrenciesNotSupportedByRateExchangerException
207210
* @throws \PostScripton\Money\Exceptions\RateExchangerException
208211
*/
@@ -216,6 +219,7 @@ public function convertTo(Currency|string $to, ?Carbon $date = null): Money;
216219
* Currency you want to convert to </p>
217220
* @param string $rate
218221
* @return Money
222+
* @throws \PostScripton\Money\Exceptions\CurrencyDoesNotExistException
219223
*/
220224
public function offlineConvertTo(Currency|string $currency, string $rate): Money;
221225

@@ -256,13 +260,16 @@ public static function setFormatter(MoneyFormatter $formatter): void;
256260
* Raw amount: 12345 stands for 1.2345 </p>
257261
* @param Currency|string|null $currency
258262
* @return self
263+
* @throws \InvalidArgumentException
264+
* @throws \PostScripton\Money\Exceptions\CurrencyDoesNotExistException
259265
*/
260266
public static function of(string $amount, Currency|string|null $currency = null): Money;
261267

262268
/**
263269
* Empty monetary object
264270
* @param Currency|string|null $currency
265271
* @return Money
272+
* @throws \PostScripton\Money\Exceptions\CurrencyDoesNotExistException
266273
*/
267274
public static function zero(Currency|string|null $currency = null): Money;
268275

@@ -271,6 +278,8 @@ public static function zero(Currency|string|null $currency = null): Money;
271278
* @param string $money
272279
* @param Currency|string|null $currency
273280
* @return self
281+
* @throws \Exception
282+
* @throws \PostScripton\Money\Exceptions\CurrencyDoesNotExistException
274283
*/
275284
public static function parse(string $money, Currency|string|null $currency = null): Money;
276285

src/Parser.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ class Parser
1010
{
1111
private const MONEY_REGEX = '/^(?:(?<start_currency>%s)\s?)?(?<amount>%s)(?:\s?(?<end_currency>%s))?$/';
1212

13+
/**
14+
* @throws Exception
15+
* @throws \PostScripton\Money\Exceptions\CurrencyDoesNotExistException
16+
*/
1317
public static function parse(string $money, Currency|string|null $currency = null): Money
1418
{
1519
$currency = Currency::getOrDefault($currency);

src/helpers.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
* Raw amount: 12345 stands for 1.2345 </p>
1111
* @param Currency|string|null $currency
1212
* @return Money
13+
* @throws InvalidArgumentException
14+
* @throws \PostScripton\Money\Exceptions\CurrencyDoesNotExistException
1315
*/
1416
function money(string $amount, Currency|string|null $currency = null): Money
1517
{
@@ -22,6 +24,7 @@ function money(string $amount, Currency|string|null $currency = null): Money
2224
* Empty monetary object
2325
* @param Currency|string|null $currency
2426
* @return Money
27+
* @throws \PostScripton\Money\Exceptions\CurrencyDoesNotExistException
2528
*/
2629
function money_zero(Currency|string|null $currency = null): Money
2730
{
@@ -35,6 +38,8 @@ function money_zero(Currency|string|null $currency = null): Money
3538
* @param string $money
3639
* @param Currency|string|null $currency
3740
* @return Money
41+
* @throws \Exception
42+
* @throws \PostScripton\Money\Exceptions\CurrencyDoesNotExistException
3843
*/
3944
function money_parse(string $money, Currency|string|null $currency = null): Money
4045
{

0 commit comments

Comments
 (0)