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

MemoryUsage   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 61
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0
wmc 7

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getPeak() 0 4 1
A get() 0 4 1
A getFormatter() 0 6 2
A reportStatic() 0 4 1
A setFormatter() 0 3 1
A createEmptyReport() 0 4 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\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