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

CounterReport::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 1
rs 10
c 0
b 0
f 0
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