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
WorkerExposedTime 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 Stewart\Contracts\EventStream;
8use Stewart\Contracts\Exposure\CalendarStateFormat;
9use Stewart\Contracts\Exposure\Command\TimeCommand;
10use Stewart\Contracts\Exposure\ExposedState;
11use Stewart\Contracts\Exposure\ExposedStateChange;
12use Stewart\Contracts\Exposure\ExposedTime;
13use Stewart\Contracts\Exposure\TimeConfig;
14use Stewart\Contracts\Schedule\TimeOfDay;
15
16/** @extends WorkerExposedEntity<TimeConfig> */
17final class WorkerExposedTime extends WorkerExposedEntity implements ExposedTime
18{
19    public function getConfig(): TimeConfig
20    {
21        return $this->findConfig();
22    }
23
24    public function updateConfig(TimeConfig $config): void
25    {
26        $this->sendReconfiguration($config);
27    }
28
29    public function watchCommands(): EventStream
30    {
31        /** @var EventStream<TimeCommand> */
32        return $this->watchOwnCommands();
33    }
34
35    public function getValue(): ?TimeOfDay
36    {
37        $value = $this->findStateValue();
38
39        return \is_string($value) ? CalendarStateFormat::parseTime($value) : null;
40    }
41
42    public function setValue(?TimeOfDay $value, ?array $attributes = null): void
43    {
44        $this->sendChange(new ExposedStateChange(new ExposedState($value === null ? null : CalendarStateFormat::formatTime($value)), $attributes));
45    }
46}