Passed
Push — develop ( 0a2c3f...8e5858 )
by Alec
03:05
created

SimpleCounterReportFormatter::computeBumped()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 6
ccs 0
cts 4
cp 0
crap 2
rs 10
c 0
b 0
f 0
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