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

CounterReportFormatter   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 51
ccs 19
cts 19
cp 1
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A full() 0 9 1
A count() 0 8 1
A setStyles() 0 2 1
A getString() 0 6 2
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