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\SimpleCounterReport; |
8
|
|
|
use const AlecRabbit\Traits\Constants\DEFAULT_NAME; |
9
|
|
|
|
10
|
|
|
class SimpleCounterReportFormatter extends ReportFormatter |
11
|
|
|
{ |
12
|
|
|
/** {@inheritdoc} */ |
13
|
1 |
|
public function process(ReportInterface $report): string |
14
|
|
|
{ |
15
|
1 |
|
if ($report instanceof SimpleCounterReport) { |
16
|
1 |
|
if (DEFAULT_NAME === $report->getName()) { |
17
|
1 |
|
return $this->simple($report); |
18
|
|
|
} |
19
|
|
|
return $this->full($report); |
20
|
|
|
} |
21
|
|
|
return ''; |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @param SimpleCounterReport $report |
26
|
|
|
* @param bool $eol |
27
|
|
|
* @return string |
28
|
|
|
*/ |
29
|
1 |
|
protected function simple(SimpleCounterReport $report, bool $eol = true): string |
30
|
|
|
{ |
31
|
|
|
/** @var CounterValuesInterface $report */ |
32
|
|
|
return |
33
|
1 |
|
sprintf( |
34
|
1 |
|
self::COUNTER . ': %s%s', |
35
|
1 |
|
(string)$report->getValue(), |
36
|
1 |
|
$eol ? PHP_EOL : '' |
37
|
|
|
); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param SimpleCounterReport $report |
42
|
|
|
* @param bool $eol |
43
|
|
|
* @return string |
44
|
|
|
*/ |
45
|
|
|
protected function full(SimpleCounterReport $report, bool $eol = true): string |
46
|
|
|
{ |
47
|
|
|
return |
48
|
|
|
sprintf( |
49
|
|
|
self::COUNTER . '[%s]: ' . |
50
|
|
|
self::VALUE . ': %s, ' . |
51
|
|
|
self::STEP . ': %s, ' . |
52
|
|
|
self::BUMPED . ': %s, ' . |
53
|
|
|
$report->getName(), |
54
|
|
|
(string)$report->getValue(), |
55
|
|
|
(string)$report->getStep(), |
56
|
|
|
$this->computeBumped($report), |
57
|
|
|
$eol ? PHP_EOL : '' |
58
|
|
|
); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @param SimpleCounterReport $report |
63
|
|
|
* @return string |
64
|
|
|
*/ |
65
|
|
|
private function computeBumped(SimpleCounterReport $report): string |
66
|
|
|
{ |
67
|
|
|
return |
68
|
|
|
sprintf( |
69
|
|
|
self::FORWARD . '%s ', |
70
|
|
|
$report->getBumped() |
71
|
|
|
); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|