Completed
Pull Request — master (#66)
by Frank
07:06 queued 04:59
created

LightSwitchWasFlipped::toPayload()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace EventSauce\EventSourcing\Snapshotting\Tests;
6
7
use EventSauce\EventSourcing\Serialization\SerializablePayload;
8
9
class LightSwitchWasFlipped implements SerializablePayload
10
{
11
    const ON = true;
12
    const OFF = false;
13
14
    /**
15
     * @var bool
16
     */
17
    private $state;
18
19
    private function __construct(bool $state)
20
    {
21
        $this->state = $state;
22
    }
23
24
    public function state(): bool
25
    {
26
        return $this->state;
27
    }
28
29
    public static function on(): LightSwitchWasFlipped
30
    {
31
        return new static(self::ON);
32
    }
33
34
    public static function off(): LightSwitchWasFlipped
35
    {
36
        return new static(self::OFF);
37
    }
38
39
    public function toPayload(): array
40
    {
41
        return ['state' => $this->state];
42
    }
43
44
    public static function fromPayload(array $payload): SerializablePayload
45
    {
46
        return new static($payload['state']);
47
    }
48
}
49