Completed
Push — master ( a25e19...a25e19 )
by Alec
08:36 queued 06:16
created

MemoryUsage   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 54
ccs 16
cts 16
cp 1
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getPeak() 0 4 1
A get() 0 4 1
A __construct() 0 6 1
A diff() 0 5 1
A getReport() 0 5 1
1
<?php declare(strict_types=1);
2
3
namespace AlecRabbit\Accessories;
4
5
use AlecRabbit\Accessories\MemoryUsage\MemoryUsageReport;
6
use AlecRabbit\Accessories\MemoryUsage\MemoryUsageReportFormatter;
7
use AlecRabbit\Reports\Core\AbstractReportable;
8
9
class MemoryUsage extends AbstractReportable
10
{
11 8
    public function __construct()
12
    {
13 8
        parent::__construct();
14 8
        $this->setBindings(
15 8
            MemoryUsageReport::class,
16 8
            MemoryUsageReportFormatter::class
17
        );
18 8
    }
19
20
    /**
21
     * @param bool $real
22
     * @param null|string $unit
23
     * @param int|null $decimals
24
     * @return string
25
     */
26 2
    public static function get(bool $real = false, ?string $unit = null, ?int $decimals = null): string
27
    {
28
        return
29 2
            Pretty::bytes(memory_get_usage($real), $unit, $decimals);
30
    }
31
32
    /**
33
     * @param bool $real
34
     * @param null|string $unit
35
     * @param int|null $decimals
36
     * @return string
37
     */
38 2
    public static function getPeak(bool $real = false, ?string $unit = null, ?int $decimals = null): string
39
    {
40
        return
41 2
            Pretty::bytes(memory_get_peak_usage($real), $unit, $decimals);
42
    }
43
44
    /**
45
     * @return MemoryUsageReport
46
     */
47 4
    public static function getReport(): MemoryUsageReport
48
    {
49
        /** @var MemoryUsageReport $report */
50 4
        $report = (new static)->report();
51 4
        return $report;
52
    }
53
54
    /**
55
     * @param MemoryUsageReport $firstReport
56
     * @return MemoryUsageReport
57
     */
58 1
    public static function diff(MemoryUsageReport $firstReport): MemoryUsageReport
59
    {
60
        /** @var MemoryUsageReport $report */
61 1
        $report = (new static)->report();
62 1
        return $report->diff($firstReport);
63
    }
64
}
65