1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace AlecRabbit\Formatters; |
4
|
|
|
|
5
|
|
|
use AlecRabbit\Formatters\Contracts\CounterStrings; |
6
|
|
|
use AlecRabbit\Reports\Core\Formattable; |
7
|
|
|
use AlecRabbit\Reports\ExtendedCounterReport; |
8
|
|
|
use const AlecRabbit\Traits\Constants\DEFAULT_NAME; |
9
|
|
|
|
10
|
|
|
class ExtendedCounterReportFormatter extends SimpleCounterReportFormatter |
11
|
|
|
{ |
12
|
4 |
|
public function format(Formattable $formattable): string |
13
|
|
|
{ |
14
|
4 |
|
if ($formattable instanceof ExtendedCounterReport) { |
15
|
3 |
|
$data = $formattable->getData(); |
16
|
3 |
|
if (DEFAULT_NAME === $data['name']) { |
17
|
2 |
|
return $this->simple($data); |
18
|
|
|
} |
19
|
1 |
|
return $this->full($data); |
20
|
|
|
} |
21
|
|
|
return |
22
|
1 |
|
$this->errorMessage($formattable, ExtendedCounterReport::class); |
23
|
|
|
} |
24
|
|
|
|
25
|
1 |
|
protected function full(array $data): string |
26
|
|
|
{ |
27
|
|
|
return |
28
|
1 |
|
sprintf( |
29
|
|
|
CounterStrings::COUNTER . '[%s]: ' . |
30
|
|
|
CounterStrings::VALUE . ': %s, ' . |
31
|
|
|
CounterStrings::STEP . ': %s, ' . |
32
|
|
|
CounterStrings::BUMPED . ': %s, ' . |
33
|
|
|
CounterStrings::PATH . ': %s, ' . |
34
|
|
|
CounterStrings::LENGTH . ': %s, ' . |
35
|
|
|
CounterStrings::MAX . ': %s, ' . |
36
|
|
|
CounterStrings::MIN . ': %s, ' . |
37
|
1 |
|
CounterStrings::DIFF . ': %s', |
38
|
1 |
|
$data['name'], |
39
|
1 |
|
(string)$data['value'], |
40
|
1 |
|
(string)$data['step'], |
41
|
1 |
|
$this->computeBumped($data), |
42
|
1 |
|
(string)$data['path'], |
43
|
1 |
|
(string)$data['length'], |
44
|
1 |
|
(string)$data['max'], |
45
|
1 |
|
(string)$data['min'], |
46
|
1 |
|
(string)$data['diff'] |
47
|
|
|
); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param array $data |
52
|
|
|
* @return string |
53
|
|
|
*/ |
54
|
1 |
|
protected function computeBumped(array $data): string |
55
|
|
|
{ |
56
|
|
|
return |
57
|
1 |
|
sprintf( |
58
|
1 |
|
CounterStrings::FORWARD . '%s ' . CounterStrings::BACKWARD . '%s ', |
59
|
1 |
|
$data['bumped'], |
60
|
1 |
|
$data['bumpedBack'] |
61
|
|
|
); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|