Completed
Push — develop ( eb616e...328010 )
by Alec
03:31
created

SimpleCounterReportFormatter::computeBumped()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 1
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\Formattable;
7
use AlecRabbit\Tools\Reports\SimpleCounterReport;
8
use const AlecRabbit\Traits\Constants\DEFAULT_NAME;
9
10
class SimpleCounterReportFormatter extends ReportFormatter
11
{
12
    /** {@inheritdoc} */
13 6
    public function process(Formattable $formattable): string
14
    {
15 6
        if ($formattable instanceof SimpleCounterReport) {
16 5
            if (DEFAULT_NAME === $formattable->getName()) {
17 4
                return $this->simple($formattable);
18
            }
19 1
            return $this->full($formattable);
20
        }
21 1
        $this->wrongFormattableType(SimpleCounterReport
22
        ::class, $formattable);
23
        // @codeCoverageIgnoreStart
24
        return '';
25
        // @codeCoverageIgnoreEnd
26
    }
27
28
    /**
29
     * @param SimpleCounterReport $report
30
     * @param bool $eol
31
     * @return string
32
     */
33 4
    protected function simple(SimpleCounterReport $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 SimpleCounterReport $report
46
     * @param bool $eol
47
     * @return string
48
     */
49 1
    protected function full(SimpleCounterReport $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%s',
57 1
                $report->getName(),
58 1
                (string)$report->getValue(),
59 1
                (string)$report->getStep(),
60 1
                $this->computeBumped($report),
61 1
                $eol ? PHP_EOL : ''
62
            );
63
    }
64
65
    /**
66
     * @param SimpleCounterReport $report
67
     * @return string
68
     */
69 1
    private function computeBumped(SimpleCounterReport $report): string
70
    {
71
        return
72 1
            sprintf(
73 1
                self::FORWARD . '%s ',
74 1
                $report->getBumped()
75
            );
76
    }
77
}
78