Lines
42.85%
3 / 7
Functions and Methods
33.33%
2 / 6
Classes and Traits
0.00%
0 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| RecordingExposedDateTime | 42.85% | 3 / 7 | 33.33% | 2 / 6 | 19.94 | 0.00% | 0 / 1 | |||
| getConfig | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | |||||
| updateConfig | 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 | |||||
| watchCommands | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | |||||
| pushCommand | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Stewart\Testing\Exposure; | |
| 6 | ||
| 7 | use DateTimeImmutable; | |
| 8 | use DateTimeInterface; | |
| 9 | use Stewart\Contracts\EventStream; | |
| 10 | use Stewart\Contracts\Exception\CommandException; | |
| 11 | use Stewart\Contracts\Exposure\CalendarStateFormat; | |
| 12 | use Stewart\Contracts\Exposure\Command\DateTimeCommand; | |
| 13 | use Stewart\Contracts\Exposure\DateTimeConfig; | |
| 14 | use Stewart\Contracts\Exposure\ExposedDateTime; | |
| 15 | use Stewart\Contracts\Exposure\ExposedState; | |
| 16 | use Stewart\Contracts\Exposure\ExposedStateChange; | |
| 17 | ||
| 18 | /** @extends RecordingExposedEntity<DateTimeConfig> */ | |
| 19 | final class RecordingExposedDateTime extends RecordingExposedEntity implements ExposedDateTime | |
| 20 | { | |
| 21 | public function getConfig(): DateTimeConfig | |
| 22 | { | |
| 23 | return $this->config; | |
| 24 | } | |
| 25 | ||
| 26 | public function updateConfig(DateTimeConfig $config): void | |
| 27 | { | |
| 28 | $this->recordConfig($config); | |
| 29 | } | |
| 30 | ||
| 31 | public function getValue(): ?DateTimeImmutable | |
| 32 | { | |
| 33 | $value = $this->findStateValue(); | |
| 34 | ||
| 35 | return \is_string($value) ? CalendarStateFormat::parseDateTime($value) : null; | |
| 36 | } | |
| 37 | ||
| 38 | public function setValue(?DateTimeInterface $value, ?array $attributes = null): void | |
| 39 | { | |
| 40 | $this->recordChange(new ExposedStateChange(new ExposedState($value === null ? null : CalendarStateFormat::formatDateTime($value)), $attributes)); | |
| 41 | } | |
| 42 | ||
| 43 | public function watchCommands(): EventStream | |
| 44 | { | |
| 45 | /** @var EventStream<DateTimeCommand> */ | |
| 46 | return $this->watchPushedCommands(); | |
| 47 | } | |
| 48 | ||
| 49 | /** @throws CommandException */ | |
| 50 | public function pushCommand(DateTimeCommand $command): void | |
| 51 | { | |
| 52 | $this->deliverCommand($command); | |
| 53 | } | |
| 54 | } |