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

Utils   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 22
rs 10
c 1
b 0
f 0
wmc 1
lcom 0
cbo 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getHumanReadableBytes() 0 12 1
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