OneOrNoneActiveTransition::selectTransition()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 10
cts 10
cp 1
rs 9.8333
c 0
b 0
f 0
cc 3
nc 3
nop 1
crap 3
1
<?php
2
3
namespace Metabor\Statemachine\Factory\TransitionSelector;
4
5
use MetaborStd\Statemachine\Factory\TransitionSelectorInterface;
6
7
/**
8
 * @author otischlinger
9
 */
10
class OneOrNoneActiveTransition implements TransitionSelectorInterface
11
{
12
    /**
13
     * @see \MetaborStd\Statemachine\Factory\TransitionSelectorInterface::selectTransition()
14
     */
15 10
    public function selectTransition(\Traversable $transitions)
16
    {
17 10
        $transitions = iterator_to_array($transitions);
18
19 10
        switch (count($transitions)) {
20 10
            case 0:
21 3
                return;
22 10
            case 1:
23 8
                return reset($transitions);
24 2
            default:
25 2
                throw new \RuntimeException('More than one transition is active!');
26 2
        }
27
    }
28
}
29