Format   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 7
c 1
b 0
f 0
dl 0
loc 14
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A humanReadableSize() 0 12 3
1
<?php
2
3
namespace Spatie\DbSnapshots\Helpers;
4
5
class Format
6
{
7
    public static function humanReadableSize(int $sizeInBytes): string
8
    {
9
        $units = ['B', 'KB', 'MB', 'GB', 'TB'];
10
11
        if ($sizeInBytes === 0) {
12
            return '0 '.$units[1];
13
        }
14
        for ($i = 0; $sizeInBytes > 1024; $i++) {
15
            $sizeInBytes /= 1024;
16
        }
17
18
        return round($sizeInBytes, 2).' '.$units[$i];
19
    }
20
}
21