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) { |
|
|
|
|
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
|
|
|
} |
|
|
|
|
53
|
|
|
} |
54
|
|
|
|