Passed
Push — develop ( 0a2c3f...8e5858 )
by Alec
03:05
created

ProfilerReport::buildOn()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 4

Importance

Changes 0
Metric Value
cc 4
eloc 8
nc 2
nop 1
dl 0
loc 13
ccs 8
cts 8
cp 1
crap 4
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace AlecRabbit\Tools\Reports;
4
5
use AlecRabbit\Tools\Contracts\Strings;
6
use AlecRabbit\Tools\Profiler;
7
use AlecRabbit\Tools\Reports\Contracts\ReportableInterface;
8
use AlecRabbit\Tools\Reports\Contracts\ReportInterface;
9
use AlecRabbit\Tools\Reports\Core\Report;
10
use AlecRabbit\Tools\Reports\Formatters\Contracts\FormatterInterface;
11
12
class ProfilerReport extends Report implements Strings
13
{
14
    /** @var array */
15
    private $reports = [];
16
17 1
    protected static function getFormatter(): FormatterInterface
18
    {
19 1
        return Factory::getProfilerReportFormatter();
20
    }
21
22
    /**
23
     * @return array
24
     */
25
    public function getReports(): array
26
    {
27
        return $this->reports;
28
    }
29
30 9
    public function buildOn(ReportableInterface $profiler): ReportInterface
31
    {
32 9
        if ($profiler instanceof Profiler) {
33 8
            foreach ($profiler->getCounters() as $counter) {
34 8
                $this->reports[self::COUNTERS][$counter->getName()] = $counter->report();
35
            }
36 8
            foreach ($profiler->getTimers() as $timer) {
37 8
                $this->reports[self::TIMERS][$timer->getName()] = $timer->report();
38
            }
39
        } else {
40 1
            $this->wrongReportable(Profiler::class, $profiler);
41
        }
42 8
        return $this;
43
    }
44
45
    /**
46
     * @return array
47
     */
48 1
    public function getCountersReports(): array
49
    {
50 1
        return $this->reports[self::COUNTERS];
51
    }
52
53
    /**
54
     * @return array
55
     */
56 1
    public function getTimersReports(): array
57
    {
58 1
        return $this->reports[self::TIMERS];
59
    }
60
}
61