Test Setup Failed
Branch master (47e707)
by Alec
02:22
created

CounterReportFormatter::process()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 0
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 2
rs 10
c 0
b 0
f 0
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 ReportFormatter
15
{
16
    /** @var CounterReport */
17
    protected $report;
18
19
    /**
20
     * {@inheritdoc}
21
     */
22 3
    public function process(): string
23
    {
24 3
        if (DEFAULT_NAME === $this->report->getName()) {
25 3
            return $this->simple();
26
        }
27 3
        return $this->full();
28
    }
29
30
    /**
31
     * @param bool $eol
32
     * @return string
33
     */
34 3
    public function simple(bool $eol = true): string
35
    {
36
        return
37 3
            sprintf(
38 3
                self::COUNTER . ': %s%s',
39 3
                (string)$this->report->getValue(),
40 3
                $eol ? PHP_EOL : ''
41
            );
42
    }
43
44
    /**
45
     * @param bool $eol
46
     * @return string
47
     */
48 3
    public function full(bool $eol = true): string
49
    {
50
        return
51 3
            sprintf(
52 3
                self::COUNTER . '[%s]: ' .
53 3
                self::VALUE . ': %s, ' .
54 3
                self::STEP . ': %s, ' .
55 3
                self::BUMPED . ': %s, ' .
56 3
                self::PATH . ': %s, ' .
57 3
                self::LENGTH . ': %s, ' .
58 3
                self::MAX . ': %s, ' .
59 3
                self::MIN . ': %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 3
                $this->computeBumped(),
65 3
                (string)$this->report->getPath(),
66 3
                (string)$this->report->getLength(),
67 3
                (string)$this->report->getMax(),
68 3
                (string)$this->report->getMin(),
69 3
                (string)$this->report->getDiff(),
70 3
                $eol ? PHP_EOL : ''
71
            );
72
    }
73
74
    /**
75
     * @return string
76
     */
77 3
    private function computeBumped(): string
78
    {
79 3
        return sprintf(
80 3
            self::FORWARD . '%s ' . self::BACKWARD . '%s',
81 3
            $this->report->getBumpedForward(),
82 3
            $this->report->getBumpedBack()
83
        );
84
    }
85
}
86