Test Failed
Push — master ( 068d94...d12c1b )
by Alec
07:11
created

MemoryUsage::createEmptyReport()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 1
cts 1
cp 1
crap 1
rs 10
c 0
b 0
f 0
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\Contracts\ReportInterface;
8
use AlecRabbit\Reports\Core\Reportable;
9
10
class MemoryUsage extends Reportable
11
{
12
    /** @var null|MemoryUsageReportFormatter */
13
    protected static $formatter;
14
15
    /**
16
     * @param bool $real
17
     * @param null|string $unit
18
     * @param int|null $decimals
19
     * @return string
20
     */
21
    public static function get(bool $real = false, ?string $unit = null, ?int $decimals = null): string
22
    {
23
        return
24
            Pretty::bytes(memory_get_usage($real), $unit, $decimals);
25
    }
26
27 2
    /**
28
     * @param bool $real
29
     * @param null|string $unit
30 2
     * @param int|null $decimals
31
     * @return string
32
     */
33
    public static function getPeak(bool $real = false, ?string $unit = null, ?int $decimals = null): string
34
    {
35
        return
36
            Pretty::bytes(memory_get_peak_usage($real), $unit, $decimals);
37
    }
38
39 2
    /**
40
     * @return MemoryUsageReport
41
     */
42 2
    public static function reportStatic(): MemoryUsageReport
43
    {
44
        return
45
            new MemoryUsageReport();
46
    }
47
48 4
    /**
49
     * @return MemoryUsageReportFormatter
50
     */
51 4
    public static function getFormatter(): MemoryUsageReportFormatter
52 4
    {
53 4
        if (null === static::$formatter) {
54 4
            static::$formatter = new MemoryUsageReportFormatter();
55 4
        }
56
        return static::$formatter;
57
    }
58
59
    /**
60
     * @param null|MemoryUsageReportFormatter $formatter
61
     */
62 7
    public static function setFormatter(?MemoryUsageReportFormatter $formatter): void
63
    {
64 7
        self::$formatter = $formatter;
65 1
    }
66
67 7
    protected function createEmptyReport(): ReportInterface
68
    {
69
        return
0 ignored issues
show
Bug Best Practice introduced by
The expression return static::reportStatic() returns the type AlecRabbit\Accessories\M...Usage\MemoryUsageReport which is incompatible with the type-hinted return AlecRabbit\Reports\Contracts\ReportInterface.
Loading history...
70
            static::reportStatic();
71
    }
72
}
73