Completed
Push — master ( 4042dc...8f92db )
by Eric
8s
created

Format::ageInDays()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
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