Passed
Push — develop ( 8e5858...26158a )
by Alec
02:57
created

AbstractCounterReport   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 28
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getFormatter() 0 3 1
A buildOn() 0 13 2
1
<?php declare(strict_types=1);
2
3
namespace AlecRabbit\Tools\Reports;
4
5
use AlecRabbit\Tools\AbstractCounter;
6
use AlecRabbit\Tools\Contracts\CounterInterface;
7
use AlecRabbit\Tools\ExtendedCounter;
8
use AlecRabbit\Tools\Reports\Contracts\ReportableInterface;
9
use AlecRabbit\Tools\Reports\Contracts\ReportInterface;
10
use AlecRabbit\Tools\Reports\Core\Report;
11
use AlecRabbit\Tools\Reports\Formatters\Contracts\FormatterInterface;
12
use AlecRabbit\Tools\SimpleCounter;
13
use AlecRabbit\Tools\Traits\ExtendedCounterFields;
14
use AlecRabbit\Tools\Traits\SimpleCounterFields;
15
use function AlecRabbit\typeOf;
16
17
abstract class AbstractCounterReport extends Report
18
{
19
    use SimpleCounterFields;
20
21 2
    protected static function getFormatter(): FormatterInterface
22
    {
23 2
        return Factory::getSimpleCounterReportFormatter();
24
    }
25
26
    /**
27
     * @param ReportableInterface $counter
28
     * @return ReportInterface
29
     * @throws \RuntimeException
30
     * @throws \Exception
31
     */
32 38
    public function buildOn(ReportableInterface $counter): ReportInterface
33
    {
34 38
        if ($counter instanceof SimpleCounter) {
35 38
            $this->name = $counter->getName();
36 38
            $this->value = $counter->getValue();
37 38
            $this->step = $counter->getStep();
38 38
            $this->started = $counter->isStarted();
39 38
            $this->initialValue = $counter->getInitialValue();
40 38
            $this->bumped = $counter->getBumped();
41
        } else {
42 1
            $this->wrongReportable(SimpleCounter::class, $counter);
43
        }
44 38
        return $this;
45
    }
46
}
47