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   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 50
ccs 12
cts 12
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 2
A resolve() 0 10 2
A getActionKey() 0 4 1
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