Completed
Push — develop ( b733eb...69cb61 )
by Alec
06:31
created

CounterReportFormatter::getString()   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\Constants\Traits\DEFAULT_NAME;
0 ignored issues
show
Bug introduced by
The constant AlecRabbit\Constants\Traits\DEFAULT_NAME was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
13
14
class CounterReportFormatter extends Formatter
15
{
16
    /** @var CounterReport */
17
    protected $report;
18
19
    /** {@inheritdoc} */
20 9
    public function setStyles(): void
21
    {
22 9
    }
23
24
    /**
25
     * {@inheritdoc}
26
     * @throws \Throwable
27
     */
28 4
    public function getString(): string
29
    {
30 4
        if (DEFAULT_NAME === $name = $this->report->getName()) {
31 3
            return $this->count();
32
        }
33 1
        return $this->full($name);
34
    }
35
36
    /**
37
     * @return string
38
     * @throws \Throwable
39
     */
40 3
    public function count(): string
41
    {
42
        return
43 3
            sprintf(
44 3
                'Counter: %s(%s)%s',
45 3
                $this->theme->comment((string)$this->report->getValue()),
46 3
                $this->theme->dark((string)$this->report->getStep()),
47 3
                PHP_EOL
48
            );
49
    }
50
51
    /**
52
     * @param string $name
53
     * @return string
54
     * @throws \Throwable
55
     */
56 1
    public function full(string $name): string
57
    {
58
        return
59 1
            sprintf(
60 1
                'Counter:[%s] Value: %s, Step: %s %s',
61 1
                $this->theme->info($name),
62 1
                $this->theme->comment((string)$this->report->getValue()),
63 1
                $this->theme->dark((string)$this->report->getStep()),
64 1
                PHP_EOL
65
            );
66
    }
67
}
68