Skip to content

Commit

Permalink
rename methods
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Nov 17, 2023
1 parent 9874d6b commit 59c509b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 47 deletions.
6 changes: 3 additions & 3 deletions src/Illuminate/Support/Number.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static function format(int|float $number, ?string $locale = null)
* @param ?string $locale
* @return string|false
*/
public static function toPercentage(int|float $number, int $precision = 0, ?string $locale = null)
public static function percentage(int|float $number, int $precision = 0, ?string $locale = null)
{
static::ensureIntlExtensionIsInstalled();

Expand All @@ -60,7 +60,7 @@ public static function toPercentage(int|float $number, int $precision = 0, ?stri
* @param ?string $locale
* @return string|false
*/
public static function toCurrency(int|float $number, string $currency = 'USD', ?string $locale = null)
public static function currency(int|float $number, string $currency = 'USD', ?string $locale = null)
{
static::ensureIntlExtensionIsInstalled();

Expand All @@ -76,7 +76,7 @@ public static function toCurrency(int|float $number, string $currency = 'USD', ?
* @param int $precision
* @return string
*/
public static function toFileSize(int|float $bytes, int $precision = 0)
public static function fileSize(int|float $bytes, int $precision = 0)
{
$units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];

Expand Down
88 changes: 44 additions & 44 deletions tests/Support/SupportNumberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,69 +60,69 @@ public function testToPercent()
{
$this->needsIntlExtension();

$this->assertSame('0%', Number::toPercentage(0, precision: 0));
$this->assertSame('0%', Number::toPercentage(0));
$this->assertSame('1%', Number::toPercentage(1));
$this->assertSame('10.00%', Number::toPercentage(10, precision: 2));
$this->assertSame('100%', Number::toPercentage(100));
$this->assertSame('100.00%', Number::toPercentage(100, precision: 2));

$this->assertSame('300%', Number::toPercentage(300));
$this->assertSame('1,000%', Number::toPercentage(1000));

$this->assertSame('2%', Number::toPercentage(1.75));
$this->assertSame('1.75%', Number::toPercentage(1.75, precision: 2));
$this->assertSame('1.750%', Number::toPercentage(1.75, precision: 3));
$this->assertSame('0%', Number::toPercentage(0.12345));
$this->assertSame('0.12%', Number::toPercentage(0.12345, precision: 2));
$this->assertSame('0.1235%', Number::toPercentage(0.12345, precision: 4));
$this->assertSame('0%', Number::percentage(0, precision: 0));
$this->assertSame('0%', Number::percentage(0));
$this->assertSame('1%', Number::percentage(1));
$this->assertSame('10.00%', Number::percentage(10, precision: 2));
$this->assertSame('100%', Number::percentage(100));
$this->assertSame('100.00%', Number::percentage(100, precision: 2));

$this->assertSame('300%', Number::percentage(300));
$this->assertSame('1,000%', Number::percentage(1000));

$this->assertSame('2%', Number::percentage(1.75));
$this->assertSame('1.75%', Number::percentage(1.75, precision: 2));
$this->assertSame('1.750%', Number::percentage(1.75, precision: 3));
$this->assertSame('0%', Number::percentage(0.12345));
$this->assertSame('0.12%', Number::percentage(0.12345, precision: 2));
$this->assertSame('0.1235%', Number::percentage(0.12345, precision: 4));
}

public function testToCurrency()
{
$this->needsIntlExtension();

$this->assertSame('$0.00', Number::toCurrency(0));
$this->assertSame('$1.00', Number::toCurrency(1));
$this->assertSame('$10.00', Number::toCurrency(10));
$this->assertSame('$0.00', Number::currency(0));
$this->assertSame('$1.00', Number::currency(1));
$this->assertSame('$10.00', Number::currency(10));

$this->assertSame('€0.00', Number::toCurrency(0, 'EUR'));
$this->assertSame('€1.00', Number::toCurrency(1, 'EUR'));
$this->assertSame('€10.00', Number::toCurrency(10, 'EUR'));
$this->assertSame('€0.00', Number::currency(0, 'EUR'));
$this->assertSame('€1.00', Number::currency(1, 'EUR'));
$this->assertSame('€10.00', Number::currency(10, 'EUR'));

$this->assertSame('-$5.00', Number::toCurrency(-5));
$this->assertSame('$5.00', Number::toCurrency(5.00));
$this->assertSame('$5.32', Number::toCurrency(5.325));
$this->assertSame('-$5.00', Number::currency(-5));
$this->assertSame('$5.00', Number::currency(5.00));
$this->assertSame('$5.32', Number::currency(5.325));
}

public function testToCurrencyWithDifferentLocale()
{
$this->needsIntlExtension();

$this->assertSame('1,00 €', Number::toCurrency(1, 'EUR', 'de'));
$this->assertSame('1,00 $', Number::toCurrency(1, 'USD', 'de'));
$this->assertSame('1,00 £', Number::toCurrency(1, 'GBP', 'de'));
$this->assertSame('1,00 €', Number::currency(1, 'EUR', 'de'));
$this->assertSame('1,00 $', Number::currency(1, 'USD', 'de'));
$this->assertSame('1,00 £', Number::currency(1, 'GBP', 'de'));

$this->assertSame('123.456.789,12 $', Number::toCurrency(123456789.12345, 'USD', 'de'));
$this->assertSame('123.456.789,12 €', Number::toCurrency(123456789.12345, 'EUR', 'de'));
$this->assertSame('1 234,56 $US', Number::toCurrency(1234.56, 'USD', 'fr'));
$this->assertSame('123.456.789,12 $', Number::currency(123456789.12345, 'USD', 'de'));
$this->assertSame('123.456.789,12 €', Number::currency(123456789.12345, 'EUR', 'de'));
$this->assertSame('1 234,56 $US', Number::currency(1234.56, 'USD', 'fr'));
}

public function testBytesToHuman()
{
$this->assertSame('0 B', Number::toFileSize(0));
$this->assertSame('1 B', Number::toFileSize(1));
$this->assertSame('1 KB', Number::toFileSize(1024));
$this->assertSame('2 KB', Number::toFileSize(2048));
$this->assertSame('2.00 KB', Number::toFileSize(2048, precision: 2));
$this->assertSame('1.23 KB', Number::toFileSize(1264, precision: 2));
$this->assertSame('1.234 KB', Number::toFileSize(1264, 3));
$this->assertSame('5 GB', Number::toFileSize(1024 * 1024 * 1024 * 5));
$this->assertSame('10 TB', Number::toFileSize((1024 ** 4) * 10));
$this->assertSame('10 PB', Number::toFileSize((1024 ** 5) * 10));
$this->assertSame('1 ZB', Number::toFileSize(1024 ** 7));
$this->assertSame('1 YB', Number::toFileSize(1024 ** 8));
$this->assertSame('1,024 YB', Number::toFileSize(1024 ** 9));
$this->assertSame('0 B', Number::fileSize(0));
$this->assertSame('1 B', Number::fileSize(1));
$this->assertSame('1 KB', Number::fileSize(1024));
$this->assertSame('2 KB', Number::fileSize(2048));
$this->assertSame('2.00 KB', Number::fileSize(2048, precision: 2));
$this->assertSame('1.23 KB', Number::fileSize(1264, precision: 2));
$this->assertSame('1.234 KB', Number::fileSize(1264, 3));
$this->assertSame('5 GB', Number::fileSize(1024 * 1024 * 1024 * 5));
$this->assertSame('10 TB', Number::fileSize((1024 ** 4) * 10));
$this->assertSame('10 PB', Number::fileSize((1024 ** 5) * 10));
$this->assertSame('1 ZB', Number::fileSize(1024 ** 7));
$this->assertSame('1 YB', Number::fileSize(1024 ** 8));
$this->assertSame('1,024 YB', Number::fileSize(1024 ** 9));
}

public function testToHuman()
Expand Down

0 comments on commit 59c509b

Please sign in to comment.