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

ProfilerReport   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 1 Features 0
Metric Value
wmc 7
eloc 10
c 4
b 1
f 0
dl 0
loc 57
ccs 16
cts 16
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A extractDataFrom() 0 8 4
A getReports() 0 3 1
A getCountersReports() 0 3 1
A getTimersReports() 0 3 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 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