Completed
Push — master ( caeb4b...4eee22 )
by Alec
02:52
created

Pretty::bytes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 3
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * User: alec
4
 * Date: 09.10.18
5
 * Time: 22:45
6
 */
7
declare(strict_types=1);
8
9
namespace AlecRabbit;
10
11
use const AlecRabbit\Helpers\Constants\DEFAULT_PRECISION;
12
13
class Pretty
14
{
15
    public const DEFAULT_DECIMALS = 2;
16
17
    /**
18
     * @param int $number
19
     * @param null|string $unit
20
     * @param int|null $decimals
21
     * @return string
22
     */
23 7
    public static function bytes(int $number, ?string $unit = null, ?int $decimals = null): string
24
    {
25
        return
26 7
            format_bytes($number, $unit, $decimals ?? static::DEFAULT_DECIMALS);
27
    }
28
29
    /**
30
     * @param float $value
31
     * @param int|null $units
32
     * @param int|null $precision
33
     * @return string
34
     */
35 20
    public static function time(float $value, ?int $units = null, ?int $precision = null): string
36
    {
37 20
        if (null === $units && null === $precision) {
38 13
            return format_time_auto($value);
39
        }
40
        return
41 7
            format_time($value, $units, $precision ?? DEFAULT_PRECISION);
42
    }
43
}
44