LightSwitchWasFlipped   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 38
ccs 13
cts 13
cp 1
rs 10
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A off() 0 3 1
A toPayload() 0 3 1
A fromPayload() 0 3 1
A __construct() 0 3 1
A state() 0 3 1
A on() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace EventSauce\EventSourcing\Snapshotting\Tests;
6
7
use EventSauce\EventSourcing\Serialization\SerializablePayload;
8
9
final class LightSwitchWasFlipped implements SerializablePayload
10
{
11
    public const ON = true;
12
    public 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(): self
30
    {
31 4
        return new static(self::ON);
32
    }
33
34 2
    public static function off(): self
35
    {
36 2
        return new self(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): self
45
    {
46 4
        return new self($payload['state']);
47
    }
48
}
49