GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

DefaultTransitionTable::resolve()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2
Metric Value
dl 0
loc 10
ccs 5
cts 5
cp 1
rs 9.4285
cc 2
eloc 5
nc 2
nop 2
crap 2
1
<?php
2
3
declare (strict_types = 1);
4
5
namespace Noodle\Transition\Table;
6
7
use Noodle\State\State;
8
use Noodle\Transition\Input\Input;
9
use Noodle\Transition\Table\Exception\InvalidInputForState;
10
use Noodle\Transition\Transition;
11
12
final class DefaultTransitionTable implements TransitionTable
13
{
14
    /**
15
     * @var array
16
     */
17
    private $transitions = [];
18
19
    /**
20
     * Constructor
21
     *
22
     * @param \Noodle\Transition\Transition[] ...$transitions
23
     */
24 14
    public function __construct(Transition ...$transitions)
25
    {
26 14
        foreach ($transitions as $transition) {
27 14
            $actionKey = $this->getActionKey($transition->getCurrentState(), $transition->getInput());
28 14
            $this->transitions[$actionKey] = $transition->getNextState();
29
        }
30 14
    }
31
32
    /**
33
     * {@inheritdoc}
34
     *
35
     * @throws InvalidInputForState
36
     */
37 14
    public function resolve(State $currentState, Input $input) : State
38
    {
39 14
        $actionKey = $this->getActionKey($currentState, $input);
40
41 14
        if (!empty($this->transitions[$actionKey])) {
42 12
            return $this->transitions[$actionKey];
43
        }
44
45 2
        throw new InvalidInputForState($input, $currentState);
46
    }
47
48
    /**
49
     * Returns the key to use to store the action involving application of an
50
     * input to a given state internally.
51
     *
52
     * @param State $currentState
53
     * @param Input $input
54
     *
55
     * @return string
56
     */
57 14
    private function getActionKey(State $currentState, Input $input) : string
58
    {
59 14
        return sprintf('%s | %s', $currentState->getName(), $input->getName());
60
    }
61
}
62