Completed
Push — master ( 152dcd...9d2605 )
by Alec
05:33 queued 02:40
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 13
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\Reports\Contracts\ReportableInterface;
6
use AlecRabbit\Tools\Reports\Contracts\ReportInterface;
7
use AlecRabbit\Tools\Reports\Core\Report;
8
use AlecRabbit\Tools\Reports\Formatters\Contracts\FormatterInterface;
9
use AlecRabbit\Tools\SimpleCounter;
10
use AlecRabbit\Tools\Traits\SimpleCounterFields;
11
12
abstract class AbstractCounterReport extends Report
13
{
14
    use SimpleCounterFields;
15
16 4
    protected static function getFormatter(): FormatterInterface
17
    {
18 4
        return Factory::getSimpleCounterReportFormatter();
19
    }
20
21
    /**
22
     * @param ReportableInterface $counter
23
     * @return ReportInterface
24
     * @throws \RuntimeException
25
     * @throws \Exception
26
     */
27 43
    public function buildOn(ReportableInterface $counter): ReportInterface
28
    {
29 43
        if ($counter instanceof SimpleCounter) {
30 43
            $this->name = $counter->getName();
31 43
            $this->value = $counter->getValue();
32 43
            $this->step = $counter->getStep();
33 43
            $this->started = $counter->isStarted();
34 43
            $this->initialValue = $counter->getInitialValue();
35 43
            $this->bumped = $counter->getBumped();
36
        } else {
37 1
            $this->wrongReportable(SimpleCounter::class, $counter);
38
        }
39 43
        return $this;
40
    }
41
}
42