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\CounterReport; |
12
|
|
|
use const AlecRabbit\Traits\Constants\DEFAULT_NAME; |
13
|
|
|
|
14
|
|
|
class CounterReportFormatter extends Formatter |
15
|
|
|
{ |
16
|
|
|
/** @var CounterReport */ |
17
|
|
|
protected $report; |
18
|
|
|
|
19
|
|
|
/** |
20
|
9 |
|
* {@inheritdoc} |
21
|
|
|
* @throws \Throwable |
22
|
9 |
|
*/ |
23
|
|
|
public function getString(): string |
24
|
|
|
{ |
25
|
|
|
if (DEFAULT_NAME === $this->report->getName()) { |
26
|
|
|
return $this->simple(); |
27
|
|
|
} |
28
|
4 |
|
return $this->full(); |
29
|
|
|
} |
30
|
4 |
|
|
31
|
3 |
|
/** |
32
|
|
|
* @param bool $eol |
33
|
3 |
|
* @return string |
34
|
|
|
*/ |
35
|
|
|
public function simple(bool $eol = true): string |
36
|
|
|
{ |
37
|
|
|
return |
38
|
|
|
sprintf( |
39
|
|
|
self::COUNTER . ': %s%s', |
40
|
3 |
|
(string)$this->report->getValue(), |
41
|
|
|
$eol ? PHP_EOL : '' |
42
|
|
|
); |
43
|
3 |
|
} |
44
|
3 |
|
|
45
|
3 |
|
/** |
46
|
3 |
|
* @param bool $eol |
47
|
3 |
|
* @return string |
48
|
|
|
*/ |
49
|
|
|
public function full(bool $eol = true): string |
50
|
|
|
{ |
51
|
|
|
$bumped = $this->computeBumped(); |
|
|
|
|
52
|
|
|
return |
53
|
|
|
sprintf( |
54
|
|
|
self::COUNTER . '[%s]: ' . |
55
|
3 |
|
self::VALUE . ': %s, ' . |
56
|
|
|
self::STEP . ': %s, ' . |
57
|
|
|
self::BUMPED . ': %s, ' . |
58
|
3 |
|
self::PATH . ': %s, ' . |
59
|
3 |
|
self::LENGTH . ': %s, ' . |
60
|
3 |
|
self::DIFF . ': %s %s', |
61
|
3 |
|
$this->report->getName(), |
62
|
3 |
|
(string)$this->report->getValue(), |
63
|
3 |
|
(string)$this->report->getStep(), |
64
|
|
|
$this->computeBumped(), |
65
|
|
|
(string)$this->report->getPath(), |
66
|
|
|
(string)$this->report->getLength(), |
67
|
|
|
(string)$this->report->getDiff(), |
68
|
|
|
$eol ? PHP_EOL : '' |
69
|
|
|
); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @return string |
74
|
|
|
*/ |
75
|
|
|
private function computeBumped(): string |
76
|
|
|
{ |
77
|
|
|
return sprintf( |
78
|
|
|
self::FORWARD . '%s ' . self::BACKWARD . '%s', |
79
|
|
|
$this->report->getBumpedForward(), |
80
|
|
|
$this->report->getBumpedBack() |
81
|
|
|
); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|