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
RecordingExposedDateTime 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 DateTimeImmutable;
8use DateTimeInterface;
9use Stewart\Contracts\EventStream;
10use Stewart\Contracts\Exception\CommandException;
11use Stewart\Contracts\Exposure\CalendarStateFormat;
12use Stewart\Contracts\Exposure\Command\DateTimeCommand;
13use Stewart\Contracts\Exposure\DateTimeConfig;
14use Stewart\Contracts\Exposure\ExposedDateTime;
15use Stewart\Contracts\Exposure\ExposedState;
16use Stewart\Contracts\Exposure\ExposedStateChange;
17use Stewart\Contracts\State\EventContext;
18
19/** @extends RecordingExposedEntity<DateTimeConfig> */
20final class RecordingExposedDateTime extends RecordingExposedEntity implements ExposedDateTime
21{
22    public function getConfig(): DateTimeConfig
23    {
24        return $this->config;
25    }
26
27    public function updateConfig(DateTimeConfig $config): void
28    {
29        $this->recordConfig($config);
30    }
31
32    public function getValue(): ?DateTimeImmutable
33    {
34        $value = $this->findStateValue();
35
36        return \is_string($value) ? CalendarStateFormat::parseDateTime($value) : null;
37    }
38
39    public function setValue(?DateTimeInterface $value, ?array $attributes = null): void
40    {
41        $this->recordChange(new ExposedStateChange(new ExposedState($value === null ? null : CalendarStateFormat::formatDateTime($value)), $attributes));
42    }
43
44    public function watchCommands(): EventStream
45    {
46        /** @var EventStream<DateTimeCommand> */
47        return $this->watchPushedCommands();
48    }
49
50    /** @throws CommandException */
51    public function pushCommand(DateTimeCommand $command): void
52    {
53        $this->deliverCommand($command);
54    }
55
56    /** @throws CommandException */
57    public function pushValue(DateTimeImmutable $value, ?EventContext $context = null): void
58    {
59        $this->pushCommand(new DateTimeCommand($value, $context ?? EventContext::unknown()));
60    }
61}