Passed
Push — master ( dbfb37...74a6ed )
by Frank
46s queued 13s
created

LightSwitchWasFlipped::on()   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 0
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\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 4
    private function __construct(bool $state)
20
    {
21 4
        $this->state = $state;
22 4
    }
23
24 4
    public function state(): bool
25
    {
26 4
        return $this->state;
27
    }
28
29 4
    public static function on(): LightSwitchWasFlipped
30
    {
31 4
        return new static(self::ON);
32
    }
33
34 2
    public static function off(): LightSwitchWasFlipped
35
    {
36 2
        return new static(self::OFF);
37
    }
38
39 4
    public function toPayload(): array
40
    {
41 4
        return ['state' => $this->state];
42
    }
43
44 4
    public static function fromPayload(array $payload): SerializablePayload
45
    {
46 4
        return new static($payload['state']);
47
    }
48
}
49