Test Setup Failed
Push — test ( ba2df3...546d28 )
by Jonathan
05:09 queued 01:53
created

Utils::getHumanReadableBytes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
nc 1
nop 1
dl 0
loc 12
rs 9.4285
c 1
b 0
f 0
1
<?php
2
3
namespace Kint;
4
5
/**
6
 * A collection of utility methods. Should all be static methods with no dependencies.
7
 */
8
class Utils
9
{
10
    /**
11
     * Turns a byte value into a human-readable representation.
12
     *
13
     * @param int $value Amount of bytes
14
     *
15
     * @return array Human readable value and unit
16
     */
17
    public static function getHumanReadableBytes($value)
18
    {
19
        static $unit = array('B', 'KB', 'MB', 'GB', 'TB');
20
21
        $i = floor(log($value, 1024));
22
        $i = min($i, 4); // Only go up to TB
23
24
        return array(
25
            'value' => (float) ($value / pow(1024, $i)),
26
            'unit' => $unit[$i],
27
        );
28
    }
29
}
30