Passed
Push — master ( c28376...9b6cf0 )
by Georgi
07:09
created

Utils::bytesToHuman()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 9
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace Epesi\Core\Helpers;
4
5
class Utils
6
{
7
    public static function bytesToHuman($bytes)
8
    {
9
        $units = [__('B'), __('KiB'), __('MiB'), __('GiB'), __('TiB'), __('PiB')];
10
11
        for ($i = 0; $bytes > 1024; $i++) {
12
            $bytes /= 1024;
13
        }
14
15
        return round($bytes, 2) . ' ' . $units[$i];
0 ignored issues
show
Bug introduced by
Are you sure $units[$i] of type array|string can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

15
        return round($bytes, 2) . ' ' . /** @scrutinizer ignore-type */ $units[$i];
Loading history...
16
    }
17
}