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

Format::getEmoji()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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