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

Pretty   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 29
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A bytes() 0 4 1
A time() 0 7 3
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