BytesFormatter   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 10
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 0
dl 0
loc 10
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A formatBytes() 0 7 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Migrations\Tools;
6
7
use function floor;
8
use function log;
9
use function pow;
10
use function round;
11
12
/**
13
 * The BytesFormatter class is responsible for converting a bytes integer to a more human readable string.
14
 * This class is used to format the memory used for display purposes when executing migrations.
15
 *
16
 * @internal
17
 */
18
final class BytesFormatter
19
{
20 13
    public static function formatBytes(float $size, int $precision = 2) : string
21
    {
22 13
        $base     = log($size, 1024);
23 13
        $suffixes = ['', 'K', 'M', 'G', 'T'];
24
25 13
        return round(pow(1024, $base - floor($base)), $precision) . $suffixes[(int) floor($base)];
26
    }
27
}
28