State::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Dflydev\FiniteStateMachine\State;
6
7
class State
8
{
9
    const INITIAL = 'initial';
10
    const NORMAL = 'normal';
11
    const FINAL = 'final';
12
13
    private string $type;
14
    private string $name;
15
    private array $metadata;
16
17 21
    private function __construct(string $type, string $name, array $metadata = [])
18
    {
19 21
        $this->type = $type;
20 21
        $this->name = $name;
21 21
        $this->metadata = $metadata;
22 21
    }
23
24 21
    public function name(): string
25
    {
26 21
        return $this->name;
27
    }
28
29 6
    public function metadata(): array
30
    {
31 6
        return $this->metadata;
32
    }
33
34
    public static function initialTyped(string $name, array $metadata): self
35
    {
36
        return new static(static::INITIAL, $name, $metadata);
37
    }
38
39 21
    public static function normalTyped(string $name, array $metadata): self
40
    {
41 21
        return new static(static::NORMAL, $name, $metadata);
42
    }
43
44
    public static function finalTyped(string $name, array $metadata): self
45
    {
46
        return new static(static::FINAL, $name, $metadata);
47
    }
48
}
49