Passed
Push — master ( 3f20a2...3eb034 )
by Frank
02:16
created

LightSwitch::applyLightSwitchWasFlipped()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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
    const OFF = false;
18
    const ON = true;
19
20
    /**
21
     * @var bool
22
     */
23
    private $state = self::OFF;
24
25
    /**
26
     * @return bool
27
     */
28 1
    private function createSnapshotState()
0 ignored issues
show
Unused Code introduced by
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...
29
    {
30 1
        return $this->state;
31
    }
32
33 1
    public function state(): bool
34
    {
35 1
        return $this->state;
36
    }
37
38 3
    public function turnOn(): void
39
    {
40 3
        if (self::OFF == $this->state) {
41 2
            $this->recordThat(LightSwitchWasFlipped::on());
42
        }
43 3
    }
44
45 3
    public function turnOff(): void
46
    {
47 3
        if (self::ON == $this->state) {
48 2
            $this->recordThat(LightSwitchWasFlipped::off());
49
        }
50 3
    }
51
52 4
    protected function applyLightSwitchWasFlipped(LightSwitchWasFlipped $event): void
53
    {
54 4
        $this->state = $event->state();
55 4
    }
56
57
    /**
58
     * @param bool $state
59
     */
60 1
    protected static function reconstituteFromSnapshotState(AggregateRootId $id, $state): AggregateRootWithSnapshotting
61
    {
62 1
        $lightSwitch = new static($id);
63 1
        $lightSwitch->state = $state;
64
65 1
        return $lightSwitch;
66
    }
67
}
68