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

MemoryUsage   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 45
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getPeak() 0 4 1
A get() 0 4 1
A __construct() 0 2 1
A report() 0 9 1
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