Passed
Push — master ( 707534...dc95cb )
by Alec
01:50
created

MemoryUsage::getPeak()   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
declare(strict_types=1);
4
5
namespace AlecRabbit\Accessories;
6
7
class MemoryUsage
8
{
9
10
    /**
11
     * Static class. Private Constructor.
12
     */
13
    // @codeCoverageIgnoreStart
14
    private function __construct()
15
    {
16
    }
17
    // @codeCoverageIgnoreEnd
18
19
    /**
20
     * @param bool $real
21
     * @param null|string $unit
22
     * @param int|null $decimals
23
     * @return string
24
     */
25 2
    public static function get(bool $real = false, ?string $unit = null, ?int $decimals = null): string
26
    {
27
        return
28 2
            Pretty::bytes(memory_get_usage($real), $unit, $decimals);
29
    }
30
31
    /**
32
     * @param bool $real
33
     * @param null|string $unit
34
     * @param int|null $decimals
35
     * @return string
36
     */
37 2
    public static function getPeak(bool $real = false, ?string $unit = null, ?int $decimals = null): string
38
    {
39
        return
40 2
            Pretty::bytes(memory_get_peak_usage($real), $unit, $decimals);
41
    }
42
43 4
    public static function report(?string $unit = null, ?int $decimals = null): MemoryUsageReport
44
    {
45 4
        return new MemoryUsageReport(
46 4
            memory_get_usage(),
47 4
            memory_get_peak_usage(),
48 4
            memory_get_usage(true),
49 4
            memory_get_peak_usage(true),
50 4
            $unit,
51 4
            $decimals
52
        );
53
    }
54
}
55