Completed
Push — master ( 6a7da5...1827cf )
by Alec
08:13 queued 02:32
created

CounterReportFormatter::setStyles()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 0
dl 0
loc 2
ccs 1
cts 1
cp 1
crap 1
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 Formatter
15
{
16
    /** @var CounterReport */
17
    protected $report;
18
19
    /**
20
     * {@inheritdoc}
21
     */
22 5
    public function getString(): string
23
    {
24 5
        if (DEFAULT_NAME === $this->report->getName()) {
25 3
            return $this->simple();
26
        }
27 5
        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 5
    public function full(bool $eol = true): string
49
    {
50
        return
51 5
            sprintf(
52 5
                self::COUNTER . '[%s]: ' .
53 5
                self::VALUE . ': %s, ' .
54 5
                self::STEP . ': %s, ' .
55 5
                self::BUMPED . ': %s, ' .
56 5
                self::PATH . ': %s, ' .
57 5
                self::LENGTH . ': %s, ' .
58 5
                self::MAX . ': %s, ' .
59 5
                self::MIN . ': %s, ' .
60 5
                self::DIFF . ': %s %s',
61 5
                $this->report->getName(),
62 5
                (string)$this->report->getValue(),
63 5
                (string)$this->report->getStep(),
64 5
                $this->computeBumped(),
65 5
                (string)$this->report->getPath(),
66 5
                (string)$this->report->getLength(),
67 5
                (string)$this->report->getMax(),
68 5
                (string)$this->report->getMin(),
69 5
                (string)$this->report->getDiff(),
70 5
                $eol ? PHP_EOL : ''
71
            );
72
    }
73
74
    /**
75
     * @return string
76
     */
77 5
    private function computeBumped(): string
78
    {
79 5
        return sprintf(
80 5
            self::FORWARD . '%s ' . self::BACKWARD . '%s',
81 5
            $this->report->getBumpedForward(),
82 5
            $this->report->getBumpedBack()
83
        );
84
    }
85
}
86