Lines
50.00%
3 / 6
Functions and Methods
40.00%
2 / 5
Classes and Traits
0.00%
0 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| WorkerExposedDate | 50.00% | 3 / 6 | 40.00% | 2 / 5 | 13.12 | 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 | 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 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Stewart\Runtime\Worker\Exposure; | |
| 6 | ||
| 7 | use DateTimeImmutable; | |
| 8 | use DateTimeInterface; | |
| 9 | use Stewart\Contracts\EventStream; | |
| 10 | use Stewart\Contracts\Exposure\CalendarStateFormat; | |
| 11 | use Stewart\Contracts\Exposure\Command\DateCommand; | |
| 12 | use Stewart\Contracts\Exposure\DateConfig; | |
| 13 | use Stewart\Contracts\Exposure\ExposedDate; | |
| 14 | use Stewart\Contracts\Exposure\ExposedState; | |
| 15 | use Stewart\Contracts\Exposure\ExposedStateChange; | |
| 16 | ||
| 17 | /** @extends WorkerExposedEntity<DateConfig> */ | |
| 18 | final class WorkerExposedDate extends WorkerExposedEntity implements ExposedDate | |
| 19 | { | |
| 20 | public function getConfig(): DateConfig | |
| 21 | { | |
| 22 | return $this->findConfig(); | |
| 23 | } | |
| 24 | ||
| 25 | public function updateConfig(DateConfig $config): void | |
| 26 | { | |
| 27 | $this->sendReconfiguration($config); | |
| 28 | } | |
| 29 | ||
| 30 | public function watchCommands(): EventStream | |
| 31 | { | |
| 32 | /** @var EventStream<DateCommand> */ | |
| 33 | return $this->watchOwnCommands(); | |
| 34 | } | |
| 35 | ||
| 36 | public function getValue(): ?DateTimeImmutable | |
| 37 | { | |
| 38 | $value = $this->findStateValue(); | |
| 39 | ||
| 40 | return \is_string($value) ? CalendarStateFormat::parseDate($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::formatDate($value)), $attributes)); | |
| 46 | } | |
| 47 | } |