Completed
Push — master ( 326b3e...061c53 )
by Freek
09:13
created

Format::getEmoji()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 8
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
3
namespace Spatie\Backup\Helpers;
4
5
use Carbon\Carbon;
6
7
class Format
8
{
9
    public static function humanReadableSize(int $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 "\u{2705}";
27
        }
28
29
        return "\u{274C}";
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