Skip to content

Commit eb12350

Browse files
authored
Mark Money::fromString pure (#19)
This requires Currency to be mutation free.
1 parent a5bcfd6 commit eb12350

File tree

2 files changed

+4
-19
lines changed

2 files changed

+4
-19
lines changed

src/Currency.php

+2-19
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
* @psalm-type CurrencyAlpha2Code=string
1717
* @psalm-type CurrencyMetadata=array{display_name: string, numeric_code: int, default_fraction_digits: int, sub_unit: int, sign: string, deprecated: boolean}
1818
* @psalm-type CurrencyRegistry=array<CurrencyAlpha2Code, CurrencyMetadata>
19+
*
20+
* @psalm-immutable
1921
*/
2022
final class Currency implements JsonSerializable
2123
{
@@ -1647,8 +1649,6 @@ public static function getCurrenciesIncludingDeprecated(): array
16471649

16481650
/**
16491651
* Returns the ISO 4217 currency code of this currency.
1650-
*
1651-
* @psalm-mutation-free
16521652
*/
16531653
public function getCurrencyCode(): string
16541654
{
@@ -1658,8 +1658,6 @@ public function getCurrencyCode(): string
16581658
/**
16591659
* Returns the default number of fraction digits used with this
16601660
* currency.
1661-
*
1662-
* @psalm-mutation-free
16631661
*/
16641662
public function getDefaultFractionDigits(): int
16651663
{
@@ -1668,8 +1666,6 @@ public function getDefaultFractionDigits(): int
16681666

16691667
/**
16701668
* Returns the name that is suitable for displaying this currency.
1671-
*
1672-
* @psalm-mutation-free
16731669
*/
16741670
public function getDisplayName(): string
16751671
{
@@ -1678,8 +1674,6 @@ public function getDisplayName(): string
16781674

16791675
/**
16801676
* Returns the ISO 4217 numeric code of this currency.
1681-
*
1682-
* @psalm-mutation-free
16831677
*/
16841678
public function getNumericCode(): int
16851679
{
@@ -1688,8 +1682,6 @@ public function getNumericCode(): int
16881682

16891683
/**
16901684
* Returns the minor currency sub units.
1691-
*
1692-
* @psalm-mutation-free
16931685
*/
16941686
public function getSubUnit(): int
16951687
{
@@ -1698,8 +1690,6 @@ public function getSubUnit(): int
16981690

16991691
/**
17001692
* Returns the currency sign.
1701-
*
1702-
* @psalm-mutation-free
17031693
*/
17041694
public function getSign(): string
17051695
{
@@ -1708,8 +1698,6 @@ public function getSign(): string
17081698

17091699
/**
17101700
* Returns the deprecation status.
1711-
*
1712-
* @psalm-mutation-free
17131701
*/
17141702
public function isDeprecated(): bool
17151703
{
@@ -1718,17 +1706,12 @@ public function isDeprecated(): bool
17181706

17191707
/**
17201708
* {@inheritdoc}
1721-
*
1722-
* @psalm-mutation-free
17231709
*/
17241710
public function jsonSerialize(): string
17251711
{
17261712
return $this->getCurrencyCode();
17271713
}
17281714

1729-
/**
1730-
* @psalm-mutation-free
1731-
*/
17321715
public function equals(self $currency): bool
17331716
{
17341717
return $this->getCurrencyCode() === $currency->getCurrencyCode();

src/Money.php

+2
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ public function __construct(int $amount, Currency $currency)
6464
* number of fractional digits then the value will be rounded to the
6565
* currency's number of fractional digits.
6666
*
67+
* @psalm-pure
68+
*
6769
* @param float|int|object|string $value
6870
* @param Currency|string $currency
6971
*

0 commit comments

Comments
 (0)