Total Complexity | 8 |
Total Lines | 45 |
Duplicated Lines | 0 % |
Changes | 3 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
12 | class LightSwitch implements AggregateRootWithSnapshotting |
||
13 | { |
||
14 | use AggregateRootBehaviour; |
||
15 | use SnapshottingBehaviour; |
||
16 | |||
17 | const OFF = false; |
||
18 | const ON = true; |
||
19 | |||
20 | private $state = self::OFF; |
||
21 | |||
22 | private function createSnapshotState() |
||
23 | { |
||
24 | return $this->state; |
||
25 | } |
||
26 | |||
27 | public function state(): bool |
||
28 | { |
||
29 | return $this->state; |
||
30 | } |
||
31 | |||
32 | public function turnOn(): void |
||
33 | { |
||
34 | if (self::OFF == $this->state) { |
||
35 | $this->recordThat(LightSwitchWasFlipped::on()); |
||
36 | } |
||
37 | } |
||
38 | |||
39 | public function turnOff(): void |
||
40 | { |
||
41 | if (self::ON == $this->state) { |
||
42 | $this->recordThat(LightSwitchWasFlipped::off()); |
||
43 | } |
||
44 | } |
||
45 | |||
46 | protected function applyLightSwitchWasFlipped(LightSwitchWasFlipped $event): void |
||
49 | } |
||
50 | |||
51 | protected static function reconstituteFromSnapshotState(AggregateRootId $id, bool $state): AggregateRootWithSnapshotting |
||
57 | } |
||
58 | } |
||
59 |