Formats   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
dl 0
loc 15
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A dataSize() 0 7 2
1
<?php
2
3
namespace BlueData\Data;
4
5
class Formats
6
{
7
    const SIZE_UNITS = ['B', 'kB', 'MB', 'GB', 'TB', 'PB'];
8
9
    /**
10
     * @param int $bytes
11
     * @return string
12
     */
13 1
    public static function dataSize($bytes)
14
    {
15 1
        $format = '%01.2f %s';
16 1
        $mod = 1000;
17 1
        $power = ($bytes > 0) ? floor(log($bytes, $mod)) : 0;
18
19 1
        return sprintf($format, $bytes / ($mod ** $power), self::SIZE_UNITS[$power]);
20
    }
21
}
22