Test Failed
Push — master ( 772f18...8c594b )
by Alec
03:05
created

TimerReportFormatter::full()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 23
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 18
nc 2
nop 1
dl 0
loc 23
rs 9.6666
c 0
b 0
f 0
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\Tools\Reports\TimerReport;
12
use function AlecRabbit\format_time_auto;
13
use const AlecRabbit\Constants\Accessories\DEFAULT_NAME;
0 ignored issues
show
Bug introduced by
The constant AlecRabbit\Constants\Accessories\DEFAULT_NAME was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
14
15
class TimerReportFormatter extends Formatter
16
{
17
    /** @var TimerReport */
18
    protected $report;
19
20
    public function setStyles(): void
21
    {
22
    }
23
24
    public function getString(): string
25
    {
26
        if (DEFAULT_NAME === $name = $this->report->getName()) {
27
            return $this->elapsed();
28
        }
29
        return $this->full($name);
30
    }
31
32
    /**
33
     * @return string
34
     * @throws \Throwable
35
     */
36
    public function elapsed(): string
37
    {
38
        return
39
            sprintf(
40
                'Elapsed: %s %s',
41
                $this->theme->comment(format_time_auto($this->report->getElapsed())),
0 ignored issues
show
Bug introduced by
The method comment() does not exist on AlecRabbit\ConsoleColour. It seems like you code against a sub-type of AlecRabbit\ConsoleColour such as AlecRabbit\Tools\Internal\Theme. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

41
                $this->theme->/** @scrutinizer ignore-call */ 
42
                              comment(format_time_auto($this->report->getElapsed())),
Loading history...
42
                PHP_EOL
43
            );
44
    }
45
46
    /**
47
     * @param string $name
48
     * @return string
49
     * @throws \Throwable
50
     */
51
    public function full(string $name): string
52
    {
53
        try {
54
            $str = sprintf(
55
                'Timer:[%s] Average: %s, Last: %s, Min(%s): %s, Max(%s): %s, Count: %s' . PHP_EOL,
56
                $this->theme->info($name),
0 ignored issues
show
Bug introduced by
The method info() does not exist on AlecRabbit\ConsoleColour. It seems like you code against a sub-type of AlecRabbit\ConsoleColour such as AlecRabbit\Tools\Internal\Theme. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

56
                $this->theme->/** @scrutinizer ignore-call */ 
57
                              info($name),
Loading history...
57
                $this->theme->comment(format_time_auto($this->report->getAverageValue())),
58
                format_time_auto($this->report->getLastValue()),
59
                $this->report->getMinValueIteration(),
60
                format_time_auto($this->report->getMinValue()),
61
                $this->report->getMaxValueIteration(),
62
                format_time_auto($this->report->getMaxValue()),
63
                $this->report->getCount()
64
            );
65
        } catch (\Throwable $e) {
66
            $str =
67
                sprintf(
68
                    'Timer:[%s] %s' . PHP_EOL,
69
                    $this->theme->info($name),
70
                    $this->theme->red('Exception encountered')
0 ignored issues
show
Bug introduced by
The method red() does not exist on AlecRabbit\ConsoleColour. It seems like you code against a sub-type of AlecRabbit\ConsoleColour such as AlecRabbit\Tools\Internal\Theme. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

70
                    $this->theme->/** @scrutinizer ignore-call */ 
71
                                  red('Exception encountered')
Loading history...
71
                );
72
        }
73
        return $str;
74
    }
75
}