Passed
Push — master ( 8b49d6...8ffc72 )
by Alec
16:03
created

ProfilerReport::extractDataFrom()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 4

Importance

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