Lines 87.50% 7 / 8
Functions and Methods 85.71% 6 / 7
Classes and Traits 0.00% 0 / 1
Name Lines Functions and Methods CRAP Classes and Traits
RecordingExposedSwitch 87.50% 7 / 8 85.71% 6 / 7 8.12 0.00% 0 / 1
 getConfig 0.00% 0 / 1 0.00% 0 / 1 2
 updateConfig 100.00% 1 / 1 100.00% 1 / 1 1
 getValue 100.00% 2 / 2 100.00% 1 / 1 2
 setOn 100.00% 1 / 1 100.00% 1 / 1 1
 setOff 100.00% 1 / 1 100.00% 1 / 1 1
 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\SwitchCommand;
10use Stewart\Contracts\Exposure\ExposedState;
11use Stewart\Contracts\Exposure\ExposedStateChange;
12use Stewart\Contracts\Exposure\ExposedSwitch;
13use Stewart\Contracts\Exposure\SwitchConfig;
14
15/** @extends RecordingExposedEntity<SwitchConfig> */
16final class RecordingExposedSwitch extends RecordingExposedEntity implements ExposedSwitch
17{
18    public function getConfig(): SwitchConfig
19    {
20        return $this->config;
21    }
22
23    public function updateConfig(SwitchConfig $config): void
24    {
25        $this->recordConfig($config);
26    }
27
28    public function getValue(): ?bool
29    {
30        $value = $this->findStateValue();
31
32        return \is_bool($value) ? $value : null;
33    }
34
35    public function setOn(?array $attributes = null): void
36    {
37        $this->recordChange(new ExposedStateChange(new ExposedState(true), $attributes));
38    }
39
40    public function setOff(?array $attributes = null): void
41    {
42        $this->recordChange(new ExposedStateChange(new ExposedState(false), $attributes));
43    }
44
45    public function watchCommands(): EventStream
46    {
47        /** @var EventStream<SwitchCommand> */
48        return $this->watchPushedCommands();
49    }
50
51    /** @throws CommandException */
52    public function pushCommand(SwitchCommand $command): void
53    {
54        $this->deliverCommand($command);
55    }
56}