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

TimerReportFormatter   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Test Coverage

Coverage 77.78%

Importance

Changes 0
Metric Value
eloc 30
dl 0
loc 60
ccs 21
cts 27
cp 0.7778
rs 10
c 0
b 0
f 0
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A simple() 0 7 2
A full() 0 21 2
A ftime() 0 3 1
A getString() 0 6 2
1
<?php
2
/**
3
 * User: alec
4
 * Date: 10.12.18
5
 * Time: 14:22
6
 */
7
declare(strict_types=1);
8
9
namespace AlecRabbit\Tools\Reports\Formatters;
10
11
use AlecRabbit\Pretty;
12
use AlecRabbit\Tools\Reports\TimerReport;
13
use const AlecRabbit\Traits\Constants\DEFAULT_NAME;
14
15
class TimerReportFormatter extends Formatter
16
{
17
    /** @var TimerReport */
18
    protected $report;
19
20
    /**
21 11
     * @return string
22
     */
23 11
    public function getString(): string
24
    {
25
        if (DEFAULT_NAME === $this->report->getName()) {
26
            return $this->simple();
27
        }
28
        return $this->full();
29 4
    }
30
31 4
    /**
32 3
     * @param bool $eol
33
     * @return string
34 1
     */
35
    public function simple(bool $eol = true): string
36
    {
37
        return
38
            sprintf(
39
                self::ELAPSED . ': %s %s',
40
                $this->ftime($this->report->getElapsed()),
41 3
                $eol ? PHP_EOL : ''
42
            );
43
    }
44 3
45 3
    protected function ftime(float $seconds): string
46 3
    {
47 3
        return Pretty::seconds($seconds);
48
    }
49
50
    /**
51
     * @param bool $eol
52
     * @return string
53
     */
54
    public function full(bool $eol = true): string
55 1
    {
56
        $r = $this->report;
57 1
        return sprintf(
58
            self::TIMER . '[%s]: ' .
59 1
            self::AVERAGE . ': %s, ' .
60 1
            self::LAST . ': %s, ' .
61 1
            self::MIN . '(%s): %s, ' .
62 1
            self::MAX . '(%s): %s, ' .
63
            self::COUNT . ': %s, ' .
64
            self::ELAPSED . ': %s%s',
65
            $r->getName(),
66
            $this->ftime($r->getAverageValue()),
67
            $this->ftime($r->getLastValue()),
68
            $r->getMinValueIteration(),
69
            $this->ftime($r->getMinValue()),
70 1
            $r->getMaxValueIteration(),
71
            $this->ftime($r->getMaxValue()),
72 1
            $r->getCount(),
73 1
            $this->ftime($r->getElapsed()),
74 1
            $eol ? PHP_EOL : ''
75 1
        );
76
    }
77
}
78