Completed
Push — master ( 02dbee...2f541b )
by Alec
04:00 queued 15s
created

Pretty::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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