Completed
Push — master ( 4eee22...4eee22 )
by Alec
04:30
created

Pretty::time()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 2
nop 3
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 3
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