Lines
87.50%
7 / 8
Functions and Methods
85.71%
6 / 7
Classes and Traits
0.00%
0 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| RecordingExposedNumber | 87.50% | 7 / 8 | 85.71% | 6 / 7 | 9.16 | 0.00% | 0 / 1 | |||
| getConfig | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| updateConfig | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| getValue | 100.00% | 2 / 2 | 100.00% | 1 / 1 | 3 | |||||
| setValue | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | |||||
| watchCommands | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| pushCommand | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| pushValue | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Stewart\Testing\Exposure; | |
| 6 | ||
| 7 | use Stewart\Contracts\EventStream; | |
| 8 | use Stewart\Contracts\Exception\CommandException; | |
| 9 | use Stewart\Contracts\Exposure\Command\NumberCommand; | |
| 10 | use Stewart\Contracts\Exposure\ExposedNumber; | |
| 11 | use Stewart\Contracts\Exposure\ExposedState; | |
| 12 | use Stewart\Contracts\Exposure\ExposedStateChange; | |
| 13 | use Stewart\Contracts\Exposure\NumberConfig; | |
| 14 | use Stewart\Contracts\State\EventContext; | |
| 15 | ||
| 16 | /** @extends RecordingExposedEntity<NumberConfig> */ | |
| 17 | final class RecordingExposedNumber extends RecordingExposedEntity implements ExposedNumber | |
| 18 | { | |
| 19 | public function getConfig(): NumberConfig | |
| 20 | { | |
| 21 | return $this->config; | |
| 22 | } | |
| 23 | ||
| 24 | public function updateConfig(NumberConfig $config): void | |
| 25 | { | |
| 26 | $this->recordConfig($config); | |
| 27 | } | |
| 28 | ||
| 29 | public function getValue(): int|float|null | |
| 30 | { | |
| 31 | $value = $this->findStateValue(); | |
| 32 | ||
| 33 | return \is_int($value) || \is_float($value) ? $value : null; | |
| 34 | } | |
| 35 | ||
| 36 | public function setValue(int|float|null $value, ?array $attributes = null): void | |
| 37 | { | |
| 38 | $this->recordChange(new ExposedStateChange(new ExposedState($this->config->formatState($value)), $attributes)); | |
| 39 | } | |
| 40 | ||
| 41 | public function watchCommands(): EventStream | |
| 42 | { | |
| 43 | /** @var EventStream<NumberCommand> */ | |
| 44 | return $this->watchPushedCommands(); | |
| 45 | } | |
| 46 | ||
| 47 | /** @throws CommandException */ | |
| 48 | public function pushCommand(NumberCommand $command): void | |
| 49 | { | |
| 50 | $this->deliverCommand($command); | |
| 51 | } | |
| 52 | ||
| 53 | /** @throws CommandException */ | |
| 54 | public function pushValue(int|float $value, ?EventContext $context = null): void | |
| 55 | { | |
| 56 | $this->pushCommand(new NumberCommand($value, $context ?? EventContext::unknown())); | |
| 57 | } | |
| 58 | } |