Completed
Branch master (755019)
by Oliver
04:40
created

OneOrNoneActiveTransition   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 87.5%

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 7
cts 8
cp 0.875
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
            case 0:
21 3
                return;
22 1
            case 1:
23 7
                return reset($transitions);
24
            default:
25 1
                throw new \RuntimeException('More than one transition is active!');
26
        }
27
    }
28
}
29