Lines
87.50%
35 / 40
Methods
79.16%
19 / 24
Classes
0.00%
0 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| getConfig | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | ||
| updateConfig | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | ||
| watchCommands | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | ||
| getValue | 100.00% | 2 / 2 | 100.00% | 1 / 1 | 2 | ||
| setValue | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 2 | ||
| [Stewart\Runtime\Worker\Exposure\WorkerExposedEntity] getEntityId | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| [Stewart\Runtime\Worker\Exposure\WorkerExposedEntity] getAttributes | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| [Stewart\Runtime\Worker\Exposure\WorkerExposedEntity] isAvailable | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| [Stewart\Runtime\Worker\Exposure\WorkerExposedEntity] setAttributes | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | ||
| [Stewart\Runtime\Worker\Exposure\WorkerExposedEntity] markAvailable | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | ||
| [Stewart\Runtime\Worker\Exposure\WorkerExposedEntity] markUnavailable | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| [Stewart\Runtime\Worker\Exposure\WorkerExposedEntity] applySnapshot | 100.00% | 4 / 4 | 100.00% | 1 / 1 | 1 | ||
| [Stewart\Runtime\Worker\Exposure\WorkerExposedEntity] recordCommandedState | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| [Stewart\Runtime\Worker\Exposure\WorkerExposedEntity] sendChange | 100.00% | 4 / 4 | 100.00% | 1 / 1 | 1 | ||
| [Stewart\Runtime\Worker\Exposure\WorkerExposedEntity] findStateValue | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| [Stewart\Runtime\Worker\Exposure\WorkerExposure] __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| [Stewart\Runtime\Worker\Exposure\WorkerExposure] getKey | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| [Stewart\Runtime\Worker\Exposure\WorkerExposure] remove | 100.00% | 4 / 4 | 100.00% | 1 / 1 | 1 | ||
| [Stewart\Runtime\Worker\Exposure\WorkerExposure] markReleased | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| [Stewart\Runtime\Worker\Exposure\WorkerExposure] findConfig | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| [Stewart\Runtime\Worker\Exposure\WorkerExposure] watchOwnCommands | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| [Stewart\Runtime\Worker\Exposure\WorkerExposure] sendReconfiguration | 100.00% | 5 / 5 | 100.00% | 1 / 1 | 2 | ||
| [Stewart\Runtime\Worker\Exposure\WorkerExposure] sendUpdate | 100.00% | 2 / 2 | 100.00% | 1 / 1 | 1 | ||
| [Stewart\Runtime\Worker\Exposure\WorkerExposure] assertNotReleased | 100.00% | 2 / 2 | 100.00% | 1 / 1 | 2 | ||
| 18 | final class WorkerExposedDateTime extends WorkerExposedEntity implements ExposedDateTime | |
| 19 | { | |
| 20 | public function getConfig(): DateTimeConfig | |
| 21 | { | |
| 22 | return $this->findConfig(); | |
| 23 | } | |
| 24 | ||
| 25 | public function updateConfig(DateTimeConfig $config): void | |
| 26 | { | |
| 27 | $this->sendReconfiguration($config); | |
| 28 | } | |
| 29 | ||
| 30 | public function watchCommands(): EventStream | |
| 31 | { | |
| 32 | /** @var EventStream<DateTimeCommand> */ | |
| 33 | return $this->watchOwnCommands(); | |
| 34 | } | |
| 35 | ||
| 36 | public function getValue(): ?DateTimeImmutable | |
| 37 | { | |
| 38 | $value = $this->findStateValue(); | |
| 39 | ||
| 40 | return \is_string($value) ? CalendarStateFormat::parseDateTime($value) : null; | |
| 41 | } | |
| 42 | ||
| 43 | public function setValue(?DateTimeInterface $value, ?array $attributes = null): void | |
| 44 | { | |
| 45 | $this->sendChange(new ExposedStateChange(new ExposedState($value === null ? null : CalendarStateFormat::formatDateTime($value)), $attributes)); | |
| 46 | } | |
| 47 | } |
Inherited from Stewart\Runtime\Worker\Exposure\WorkerExposedEntity
| 32 | public function getEntityId(): ?EntityId | |
| 33 | { | |
| 34 | return $this->entityId; | |
| 35 | } |
| 37 | public function getAttributes(): array | |
| 38 | { | |
| 39 | return $this->attributes; | |
| 40 | } |
| 42 | public function isAvailable(): bool | |
| 43 | { | |
| 44 | return $this->available; | |
| 45 | } |
| 47 | public function setAttributes(array $attributes): void | |
| 48 | { | |
| 49 | $this->sendChange(new ExposedStateChange(attributes: $attributes)); | |
| 50 | } |
| 52 | public function markAvailable(): void | |
| 53 | { | |
| 54 | $this->sendChange(new ExposedStateChange(available: true)); | |
| 55 | } |
| 57 | public function markUnavailable(): void | |
| 58 | { | |
| 59 | $this->sendChange(new ExposedStateChange(available: false)); | |
| 60 | } |
| 62 | public function applySnapshot(ExposedEntitySnapshot $snapshot): void | |
| 63 | { | |
| 64 | $this->entityId = $snapshot->entityId; | |
| 65 | $this->state = $snapshot->state; | |
| 66 | $this->attributes = $snapshot->attributes; | |
| 67 | $this->available = $snapshot->available; | |
| 68 | } |
| 70 | public function recordCommandedState(ExposedState $state): void | |
| 71 | { | |
| 72 | $this->state = $state; | |
| 73 | } |
| 76 | protected function sendChange(ExposedStateChange $change): void | |
| 77 | { | |
| 78 | $this->sendUpdate($change); | |
| 79 | ||
| 80 | $this->state = $change->state ?? $this->state; | |
| 81 | $this->attributes = $change->attributes ?? $this->attributes; | |
| 82 | $this->available = $change->available ?? $this->available; | |
| 83 | } |
| 85 | protected function findStateValue(): int|float|string|bool|null | |
| 86 | { | |
| 87 | return $this->state?->value; | |
| 88 | } |
Inherited from Stewart\Runtime\Worker\Exposure\WorkerExposure
| 21 | public function __construct( | |
| 22 | private readonly ExposureChannel $channel, | |
| 23 | private readonly ResourceScope $scope, | |
| 24 | private readonly ExposedEntityKey $key, | |
| 25 | private ExposureConfig $config, | |
| 26 | ) {} |
| 28 | public function getKey(): ExposedEntityKey | |
| 29 | { | |
| 30 | return $this->key; | |
| 31 | } |
| 33 | public function remove(): void | |
| 34 | { | |
| 35 | $this->assertNotReleased(); | |
| 36 | $this->channel->requester->requestRemoval($this->scope, $this->key); | |
| 37 | $this->channel->handles->forgetHandle($this->scope, $this->key); | |
| 38 | $this->released = true; | |
| 39 | } |
| 41 | public function markReleased(): void | |
| 42 | { | |
| 43 | $this->released = true; | |
| 44 | } |
| 47 | protected function findConfig(): ExposureConfig | |
| 48 | { | |
| 49 | return $this->config; | |
| 50 | } |
| 53 | protected function watchOwnCommands(): EventStream | |
| 54 | { | |
| 55 | return $this->channel->commandStreams->watchCommands($this->scope, $this->key); | |
| 56 | } |
| 62 | protected function sendReconfiguration(ExposureConfig $config): void | |
| 63 | { | |
| 64 | $this->assertNotReleased(); | |
| 65 | $snapshot = $this->channel->requester->requestReconfiguration($this->scope, $this->key, $config); | |
| 66 | $this->config = $config; | |
| 67 | ||
| 68 | if ($snapshot !== null) { | |
| 69 | $this->applySnapshot($snapshot); | |
| 70 | } | |
| 71 | } |
| 74 | protected function sendUpdate(ExposedStateChange $change): void | |
| 75 | { | |
| 76 | $this->assertNotReleased(); | |
| 77 | $this->channel->requester->requestUpdate($this->scope, $this->key, $change); | |
| 78 | } |
| 81 | private function assertNotReleased(): void | |
| 82 | { | |
| 83 | if ($this->released) { | |
| 84 | throw ExposureException::removed($this->key); | |
| 85 | } | |
| 86 | } |