Passed
Pull Request — master (#681)
by Jonathan
02:01
created

BytesFormatter   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 8
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A formatBytes() 0 6 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
final class BytesFormatter
13
{
14 53
    public static function formatBytes(int $size, int $precision = 2) : string
15
    {
16 53
        $base     = log($size, 1024);
17 53
        $suffixes = ['', 'K', 'M', 'G', 'T'];
18
19 53
        return round(pow(1024, $base - floor($base)), $precision) . $suffixes[floor($base)];
20
    }
21
}
22