Completed
Push — develop ( 6b618f...2007a6 )
by Alec
04:06
created

CounterReport   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 66.67%

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 36
ccs 12
cts 18
cp 0.6667
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A __toString() 0 18 2
1
<?php
2
/**
3
 * User: alec
4
 * Date: 29.11.18
5
 * Time: 21:02
6
 */
7
8
namespace AlecRabbit\Tools\Reports;
9
10
use const AlecRabbit\Constants\Accessories\DEFAULT_NAME;
0 ignored issues
show
Bug introduced by
The constant AlecRabbit\Constants\Accessories\DEFAULT_NAME was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
11
use AlecRabbit\Tools\Counter;
12
use AlecRabbit\Tools\Reports\Base\Report;
13
use AlecRabbit\Tools\Traits\CounterFields;
14
15
class CounterReport extends Report
16
{
17
    use CounterFields;
18
19
    /**
20
     * CounterReport constructor.
21
     * @param Counter $counter
22
     */
23 6
    public function __construct(Counter $counter)
24
    {
25 6
        $this->name = $counter->getName();
26 6
        $this->value = $counter->getValue();
27 6
        $this->step = $counter->getStep();
28 6
    }
29
30
    /**
31
     * @return string
32
     */
33 1
    public function __toString(): string
34
    {
35 1
        if (DEFAULT_NAME === $name = $this->getName()) {
36
            return
37 1
                sprintf(
38 1
                    'Counter: %s(%s)%s',
39 1
                    $this->getValue(),
40 1
                    $this->getStep(),
41 1
                    PHP_EOL
42
                );
43
        }
44
        return
45
            sprintf(
46
                'Counter:[%s] Value: %s, Step: %s %s',
47
                $name,
48
                $this->getValue(),
49
                $this->getStep(),
50
                PHP_EOL
51
            );
52
    }
53
}
54