Test Setup Failed
Push — develop ( 7cd2b2...750858 )
by Alec
03:42
created

Factory::getExtendedCounterReportFormatter()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
ccs 4
cts 4
cp 1
crap 2
1
<?php declare(strict_types=1);
2
3
namespace AlecRabbit\Tools\Reports;
4
5
use AlecRabbit\Tools\Reports\Formatters\BenchmarkFunctionFormatter;
6
use AlecRabbit\Tools\Reports\Formatters\BenchmarkReportFormatter;
7
use AlecRabbit\Tools\Reports\Formatters\Contracts\FormatterInterface;
8
use AlecRabbit\Tools\Reports\Formatters\ExtendedCounterReportFormatter;
9
use AlecRabbit\Tools\Reports\Formatters\ProfilerReportFormatter;
10
use AlecRabbit\Tools\Reports\Formatters\SimpleCounterReportFormatter;
11
use AlecRabbit\Tools\Reports\Formatters\TimerReportFormatter;
12
use function AlecRabbit\typeOf;
13
14
class Factory
15
{
16
    /** @var null|TimerReportFormatter */
17
    protected static $timerReportFormatter;
18
19
    /** @var null|SimpleCounterReportFormatter */
20
    protected static $simpleCounterReportFormatter;
21
22
    /** @var null|ExtendedCounterReportFormatter */
23
    protected static $extendedCounterReportFormatter;
24
25
    /** @var null|ProfilerReportFormatter */
26
    protected static $profilerReportFormatter;
27
28
    /** @var null|BenchmarkReportFormatter */
29
    protected static $benchmarkReportFormatter;
30
31
    /** @var null|BenchmarkFunctionFormatter */
32
    protected static $benchmarkFunctionFormatter;
33
34
    /** @codeCoverageIgnore */
35
    private function __construct()
36
    {
37
        // Static class
38
    }
39
40
    /**
41
     * @return TimerReportFormatter
42
     */
43
    public static function getTimerReportFormatter(): TimerReportFormatter
44
    {
45
        if (null === static::$timerReportFormatter) {
46
            static::$timerReportFormatter = new TimerReportFormatter();
47
        }
48
        return
49 15
            static::$timerReportFormatter;
50
    }
51 15
52
    /**
53 12
     * @param null|TimerReportFormatter $timerReportFormatter
54
     */
55 10
    public static function setTimerReportFormatter(?TimerReportFormatter $timerReportFormatter): void
56
    {
57 9
        self::$timerReportFormatter = $timerReportFormatter;
58
    }
59 8
60
    /**
61 7
     * @return SimpleCounterReportFormatter
62
     */
63 6
    public static function getSimpleCounterReportFormatter(): SimpleCounterReportFormatter
64
    {
65 5
        if (null === static::$simpleCounterReportFormatter) {
66
            static::$simpleCounterReportFormatter = new SimpleCounterReportFormatter();
67 1
        }
68
        return
69
            new SimpleCounterReportFormatter();
70
    }
71
72
    /**
73
     * @param null|SimpleCounterReportFormatter $simpleCounterReportFormatter
74 15
     */
75
    public static function setSimpleCounterReportFormatter(
76 15
        ?SimpleCounterReportFormatter $simpleCounterReportFormatter
77
    ): void {
78 12
        self::$simpleCounterReportFormatter = $simpleCounterReportFormatter;
79
    }
80 10
81
    /**
82 9
     * @return ExtendedCounterReportFormatter
83
     */
84 8
    public static function getExtendedCounterReportFormatter(): ExtendedCounterReportFormatter
85
    {
86 7
        if (null === static::$extendedCounterReportFormatter) {
87
            static::$extendedCounterReportFormatter = new ExtendedCounterReportFormatter();
88 6
        }
89
        return
90 5
            new ExtendedCounterReportFormatter();
91
    }
92 1
93
    /**
94
     * @param null|ExtendedCounterReportFormatter $extendedCounterReportFormatter
95
     */
96
    public static function setExtendedCounterReportFormatter(
97
        ?ExtendedCounterReportFormatter $extendedCounterReportFormatter
98
    ): void {
99 12
        self::$extendedCounterReportFormatter = $extendedCounterReportFormatter;
100
    }
101
102
    /**
103
     * @return BenchmarkFunctionFormatter
104
     */
105 12
    public static function getBenchmarkFunctionFormatter(): BenchmarkFunctionFormatter
106
    {
107
        if (null === static::$benchmarkFunctionFormatter) {
108
            static::$benchmarkFunctionFormatter = new BenchmarkFunctionFormatter();
109
        }
110
        return
111
            static::$benchmarkFunctionFormatter->resetEqualReturns();
112 9
    }
113
114
    /**
115
     * @param BenchmarkFunctionFormatter $benchmarkFunctionFormatter
116
     */
117
    public static function setBenchmarkFunctionFormatter(
118 9
        BenchmarkFunctionFormatter $benchmarkFunctionFormatter
119
    ): void {
120
        self::$benchmarkFunctionFormatter = $benchmarkFunctionFormatter;
121
    }
122
123
    /**
124
     * @return BenchmarkReportFormatter
125 7
     */
126
    public static function getBenchmarkReportFormatter(): BenchmarkReportFormatter
127
    {
128
        if (null === static::$benchmarkReportFormatter) {
129
            static::$benchmarkReportFormatter = new BenchmarkReportFormatter();
130
        }
131 7
        return
132
            new BenchmarkReportFormatter();
133
    }
134
135
    /**
136
     * @param null|BenchmarkReportFormatter $benchmarkReportFormatter
137
     */
138 5
    public static function setBenchmarkReportFormatter(?BenchmarkReportFormatter $benchmarkReportFormatter): void
139
    {
140
        self::$benchmarkReportFormatter = $benchmarkReportFormatter;
141
    }
142
143
    /**
144 5
     * @return ProfilerReportFormatter
145
     */
146
    public static function getProfilerReportFormatter(): ProfilerReportFormatter
147
    {
148
        if (null === static::$profilerReportFormatter) {
149
            static::$profilerReportFormatter = new ProfilerReportFormatter();
150 4
        }
151
        return
152 4
            new ProfilerReportFormatter();
153 1
    }
154
155
    /**
156 4
     * @param null|ProfilerReportFormatter $profilerReportFormatter
157
     */
158
    public static function setProfilerReportFormatter(?ProfilerReportFormatter $profilerReportFormatter): void
159
    {
160
        self::$profilerReportFormatter = $profilerReportFormatter;
161
    }
162
163
    public function setFormatter(FormatterInterface $formatter): void
164
    {
165
        if ($formatter instanceof TimerReportFormatter) {
166
            static::setTimerReportFormatter($formatter);
167
        }
168
        if ($formatter instanceof ProfilerReportFormatter) {
169
            static::setProfilerReportFormatter($formatter);
170
        }
171
        throw new \RuntimeException('Formatter [' . typeOf($formatter) .'] is not accepted.');
172
    }
173
}
174