Completed
Push — master ( f9a123...73c14a )
by Alec
18:36
created

ProfilerReport::extractDataFrom()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 4

Importance

Changes 0
Metric Value
eloc 5
c 0
b 0
f 0
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 10
cc 4
nc 5
nop 1
crap 4
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 2
    public function getReports(): array
19
    {
20 2
        return $this->reports;
21
    }
22
23
    /** {@inheritDoc}
24
     * @throws \Exception
25
     */
26 1
    protected function extractDataFrom(AbstractReportable $reportable = null): void
27
    {
28 1
        if ($reportable instanceof Profiler) {
29
            foreach ($reportable->getCounters() as $counter) {
30
                $this->reports[self::COUNTERS][$counter->getName()] = $counter->report();
31 11
            }
32
            foreach ($reportable->getTimers() as $timer) {
33 11
                $this->reports[self::TIMERS][$timer->getName()] = $timer->report();
34 10
            }
35 10
        }
36
    }
37 10
38 10
//    public function buildOn(ReportableInterface $profiler): ReportInterface
39
//    {
40
//        if ($profiler instanceof Profiler) {
41 1
//            foreach ($profiler->getCounters() as $counter) {
42
//                $this->reports[self::COUNTERS][$counter->getName()] = $counter->report();
43 10
//            }
44
//            foreach ($profiler->getTimers() as $timer) {
45
//                $this->reports[self::TIMERS][$timer->getName()] = $timer->report();
46
//            }
47
//        } else {
48
//            $this->wrongReportable(Profiler::class, $profiler);
49 3
//        }
50
//        return $this;
51 3
//    }
52
//
53
    /**
54
     * @return array
55
     */
56
    public function getCountersReports(): array
57 3
    {
58
        return $this->reports[self::COUNTERS];
59 3
    }
60
61
    /**
62
     * @return array
63
     */
64
    public function getTimersReports(): array
65
    {
66
        return $this->reports[self::TIMERS];
67
    }
68
}
69