Format::getHumanReadableSize()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 1
dl 0
loc 13
rs 9.8333
c 0
b 0
f 0
1
<?php
2
3
namespace EricMakesStuff\ServerMonitor\Helpers;
4
5
use Carbon\Carbon;
6
7
class Format
8
{
9
    /**
10
     * @param int $sizeInBytes
11
     *
12
     * @return string
13
     */
14
    public static function getHumanReadableSize($sizeInBytes)
15
    {
16
        $units = ['B', 'KB', 'MB', 'GB', 'TB'];
17
18
        if ($sizeInBytes === 0) {
19
            return '0 '.$units[1];
20
        }
21
        for ($i = 0; $sizeInBytes > 1024; ++$i) {
22
            $sizeInBytes /= 1024;
23
        }
24
25
        return round($sizeInBytes, 2).' '.$units[$i];
26
    }
27
}
28