Lines 86.20% 25 / 29
Methods 76.47% 13 / 17
Classes 0.00% 0 / 1
Name Lines Methods CRAP
 __construct 100.00% 2 / 2 100.00% 1 / 1 1
 applySnapshot 100.00% 4 / 4 100.00% 1 / 1 1
 getEntityId 100.00% 1 / 1 100.00% 1 / 1 1
 getAttributes 0.00% 0 / 1 0.00% 0 / 1 2
 isAvailable 100.00% 1 / 1 100.00% 1 / 1 1
 setAttributes 0.00% 0 / 1 0.00% 0 / 1 2
 markAvailable 0.00% 0 / 1 0.00% 0 / 1 2
 markUnavailable 100.00% 1 / 1 100.00% 1 / 1 1
 recordChange 100.00% 5 / 5 100.00% 1 / 1 1
 deliverCommand 100.00% 2 / 2 100.00% 1 / 1 1
 findStateValue 100.00% 1 / 1 100.00% 1 / 1 1
 [Stewart\Testing\Exposure\RecordingExposure] getKey 100.00% 1 / 1 100.00% 1 / 1 1
 [Stewart\Testing\Exposure\RecordingExposure] cancelCommandSubscriptions 0.00% 0 / 1 0.00% 0 / 1 2
 [Stewart\Testing\Exposure\RecordingExposure] remove 100.00% 2 / 2 100.00% 1 / 1 1
 [Stewart\Testing\Exposure\RecordingExposure] recordConfig 100.00% 2 / 2 100.00% 1 / 1 1
 [Stewart\Testing\Exposure\RecordingExposure] watchPushedCommands 100.00% 1 / 1 100.00% 1 / 1 1
 [Stewart\Testing\Exposure\RecordingExposure] assertNotRemoved 100.00% 2 / 2 100.00% 1 / 1 2
25abstract class RecordingExposedEntity extends RecordingExposure implements ExposedEntity
26{
27    public private(set) ExposedStateChangeCollection $changes;
28
29    private ?EntityId $entityId = null;
30
31    private ?ExposedState $state = null;
32
33    /** @var ExposedAttributes */
34    private array $attributes = [];
35
36    private bool $available = true;
37
38    /** @param TConfig $config */
39    public function __construct(ExposedEntityKey $key, ExposedEntityConfig $config, ManualTimers $timers)
40    {
41        parent::__construct($key, $config, $timers);
42        $this->changes = ExposedStateChangeCollection::empty();
43    }
44
45    public function applySnapshot(ExposedEntitySnapshot $snapshot): void
46    {
47        $this->entityId = $snapshot->entityId;
48        $this->state = $snapshot->state;
49        $this->attributes = $snapshot->attributes;
50        $this->available = $snapshot->available;
51    }
52
53    public function getEntityId(): ?EntityId
54    {
55        return $this->entityId;
56    }
57
58    public function getAttributes(): array
59    {
60        return $this->attributes;
61    }
62
63    public function isAvailable(): bool
64    {
65        return $this->available;
66    }
67
68    public function setAttributes(array $attributes): void
69    {
70        $this->recordChange(new ExposedStateChange(attributes: $attributes));
71    }
72
73    public function markAvailable(): void
74    {
75        $this->recordChange(new ExposedStateChange(available: true));
76    }
77
78    public function markUnavailable(): void
79    {
80        $this->recordChange(new ExposedStateChange(available: false));
81    }
82
83    /** @throws ExposureException */
84    protected function recordChange(ExposedStateChange $change): void
85    {
86        $this->assertNotRemoved();
87        $this->changes = $this->changes->withChange($change);
88        $this->state = $change->state ?? $this->state;
89        $this->attributes = $change->attributes ?? $this->attributes;
90        $this->available = $change->available ?? $this->available;
91    }
92
93    protected function deliverCommand(ExposedCommand $command): void
94    {
95        parent::deliverCommand($command);
96        $this->state = $command->getRequestedState() ?? $this->state;
97    }
98
99    protected function findStateValue(): int|float|string|bool|null
100    {
101        return $this->state?->value;
102    }
103}

Inherited from Stewart\Testing\Exposure\RecordingExposure

34    public function getKey(): ExposedEntityKey
35    {
36        return $this->key;
37    }
39    public function cancelCommandSubscriptions(): void
40    {
41        $this->commands->cancelAttachments();
42    }
44    public function remove(): void
45    {
46        $this->assertNotRemoved();
47        $this->removed = true;
48    }
54    protected function recordConfig(ExposureConfig $config): void
55    {
56        $this->assertNotRemoved();
57        $this->config = $config;
58    }
61    protected function watchPushedCommands(): EventStream
62    {
63        return new OperatorStream($this->commands, $this->timers);
64    }
73    protected function assertNotRemoved(): void
74    {
75        if ($this->removed) {
76            throw ExposureException::removed($this->key);
77        }
78    }