Test Failed
Push — develop ( f741b1...4c7784 )
by Alec
05:40
created

ProfilerReportFormatter::getString()   B

Complexity

Conditions 8
Paths 6

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 8

Importance

Changes 0
Metric Value
cc 8
eloc 11
nc 6
nop 0
dl 0
loc 16
ccs 6
cts 6
cp 1
crap 8
rs 8.4444
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace AlecRabbit\Tools\Reports\Formatters;
5
6
use AlecRabbit\Tools\Reports\CounterReport;
7
use AlecRabbit\Tools\Reports\ProfilerReport;
8
use AlecRabbit\Tools\Reports\TimerReport;
9
use const AlecRabbit\Traits\Constants\DEFAULT_NAME;
10
11
class ProfilerReportFormatter extends Formatter
12
{
13 7
    /** @var ProfilerReport */
14
    protected $report;
15 7
16
    public function getString(): string
17 3
    {
18
        $r = '';
19 3
        $elapsed = '';
20 3
        foreach ($this->report->getReports() as $reports) {
21 3
            foreach ($reports as $report) {
22 3
                if ($report instanceof TimerReport && DEFAULT_NAME === $report->getName()) {
23
                    $elapsed .= $report;
24
                } elseif ($report instanceof CounterReport && DEFAULT_NAME === $report->getName()) {
25 3
                    $r .= $report->isStarted() ? $report : '';
26
                } else {
27
                    $r .= $report;
28
                }
29
            }
30
        }
31
        return $r . $elapsed;
32
    }
33
}
34