1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace AlecRabbit\Tools\Reports\Formatters; |
4
|
|
|
|
5
|
|
|
use AlecRabbit\Tools\Contracts\CounterValuesInterface; |
6
|
|
|
use AlecRabbit\Tools\Reports\Contracts\ReportInterface; |
7
|
|
|
use AlecRabbit\Tools\Reports\ExtendedCounterReport; |
8
|
|
|
use AlecRabbit\Tools\Reports\SimpleCounterReport; |
9
|
|
|
use const AlecRabbit\Traits\Constants\DEFAULT_NAME; |
10
|
|
|
|
11
|
|
|
class ExtendedCounterReportFormatter extends ReportFormatter |
12
|
|
|
{ |
13
|
|
|
/** {@inheritdoc} */ |
14
|
6 |
|
public function process(ReportInterface $report): string |
15
|
|
|
{ |
16
|
6 |
|
if ($report instanceof ExtendedCounterReport) { |
17
|
5 |
|
if (DEFAULT_NAME === $report->getName()) { |
18
|
4 |
|
return $this->simple($report); |
19
|
|
|
} |
20
|
1 |
|
return $this->full($report); |
21
|
|
|
} |
22
|
1 |
|
$this->wrongReportType(ExtendedCounterReport::class, $report); |
23
|
|
|
// @codeCoverageIgnoreStart |
24
|
|
|
return ''; |
25
|
|
|
// @codeCoverageIgnoreEnd |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @param ExtendedCounterReport $report |
30
|
|
|
* @param bool $eol |
31
|
|
|
* @return string |
32
|
|
|
*/ |
33
|
4 |
|
protected function simple(ExtendedCounterReport $report, bool $eol = true): string |
34
|
|
|
{ |
35
|
|
|
/** @var CounterValuesInterface $report */ |
36
|
|
|
return |
37
|
4 |
|
sprintf( |
38
|
4 |
|
self::COUNTER . ': %s%s', |
39
|
4 |
|
(string)$report->getValue(), |
40
|
4 |
|
$eol ? PHP_EOL : '' |
41
|
|
|
); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @param ExtendedCounterReport $report |
46
|
|
|
* @param bool $eol |
47
|
|
|
* @return string |
48
|
|
|
*/ |
49
|
1 |
|
protected function full(ExtendedCounterReport $report, bool $eol = true): string |
50
|
|
|
{ |
51
|
|
|
return |
52
|
1 |
|
sprintf( |
53
|
1 |
|
self::COUNTER . '[%s]: ' . |
54
|
1 |
|
self::VALUE . ': %s, ' . |
55
|
1 |
|
self::STEP . ': %s, ' . |
56
|
1 |
|
self::BUMPED . ': %s, ' . |
57
|
1 |
|
self::PATH . ': %s, ' . |
58
|
1 |
|
self::LENGTH . ': %s, ' . |
59
|
1 |
|
self::MAX . ': %s, ' . |
60
|
1 |
|
self::MIN . ': %s, ' . |
61
|
1 |
|
self::DIFF . ': %s %s', |
62
|
1 |
|
$report->getName(), |
63
|
1 |
|
(string)$report->getValue(), |
64
|
1 |
|
(string)$report->getStep(), |
65
|
1 |
|
$this->computeBumped($report), |
66
|
1 |
|
(string)$report->getPath(), |
67
|
1 |
|
(string)$report->getLength(), |
68
|
1 |
|
(string)$report->getMax(), |
69
|
1 |
|
(string)$report->getMin(), |
70
|
1 |
|
(string)$report->getDiff(), |
71
|
1 |
|
$eol ? PHP_EOL : '' |
72
|
|
|
); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @param ExtendedCounterReport $report |
77
|
|
|
* @return string |
78
|
|
|
*/ |
79
|
1 |
|
private function computeBumped(ExtendedCounterReport $report): string |
80
|
|
|
{ |
81
|
|
|
return |
82
|
1 |
|
sprintf( |
83
|
1 |
|
self::FORWARD . '%s ' . self::BACKWARD . '%s', |
84
|
1 |
|
$report->getBumped(), |
85
|
1 |
|
$report->getBumpedBack() |
86
|
|
|
); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|