Test Setup Failed
Push — test ( 546d28...089b88 )
by Jonathan
03:07
created

Utils::isSequential()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
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
    public static function isSequential(array $array)
31
    {
32
        return array_keys($array) === range(0, count($array) - 1);
33
    }
34
}
35