GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

HumanFilesize   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
c 1
b 0
f 0
dl 0
loc 31
rs 10
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A humanFilesize() 0 24 5
1
<?php
2
3
namespace ProtoneMedia\LaravelMixins\String;
4
5
class HumanFilesize
6
{
7
    /**
8
     * Returns a function containing the macro.
9
     *
10
     * @return callable
11
     */
12
    public function humanFilesize(): callable
13
    {
14
        /**
15
         * Formats the $value into a human readable filesize.
16
         */
17
        return function ($value, $precision = 1): string {
18
            if ($value >= 1000000000000) {
19
                $value = round($value / (1024 * 1024 * 1024 * 1024), $precision);
20
                $unit  = 'TB';
21
            } elseif ($value >= 1000000000) {
22
                $value = round($value / (1024 * 1024 * 1024), $precision);
23
                $unit  = 'GB';
24
            } elseif ($value >= 1000000) {
25
                $value = round($value / (1024 * 1024), $precision);
26
                $unit  = 'MB';
27
            } elseif ($value >= 1000) {
28
                $value = round($value / (1024), $precision);
29
                $unit  = 'KB';
30
            } else {
31
                $unit = 'Bytes';
32
                return number_format($value) . ' ' . $unit;
33
            }
34
35
            return number_format($value, $precision) . ' ' . $unit;
36
        };
37
    }
38
}
39