Skip to content

Commit 8707be0

Browse files
authored
Move base units to a constant
1 parent 8b93d39 commit 8707be0

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

src/Illuminate/Support/Number.php

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ class Number
1010
{
1111
use Macroable;
1212

13+
private const BASE_UNITS = [
14+
3 => 'K',
15+
6 => 'M',
16+
9 => 'B',
17+
12 => 'T',
18+
15 => 'Q',
19+
];
20+
1321
/**
1422
* The current default locale.
1523
*
@@ -192,13 +200,7 @@ public static function abbreviate(int|float $number, int $precision = 0, ?int $m
192200
*/
193201
public static function forHumans(int|float $number, int $precision = 0, ?int $maxPrecision = null, bool $abbreviate = false)
194202
{
195-
return static::summarize($number, $precision, $maxPrecision, $abbreviate ? [
196-
3 => 'K',
197-
6 => 'M',
198-
9 => 'B',
199-
12 => 'T',
200-
15 => 'Q',
201-
] : [
203+
return static::summarize($number, $precision, $maxPrecision, $abbreviate ? self::BASE_UNITS : [
202204
3 => ' thousand',
203205
6 => ' million',
204206
9 => ' billion',
@@ -218,14 +220,8 @@ public static function forHumans(int|float $number, int $precision = 0, ?int $ma
218220
*/
219221
protected static function summarize(int|float $number, int $precision = 0, ?int $maxPrecision = null, array $units = [])
220222
{
221-
if (empty($units)) {
222-
$units = [
223-
3 => 'K',
224-
6 => 'M',
225-
9 => 'B',
226-
12 => 'T',
227-
15 => 'Q',
228-
];
223+
if ($units === []) {
224+
$units = self::BASE_UNITS;
229225
}
230226

231227
switch (true) {

0 commit comments

Comments
 (0)