Passed
Push — master ( 4da179...4cded1 )
by Yannick
02:33
created

ManyToOneTransition::getName()   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 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Star\Component\State\Transitions;
4
5
use Star\Component\State\RegistryBuilder;
6
use Star\Component\State\StateTransition;
7
use Webmozart\Assert\Assert;
8
9
final class ManyToOneTransition implements StateTransition
10
{
11
    /**
12
     * @var string
13
     */
14
    private $name;
15
16
    /**
17
     * @var string[]
18
     */
19
    private $fromStates;
20
21
    /**
22
     * @var string
23
     */
24
    private $to;
25
26
    /**
27
     * @param string $name
28
     * @param string[] $fromStates
29
     * @param string $to
30
     */
31 21
    public function __construct($name, array $fromStates, $to)
32
    {
33 21
        Assert::string($name);
34 21
        $this->name = $name;
35 21
        Assert::greaterThanEq(count($fromStates), 1, 'Expected at least %2$s state. Got: %s');
36 21
        Assert::allString($fromStates);
37 21
        Assert::string($to);
38 21
        $this->fromStates = $fromStates;
39 21
        $this->to = $to;
40 21
    }
41
42
    /**
43
     * @return string
44
     */
45 18
    public function getName()
46
    {
47 18
        return $this->name;
48
    }
49
50
    /**
51
     * @param RegistryBuilder $registry
52
     */
53 18
    public function onRegister(RegistryBuilder $registry)
54
    {
55 18
        foreach ($this->fromStates as $from) {
56 18
            $registry->registerStartingState($this->name, $from, []);
57
        }
58
59 18
        $registry->registerDestinationState($this->name, $this->to, []);
60 18
    }
61
62
    /**
63
     * @return string
64
     */
65
    public function getDestinationState()
66
    {
67
        return $this->to;
68
    }
69
}
70