Test Failed
Push — master ( 772f18...8c594b )
by Alec
03:05
created

Factory::setColour()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * User: alec
4
 * Date: 01.12.18
5
 * Time: 17:14
6
 */
7
8
namespace AlecRabbit\Tools\Reports;
9
10
use AlecRabbit\Tools\Benchmark;
11
use AlecRabbit\Tools\Counter;
12
use AlecRabbit\Tools\Internal\Theme;
13
use AlecRabbit\Tools\Profiler;
14
use AlecRabbit\Tools\Reports\Contracts\ReportableInterface;
15
use AlecRabbit\Tools\Reports\Contracts\ReportInterface;
16
use AlecRabbit\Tools\Reports\Formatters\BenchmarkReportFormatter;
17
use AlecRabbit\Tools\Reports\Formatters\Contracts\ReportFormatter;
18
use AlecRabbit\Tools\Reports\Formatters\CounterReportFormatter;
19
use AlecRabbit\Tools\Reports\Formatters\ProfilerReportFormatter;
20
use AlecRabbit\Tools\Reports\Formatters\TimerReportFormatter;
21
use AlecRabbit\Tools\Timer;
22
use function AlecRabbit\typeOf;
23
24
class Factory
25
{
26
    private static $theme;
27
    protected static $colour = false;
28
29
    /**
30
     * @param ReportableInterface $reportable
31
     * @return ReportInterface
32
     */
33
    public static function makeReport(ReportableInterface $reportable): ReportInterface
34
    {
35
        if ($reportable instanceof Timer) {
36
            return
37
                new TimerReport($reportable);
38
        }
39
        if ($reportable instanceof Counter) {
40
            return
41
                new CounterReport($reportable);
42
        }
43
        if ($reportable instanceof Profiler) {
44
            return
45
                new ProfilerReport($reportable);
46
        }
47
        if ($reportable instanceof Benchmark) {
48
            return
49
                new BenchmarkReport($reportable);
50
        }
51
        throw new \RuntimeException('Attempt to create unimplemented report for: ' . typeOf($reportable));
52
    }
53
54
    /**
55
     * @param ReportInterface $report
56
     * @return ReportFormatter
57
     */
58
    public static function makeFormatter(ReportInterface $report): ReportFormatter
59
    {
60
        if ($report instanceof TimerReport) {
61
            return
62
                new TimerReportFormatter($report);
63
        }
64
        if ($report instanceof CounterReport) {
65
            return
66
                new CounterReportFormatter($report);
67
        }
68
        if ($report instanceof ProfilerReport) {
69
            return
70
                new ProfilerReportFormatter($report);
71
        }
72
        if ($report instanceof BenchmarkReport) {
73
            return
74
                new BenchmarkReportFormatter($report);
75
        }
76
        throw new \RuntimeException('Attempt to create unimplemented formatter for: ' . typeOf($report));
77
    }
78
79
    public static function getThemeObject(): Theme
80
    {
81
        if (!static::$theme) {
0 ignored issues
show
Bug introduced by
Since $theme is declared private, accessing it with static will lead to errors in possible sub-classes; you can either use self, or increase the visibility of $theme to at least protected.
Loading history...
82
            static::$theme = new Theme(static::$colour);
83
        }
84
        return static::$theme;
85
    }
86
87
    /**
88
     * @param bool $colour
89
     */
90
    public static function setColour(bool $colour): void
91
    {
92
        self::$colour = $colour;
93
    }
94
95
96
}
97