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
WorkerExposedDateTime 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
3declare(strict_types=1);
4
5namespace Stewart\Runtime\Worker\Exposure;
6
7use DateTimeImmutable;
8use DateTimeInterface;
9use Stewart\Contracts\EventStream;
10use Stewart\Contracts\Exposure\CalendarStateFormat;
11use Stewart\Contracts\Exposure\Command\DateTimeCommand;
12use Stewart\Contracts\Exposure\DateTimeConfig;
13use Stewart\Contracts\Exposure\ExposedDateTime;
14use Stewart\Contracts\Exposure\ExposedState;
15use Stewart\Contracts\Exposure\ExposedStateChange;
16
17/** @extends WorkerExposedEntity<DateTimeConfig> */
18final 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}