Passed
Push — master ( 42ec06...5ff168 )
by Alec
09:14
created

TimerReport::extractDataFrom()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 13
nc 3
nop 1
dl 0
loc 15
ccs 14
cts 14
cp 1
crap 3
rs 9.8333
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace AlecRabbit\Reports;
4
5
use AlecRabbit\Reports\Contracts\TimerReportInterface;
6
use AlecRabbit\Reports\Core\AbstractReport;
7
use AlecRabbit\Reports\Core\AbstractReportable;
8
use AlecRabbit\Timers\Core\AbstractTimer;
9
use AlecRabbit\Timers\Core\Traits\TimerFields;
10
11
/**
12
 * Class TimerReport
13
 * @psalm-suppress MissingConstructor
14
 * @psalm-suppress PropertyNotSetInConstructor
15
 */
16
class TimerReport extends AbstractReport implements TimerReportInterface
17
{
18
    use TimerFields;
19
20
    /** {@inheritDoc}
21
     * @throws \Exception
22
     */
23 10
    protected function extractDataFrom(AbstractReportable $reportable = null): void
24
    {
25 10
        if ($reportable instanceof AbstractTimer) {
26 10
            $this->name = $reportable->getName();
27 10
            $this->creationTime = $reportable->getCreation();
28 10
            $this->count = $count = $reportable->getCount();
29 10
            $this->minValue = ($count === 1) ? $reportable->getLastValue() : $reportable->getMinValue();
30 10
            $this->maxValue = $reportable->getMaxValue();
31 10
            $this->maxValueIteration = $reportable->getMaxValueIteration();
32 10
            $this->minValueIteration = $reportable->getMinValueIteration();
33 10
            $this->started = $reportable->isStarted();
34 10
            $this->stopped = $reportable->isStopped();
35 10
            $this->avgValue = $reportable->getAverageValue();
36 10
            $this->currentValue = $reportable->getLastValue();
37 10
            $this->elapsed = $reportable->getElapsed();
38
        }
39 10
    }
40
}
41