Lines 57.14% 4 / 7
Functions and Methods 50.00% 3 / 6
Classes and Traits 0.00% 0 / 1
Name Lines Functions and Methods CRAP Classes and Traits
RecordingExposedDate 57.14% 4 / 7 50.00% 3 / 6 13.04 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
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\DateCommand;
13use Stewart\Contracts\Exposure\DateConfig;
14use Stewart\Contracts\Exposure\ExposedDate;
15use Stewart\Contracts\Exposure\ExposedState;
16use Stewart\Contracts\Exposure\ExposedStateChange;
17
18/** @extends RecordingExposedEntity<DateConfig> */
19final class RecordingExposedDate extends RecordingExposedEntity implements ExposedDate
20{
21    public function getConfig(): DateConfig
22    {
23        return $this->config;
24    }
25
26    public function updateConfig(DateConfig $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::parseDate($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::formatDate($value)), $attributes));
41    }
42
43    public function watchCommands(): EventStream
44    {
45        /** @var EventStream<DateCommand> */
46        return $this->watchPushedCommands();
47    }
48
49    /** @throws CommandException */
50    public function pushCommand(DateCommand $command): void
51    {
52        $this->deliverCommand($command);
53    }
54}