Passed
Push — master ( 6d6f4a...2fcf63 )
by Alec
01:59
created

ExtendedCounterReport::buildOn()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 2.0065

Importance

Changes 0
Metric Value
cc 2
eloc 16
nc 2
nop 1
dl 0
loc 19
ccs 15
cts 17
cp 0.8824
crap 2.0065
rs 9.7333
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace AlecRabbit\Reports;
4
5
use AlecRabbit\Counters\Core\AbstractCounter;
6
use AlecRabbit\Counters\Core\Traits\ExtendedCounterFields;
7
use AlecRabbit\Counters\ExtendedCounter;
8
use AlecRabbit\Formatters\Contracts\CounterReportFormatterInterface;
9
use AlecRabbit\Formatters\SimpleCounterReportFormatter;
10
use AlecRabbit\Reports\Contracts\ReportableInterface;
11
use AlecRabbit\Reports\Contracts\ReportInterface;
12
13
class ExtendedCounterReport extends SimpleCounterReport
14
{
15
    use ExtendedCounterFields;
16
17
    protected static function getFormatter(): CounterReportFormatterInterface
18
    {
19
        if (!static::$reportFormatter instanceof CounterReportFormatterInterface) {
0 ignored issues
show
introduced by
static::reportFormatter is always a sub-type of AlecRabbit\Formatters\Co...eportFormatterInterface.
Loading history...
20
            static::$reportFormatter = new SimpleCounterReportFormatter();
21
        }
22
        return static::$reportFormatter;
23
    }
24
25
    /**
26
     * @param ReportableInterface $counter
27
     * @return ReportInterface
28
     * @throws \RuntimeException
29
     * @throws \Exception
30
     */
31 7
    public function buildOn(ReportableInterface $counter): ReportInterface
32
    {
33 7
        if ($counter instanceof ExtendedCounter) {
34 7
            $this->name = $counter->getName();
35 7
            $this->value = $counter->getValue();
36 7
            $this->step = $counter->getStep();
37 7
            $this->started = $counter->isStarted();
38 7
            $this->initialValue = $counter->getInitialValue();
39 7
            $this->bumped = $counter->getBumped();
40 7
            $this->max = $counter->getMax();
41 7
            $this->min = $counter->getMin();
42 7
            $this->path = $counter->getPath();
43 7
            $this->length = $counter->getLength();
44 7
            $this->diff = $counter->getDiff();
45 7
            $this->bumpedBack = $counter->getBumpedBack();
46 7
            return $this;
47
        }
48
        throw new \InvalidArgumentException(
49
            AbstractCounter::class . ' expected, ' . get_class($counter) . ' given.'
50
        );
51
52
    }
0 ignored issues
show
Coding Style introduced by
Function closing brace must go on the next line following the body; found 1 blank lines before brace
Loading history...
53
}
54