Skip to content

Commit 5755f80

Browse files
authored
refactor(intl): move currency enum to tempest/intl (#1312)
1 parent 4820908 commit 5755f80

File tree

6 files changed

+36
-6
lines changed

6 files changed

+36
-6
lines changed
Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
<?php
22

3-
namespace Tempest\Support;
3+
namespace Tempest\Intl;
4+
5+
use Stringable;
6+
use TypeError;
7+
use ValueError;
8+
9+
use function Tempest\Support\str;
410

511
/**
612
* Represents an ISO-4217 currency.
@@ -165,12 +171,15 @@ enum Currency: string
165171
case ZMW = 'ZMW';
166172
case ZWG = 'ZWG';
167173

174+
/**
175+
* Parses the given value into a `Currency` instance.
176+
*/
168177
public static function parse(mixed $currency): self
169178
{
170179
if ($currency instanceof self) {
171180
return $currency;
172181
}
173182

174-
return self::from($currency);
183+
return self::from(str($currency)->trim()->upper()->toString());
175184
}
176185
}

packages/intl/src/MessageFormat/Functions/NumberFunction.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Tempest\Intl\MessageFormat\Functions;
44

5+
use Tempest\Intl\Currency;
56
use Tempest\Intl\IntlConfig;
67
use Tempest\Intl\Locale;
78
use Tempest\Intl\MessageFormat\Formatter\FormattedValue;
@@ -10,7 +11,6 @@
1011
use Tempest\Intl\Number;
1112
use Tempest\Intl\PluralRules\PluralRulesMatcher;
1213
use Tempest\Support\Arr;
13-
use Tempest\Support\Currency;
1414
use Tempest\Support\Str;
1515

1616
final class NumberFunction implements FormattingFunction, SelectorFunction

packages/intl/src/Number/functions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
namespace Tempest\Intl\Number;
44

55
use NumberFormatter;
6+
use Tempest\Intl\Currency;
67
use Tempest\Intl\Locale;
7-
use Tempest\Support\Currency;
88
use Tempest\Support\Math;
99

1010
/**
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace Tempest\Intl\Tests;
4+
5+
use PHPUnit\Framework\TestCase;
6+
use Tempest\Intl\Currency;
7+
8+
use function Tempest\Support\str;
9+
10+
final class CurrencyTest extends TestCase
11+
{
12+
public function test_parse(): void
13+
{
14+
$this->assertSame(Currency::EUR, Currency::parse('EUR'));
15+
$this->assertSame(Currency::EUR, Currency::parse(' EUR '));
16+
$this->assertSame(Currency::EUR, Currency::parse('eur'));
17+
$this->assertSame(Currency::EUR, Currency::parse(' eur '));
18+
$this->assertSame(Currency::EUR, Currency::parse(Currency::EUR));
19+
$this->assertSame(Currency::EUR, Currency::parse(str('eur')));
20+
}
21+
}

packages/intl/tests/FormatterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use PHPUnit\Framework\Attributes\TestWith;
66
use PHPUnit\Framework\TestCase;
77
use Tempest\DateTime\DateTime;
8+
use Tempest\Intl\Currency;
89
use Tempest\Intl\IntlConfig;
910
use Tempest\Intl\Locale;
1011
use Tempest\Intl\MessageFormat\Formatter\FormattedValue;
@@ -15,7 +16,6 @@
1516
use Tempest\Intl\MessageFormat\Functions\StringFunction;
1617
use Tempest\Intl\MessageFormat\Markup\HtmlTagFormatter;
1718
use Tempest\Intl\MessageFormat\Markup\VoidHtmlTagFormatter;
18-
use Tempest\Support\Currency;
1919

2020
final class FormatterTest extends TestCase
2121
{

packages/intl/tests/FunctionsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
66
use PHPUnit\Framework\TestCase;
7+
use Tempest\Intl\Currency;
78
use Tempest\Intl\Locale;
89
use Tempest\Intl\Number;
9-
use Tempest\Support\Currency;
1010
use Tempest\Support\Math;
1111

1212
final class FunctionsTest extends TestCase

0 commit comments

Comments
 (0)