Passed
Push — master ( e92e62...a2a1ac )
by Alec
09:33
created

ExtendedCounterReportFormatter::full()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 20
nc 1
nop 1
dl 0
loc 22
ccs 12
cts 12
cp 1
crap 1
rs 9.6
c 0
b 0
f 0
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 5
    public function format(Formattable $formattable): string
13
    {
14 5
        if ($formattable instanceof ExtendedCounterReport) {
15 4
            $data = $formattable->getData();
16 4
            if (DEFAULT_NAME === $data['name']) {
17 3
                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