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
|
|
|
|