Skip to content

Commit c11386e

Browse files
authored
[12.x] Fix passing countable to Number::format() (laravel#57434)
* Fix passing countable to Number::format() * Add test assertions * Fix typo
1 parent 760ffd1 commit c11386e

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/Illuminate/Support/Str.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,10 @@ public static function parseCallback($callback, $default = null)
996996
*/
997997
public static function plural($value, $count = 2, $prependCount = false)
998998
{
999+
if (is_countable($count)) {
1000+
$count = count($count);
1001+
}
1002+
9991003
return ($prependCount ? Number::format($count).' ' : '').Pluralizer::plural($value, $count);
10001004
}
10011005

tests/Support/SupportStrTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1870,8 +1870,16 @@ public function testReplaceMatches()
18701870
public function testPlural(): void
18711871
{
18721872
$this->assertSame('Laracon', Str::plural('Laracon', 1));
1873+
$this->assertSame('Laracon', Str::plural('Laracon', [2025]));
1874+
18731875
$this->assertSame('Laracons', Str::plural('Laracon', 3));
1876+
$this->assertSame('Laracons', Str::plural('Laracon', [2024, 2025]));
1877+
1878+
$this->assertSame('1 Laracon', Str::plural('Laracon', 1, prependCount: true));
1879+
$this->assertSame('1 Laracon', Str::plural('Laracon', [2025], prependCount: true));
1880+
18741881
$this->assertSame('1,000 Laracons', Str::plural('Laracon', 1000, prependCount: true));
1882+
$this->assertSame('2 Laracons', Str::plural('Laracon', [2024, 2025], prependCount: true));
18751883
}
18761884

18771885
public function testPluralPascal(): void

0 commit comments

Comments
 (0)