Passed
Pull Request — master (#19)
by Yannick
02:27
created

OneToOneTransition::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 2
dl 0
loc 6
ccs 5
cts 5
cp 1
crap 1
rs 9.4285
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\StateRegistry;
7
use Star\Component\State\StateTransition;
8
use Star\Component\State\StateVisitor;
9
use Star\Component\State\TransitionVisitor;
10
use Webmozart\Assert\Assert;
11
12
final class OneToOneTransition implements StateTransition
13
{
14
    /**
15
     * @var string
16
     */
17
    private $from;
18
19
    /**
20
     * @var string
21
     */
22
    private $to;
23
24
    /**
25
     * @param string $from
26
     * @param string $to
27
     */
28 43
    public function __construct($from, $to)
29
    {
30 43
        Assert::string($from);
31 43
        Assert::string($to);
32 43
        $this->from = $from;
33 43
        $this->to = $to;
34 43
    }
35
36
    /**
37
     * @param string $from
38
     *
39
     * @return bool
40
     */
41 27
    public function isAllowed($from)
42
    {
43 27
        Assert::string($from);
44 27
        return $from === $this->from;
45
    }
46
47
    /**
48
     * @param RegistryBuilder $registry
49
     */
50 42
    public function onRegister(RegistryBuilder $registry)
51
    {
52 42
        $registry->registerState($this->from, []);
53 42
        $registry->registerState($this->to, []);
54 42
    }
55
56 26
    public function getDestinationState()
57
    {
58 26
        return $this->to;
59
    }
60
61
    /**
62
     * @param TransitionVisitor $visitor
63
     */
64 2
    public function acceptTransitionVisitor(TransitionVisitor $visitor)
65
    {
66 2
        $visitor->visitFromState($this->from);
67 2
        $visitor->visitToState($this->to);
68 2
    }
69
70
    /**
71
     * @param StateVisitor $visitor
72
     * @param StateRegistry $registry
73
     */
74 1
    public function acceptStateVisitor(StateVisitor $visitor, StateRegistry $registry)
75
    {
76 1
        $registry->getState($this->from)->acceptStateVisitor($visitor);
77 1
        $registry->getState($this->to)->acceptStateVisitor($visitor);
78 1
    }
79
}
80