Completed
Push — develop ( ca99c7...b953bd )
by Alec
03:03
created

ProfilerReport::buildOn()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 4.0312

Importance

Changes 0
Metric Value
cc 4
eloc 8
nc 2
nop 1
dl 0
loc 13
ccs 7
cts 8
cp 0.875
crap 4.0312
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
    protected static function getFormatter(): FormatterInterface
18
    {
19
        return Factory::getProfilerReportFormatter();
20
    }
21
22
    /**
23
     * @return array
24
     */
25
    public function getReports(): array
26
    {
27
        return $this->reports;
28
    }
29
30 3
    public function buildOn(ReportableInterface $profiler): ReportInterface
31
    {
32 3
        if ($profiler instanceof Profiler) {
33 3
            foreach ($profiler->getCounters() as $counter) {
34 3
                $this->reports[self::COUNTERS][$counter->getName()] = $counter->report();
35
            }
36 3
            foreach ($profiler->getTimers() as $timer) {
37 3
                $this->reports[self::TIMERS][$timer->getName()] = $timer->report();
38
            }
39
        } else {
40
            $this->wrongReportable(Profiler::class, $profiler);
41
        }
42 3
        return $this;
43
    }
44
45
    /**
46
     * @return array
47
     */
48
    public function getCountersReports(): array
49
    {
50
        return $this->reports[self::COUNTERS];
51
    }
52
53
    /**
54
     * @return array
55
     */
56
    public function getTimersReports(): array
57
    {
58
        return $this->reports[self::TIMERS];
59
    }
60
}
61