Completed
Push — develop ( f10e50...4f888d )
by Alec
03:20
created

ProfilerReport::__construct()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 4
nop 1
dl 0
loc 7
ccs 5
cts 5
cp 1
crap 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * User: alec
4
 * Date: 01.12.18
5
 * Time: 17:36
6
 */
7
8
namespace AlecRabbit\Tools\Reports;
9
10
use AlecRabbit\Tools\Contracts\StringsInterface;
11
use AlecRabbit\Tools\Profiler;
12
use AlecRabbit\Tools\Reports\Base\Report;
13
14
class ProfilerReport extends Report implements StringsInterface
15
{
16
    /** @var array */
17
    private $reports = [];
18
19
    /**
20
     * @return array
21
     */
22 2
    public function getReports(): array
23
    {
24 2
        return $this->reports;
25
    }
26
27
    /**
28
     * ProfilerReport constructor.
29
     * @param Profiler $reportable
30
     */
31 5
    public function __construct(Profiler $reportable)
32
    {
33 5
        foreach ($reportable->getCounters() as $counter) {
34 5
            $this->reports[static::_COUNTERS][$counter->getName()] = $counter->report();
35
        }
36 5
        foreach ($reportable->getTimers() as $timer) {
37 5
            $this->reports[static::_TIMERS][$timer->getName()] = $timer->report();
38
        }
39 5
    }
40
41
    /**
42
     * @return string
43
     */
44 1
    public function __toString(): string
45
    {
46 1
        $r = '';
47 1
        foreach ($this->reports as $reports) {
48 1
            foreach ($reports as $report) {
49 1
                $r .= $report;
50
            }
51
        }
52 1
        return $r;
53
    }
54
}
55