Completed
Push — master ( 755019...3e762f )
by Oliver
02:11
created

OneOrNoneActiveTransition   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 1 Features 1
Metric Value
wmc 3
c 2
b 1
f 1
lcom 0
cbo 0
dl 0
loc 19
ccs 10
cts 10
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A selectTransition() 0 13 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 8
    public function selectTransition(\Traversable $transitions)
16
    {
17 8
        $transitions = iterator_to_array($transitions);
18
19 8
        switch (count($transitions)) {
20 8
            case 0:
21 3
                return;
22 8
            case 1:
23 7
                return reset($transitions);
24 1
            default:
25 1
                throw new \RuntimeException('More than one transition is active!');
26 1
        }
27
    }
28
}
29