Format::emoji()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Spatie\Backup\Helpers;
4
5
use Carbon\Carbon;
6
7
class Format
8
{
9
    public static function humanReadableSize(float $sizeInBytes): string
10
    {
11
        $units = ['B', 'KB', 'MB', 'GB', 'TB'];
12
13
        if ($sizeInBytes === 0) {
14
            return '0 '.$units[1];
15
        }
16
        for ($i = 0; $sizeInBytes > 1024; $i++) {
17
            $sizeInBytes /= 1024;
18
        }
19
20
        return round($sizeInBytes, 2).' '.$units[$i];
21
    }
22
23
    public static function emoji(bool $bool): string
24
    {
25
        if ($bool) {
26
            return '✅';
27
        }
28
29
        return '❌';
30
    }
31
32
    public static function ageInDays(Carbon $date): string
33
    {
34
        return number_format(round($date->diffInMinutes() / (24 * 60), 2), 2).' ('.$date->diffForHumans().')';
35
    }
36
}
37