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

ManyToOneTransition   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Test Coverage

Coverage 88.89%

Importance

Changes 0
Metric Value
dl 0
loc 59
ccs 16
cts 18
cp 0.8889
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A getName() 0 3 1
A getDestinationState() 0 3 1
A onRegister() 0 7 2
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