Lines 85.71% 6 / 7
Functions and Methods 83.33% 5 / 6
Classes and Traits 0.00% 0 / 1
Name Lines Functions and Methods CRAP Classes and Traits
RecordingExposedNumber 85.71% 6 / 7 83.33% 5 / 6 8.19 0.00% 0 / 1
 getConfig 100.00% 1 / 1 100.00% 1 / 1 1
 updateConfig 100.00% 1 / 1 100.00% 1 / 1 1
 getValue 100.00% 2 / 2 100.00% 1 / 1 3
 setValue 0.00% 0 / 1 0.00% 0 / 1 2
 watchCommands 100.00% 1 / 1 100.00% 1 / 1 1
 pushCommand 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\Command\NumberCommand;
10use Stewart\Contracts\Exposure\ExposedNumber;
11use Stewart\Contracts\Exposure\ExposedState;
12use Stewart\Contracts\Exposure\ExposedStateChange;
13use Stewart\Contracts\Exposure\NumberConfig;
14
15/** @extends RecordingExposedEntity<NumberConfig> */
16final class RecordingExposedNumber extends RecordingExposedEntity implements ExposedNumber
17{
18    public function getConfig(): NumberConfig
19    {
20        return $this->config;
21    }
22
23    public function updateConfig(NumberConfig $config): void
24    {
25        $this->recordConfig($config);
26    }
27
28    public function getValue(): int|float|null
29    {
30        $value = $this->findStateValue();
31
32        return \is_int($value) || \is_float($value) ? $value : null;
33    }
34
35    public function setValue(int|float|null $value, ?array $attributes = null): void
36    {
37        $this->recordChange(new ExposedStateChange(new ExposedState($this->config->formatState($value)), $attributes));
38    }
39
40    public function watchCommands(): EventStream
41    {
42        /** @var EventStream<NumberCommand> */
43        return $this->watchPushedCommands();
44    }
45
46    /** @throws CommandException */
47    public function pushCommand(NumberCommand $command): void
48    {
49        $this->deliverCommand($command);
50    }
51}