Test Setup Failed
Push — test ( 3f4611...5d3f5c )
by Jonathan
03:36
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
class Utils
6
{
7
    /**
8
     * Turns a byte value into a human-readable representation.
9
     *
10
     * @param int $value Amount of bytes
11
     *
12
     * @return [value, unit]        Human readable value and unit
0 ignored issues
show
Documentation introduced by
The doc-type value,">[value, could not be parsed: Unknown type name "[" at position 0. [(view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
13
     */
14
    public static function getHumanReadableBytes($value)
15
    {
16
        static $unit = array('B', 'KB', 'MB', 'GB', 'TB');
17
18
        $i = floor(log($value, 1024));
19
        $i = min($i, 4); // Only go up to TB
20
21
        return array(
22
            'value' => $value / pow(1024, $i),
23
            'unit' => $unit[$i],
24
        );
25
    }
26
}
27