Lines
83.33%
5 / 6
Functions and Methods
80.00%
4 / 5
Classes and Traits
0.00%
0 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| WorkerExposedNumber | 83.33% | 5 / 6 | 80.00% | 4 / 5 | 7.23 | 0.00% | 0 / 1 | |||
| getConfig | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| updateConfig | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| watchCommands | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | |||||
| getValue | 100.00% | 2 / 2 | 100.00% | 1 / 1 | 3 | |||||
| setValue | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Stewart\Runtime\Worker\Exposure; | |
| 6 | ||
| 7 | use Stewart\Contracts\EventStream; | |
| 8 | use Stewart\Contracts\Exposure\Command\NumberCommand; | |
| 9 | use Stewart\Contracts\Exposure\ExposedNumber; | |
| 10 | use Stewart\Contracts\Exposure\ExposedState; | |
| 11 | use Stewart\Contracts\Exposure\ExposedStateChange; | |
| 12 | use Stewart\Contracts\Exposure\NumberConfig; | |
| 13 | ||
| 14 | /** @extends WorkerExposedEntity<NumberConfig> */ | |
| 15 | final class WorkerExposedNumber extends WorkerExposedEntity implements ExposedNumber | |
| 16 | { | |
| 17 | public function getConfig(): NumberConfig | |
| 18 | { | |
| 19 | return $this->findConfig(); | |
| 20 | } | |
| 21 | ||
| 22 | public function updateConfig(NumberConfig $config): void | |
| 23 | { | |
| 24 | $this->sendReconfiguration($config); | |
| 25 | } | |
| 26 | ||
| 27 | public function watchCommands(): EventStream | |
| 28 | { | |
| 29 | /** @var EventStream<NumberCommand> */ | |
| 30 | return $this->watchOwnCommands(); | |
| 31 | } | |
| 32 | ||
| 33 | public function getValue(): int|float|null | |
| 34 | { | |
| 35 | $value = $this->findStateValue(); | |
| 36 | ||
| 37 | return \is_int($value) || \is_float($value) ? $value : null; | |
| 38 | } | |
| 39 | ||
| 40 | public function setValue(int|float|null $value, ?array $attributes = null): void | |
| 41 | { | |
| 42 | $this->sendChange(new ExposedStateChange(new ExposedState($this->getConfig()->formatState($value)), $attributes)); | |
| 43 | } | |
| 44 | } |