Test Setup Failed
Branch master (47e707)
by Alec
02:22
created

ProfilerReportFormatter::timersStrings()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 4

Importance

Changes 0
Metric Value
cc 4
eloc 7
nc 3
nop 0
dl 0
loc 11
ccs 7
cts 7
cp 1
crap 4
rs 10
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 ReportFormatter
12
{
13
    /** @var ProfilerReport */
14
    protected $report;
15
16
    /** @var string */
17
    protected $elapsed = '';
18
19 1
    public function process(): string
20
    {
21
        return
22 1
            sprintf(
23 1
                '%s %s %s ',
24 1
                $this->countersStrings(),
25 1
                $this->timersStrings(),
26 1
                $this->elapsed
27
            );
28
    }
29
30
    /**
31
     * @return string
32
     */
33 1
    protected function countersStrings(): string
34
    {
35 1
        $r = '';
36 1
        foreach ($this->report->getCountersReports() as $report) {
37 1
            if ($report instanceof CounterReport && DEFAULT_NAME === $report->getName()) {
38 1
                $r .= $report->isStarted() ? $report : '';
39
            } else {
40 1
                $r .= $report;
41
            }
42
        }
43 1
        return $r;
44
    }
45
46
    /**
47
     * @return string
48
     */
49 1
    protected function timersStrings(): string
50
    {
51 1
        $r = '';
52 1
        foreach ($this->report->getTimersReports() as $report) {
53 1
            if ($report instanceof TimerReport && DEFAULT_NAME === $report->getName()) {
54 1
                $this->elapsed = (string)$report;
55
            } else {
56 1
                $r .= $report;
57
            }
58
        }
59 1
        return $r;
60
    }
61
}
62