Issues (14)

src/Snapshotting/Tests/LightSwitch.php (1 issue)

Severity
1
<?php
2
3
declare(strict_types=1);
4
5
namespace EventSauce\EventSourcing\Snapshotting\Tests;
6
7
use EventSauce\EventSourcing\AggregateRootBehaviour;
8
use EventSauce\EventSourcing\AggregateRootId;
9
use EventSauce\EventSourcing\Snapshotting\AggregateRootWithSnapshotting;
10
use EventSauce\EventSourcing\Snapshotting\SnapshottingBehaviour;
11
12
final class LightSwitch implements AggregateRootWithSnapshotting
13
{
14
    use AggregateRootBehaviour;
15
    use SnapshottingBehaviour;
16
17
    public const OFF = false;
18
    public const ON = true;
19
20
    private bool $state = self::OFF;
21
22
    private function createSnapshotState(): bool
0 ignored issues
show
The method createSnapshotState() is not used, and could be removed.

This check looks for private methods that have been defined, but are not used inside the class.

Loading history...
23
    {
24
        return $this->state;
25
    }
26
27
    public function state(): bool
28 1
    {
29
        return $this->state;
30 1
    }
31
32
    public function turnOn(): void
33 1
    {
34
        if (self::OFF == $this->state) {
35 1
            $this->recordThat(LightSwitchWasFlipped::on());
36
        }
37
    }
38 3
39
    public function turnOff(): void
40 3
    {
41 2
        if (self::ON == $this->state) {
42
            $this->recordThat(LightSwitchWasFlipped::off());
43 3
        }
44
    }
45 3
46
    protected function applyLightSwitchWasFlipped(LightSwitchWasFlipped $event): void
47 3
    {
48 2
        $this->state = $event->state();
49
    }
50 3
51
    /**
52 4
     * @param bool $state
53
     */
54 4
    protected static function reconstituteFromSnapshotState(AggregateRootId $id, $state): AggregateRootWithSnapshotting
55 4
    {
56
        $lightSwitch = new static($id);
57
        $lightSwitch->state = (bool) $state;
58
59
        return $lightSwitch;
60 1
    }
61
}
62