Lines
71.42%
5 / 7
Functions and Methods
66.66%
4 / 6
Classes and Traits
0.00%
0 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| WorkerExposedSwitch | 71.42% | 5 / 7 | 66.66% | 4 / 6 | 8.14 | 0.00% | 0 / 1 | |||
| getConfig | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | |||||
| updateConfig | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | |||||
| watchCommands | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| getValue | 100.00% | 2 / 2 | 100.00% | 1 / 1 | 2 | |||||
| setOn | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| setOff | 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\SwitchCommand; | |
| 9 | use Stewart\Contracts\Exposure\ExposedState; | |
| 10 | use Stewart\Contracts\Exposure\ExposedStateChange; | |
| 11 | use Stewart\Contracts\Exposure\ExposedSwitch; | |
| 12 | use Stewart\Contracts\Exposure\SwitchConfig; | |
| 13 | ||
| 14 | /** @extends WorkerExposedEntity<SwitchConfig> */ | |
| 15 | final class WorkerExposedSwitch extends WorkerExposedEntity implements ExposedSwitch | |
| 16 | { | |
| 17 | public function getConfig(): SwitchConfig | |
| 18 | { | |
| 19 | return $this->findConfig(); | |
| 20 | } | |
| 21 | ||
| 22 | public function updateConfig(SwitchConfig $config): void | |
| 23 | { | |
| 24 | $this->sendReconfiguration($config); | |
| 25 | } | |
| 26 | ||
| 27 | public function watchCommands(): EventStream | |
| 28 | { | |
| 29 | /** @var EventStream<SwitchCommand> */ | |
| 30 | return $this->watchOwnCommands(); | |
| 31 | } | |
| 32 | ||
| 33 | public function getValue(): ?bool | |
| 34 | { | |
| 35 | $value = $this->findStateValue(); | |
| 36 | ||
| 37 | return \is_bool($value) ? $value : null; | |
| 38 | } | |
| 39 | ||
| 40 | public function setOn(?array $attributes = null): void | |
| 41 | { | |
| 42 | $this->sendChange(new ExposedStateChange(new ExposedState(true), $attributes)); | |
| 43 | } | |
| 44 | ||
| 45 | public function setOff(?array $attributes = null): void | |
| 46 | { | |
| 47 | $this->sendChange(new ExposedStateChange(new ExposedState(false), $attributes)); | |
| 48 | } | |
| 49 | } |