Lines 62.50% 5 / 8
Functions and Methods 57.14% 4 / 7
Classes and Traits 0.00% 0 / 1
Name Lines Functions and Methods CRAP Classes and Traits
RecordingExposedTime 62.50% 5 / 8 57.14% 4 / 7 13.27 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 100.00% 1 / 1 100.00% 1 / 1 1
 pushValue 100.00% 1 / 1 100.00% 1 / 1 1
1<?php
2
3declare(strict_types=1);
4
5namespace Stewart\Testing\Exposure;
6
7use Stewart\Contracts\EventStream;
8use Stewart\Contracts\Exception\CommandException;
9use Stewart\Contracts\Exposure\CalendarStateFormat;
10use Stewart\Contracts\Exposure\Command\TimeCommand;
11use Stewart\Contracts\Exposure\ExposedState;
12use Stewart\Contracts\Exposure\ExposedStateChange;
13use Stewart\Contracts\Exposure\ExposedTime;
14use Stewart\Contracts\Exposure\TimeConfig;
15use Stewart\Contracts\Schedule\TimeOfDay;
16use Stewart\Contracts\State\EventContext;
17
18/** @extends RecordingExposedEntity<TimeConfig> */
19final class RecordingExposedTime extends RecordingExposedEntity implements ExposedTime
20{
21    public function getConfig(): TimeConfig
22    {
23        return $this->config;
24    }
25
26    public function updateConfig(TimeConfig $config): void
27    {
28        $this->recordConfig($config);
29    }
30
31    public function getValue(): ?TimeOfDay
32    {
33        $value = $this->findStateValue();
34
35        return \is_string($value) ? CalendarStateFormat::parseTime($value) : null;
36    }
37
38    public function setValue(?TimeOfDay $value, ?array $attributes = null): void
39    {
40        $this->recordChange(new ExposedStateChange(new ExposedState($value === null ? null : CalendarStateFormat::formatTime($value)), $attributes));
41    }
42
43    public function watchCommands(): EventStream
44    {
45        /** @var EventStream<TimeCommand> */
46        return $this->watchPushedCommands();
47    }
48
49    /** @throws CommandException */
50    public function pushCommand(TimeCommand $command): void
51    {
52        $this->deliverCommand($command);
53    }
54
55    /** @throws CommandException */
56    public function pushValue(TimeOfDay $value, ?EventContext $context = null): void
57    {
58        $this->pushCommand(new TimeCommand($value, $context ?? EventContext::unknown()));
59    }
60}