AbstractVotingManager   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 41
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A innerVote() 0 15 4
1
<?php
2
namespace SpareParts\Overseer;
3
4
use SpareParts\Overseer\Assembly\IVotingAbilityAwareAssembly;
5
use SpareParts\Overseer\Context\IVotingContext;
6
7
abstract class AbstractVotingManager
8
{
9
    /**
10
     * @var IVotingAbilityAwareAssembly[]
11
     */
12
    private $votingAssemblies;
13
14
15
    /**
16
     * VotingManager constructor.
17
     * @param IVotingAbilityAwareAssembly[] $votingAssemblies
18
     */
19 7
    public function __construct(array $votingAssemblies)
20
    {
21 7
        $this->votingAssemblies = $votingAssemblies;
22 7
    }
23
24
25
    /**
26
     * @param string $action
27
     * @param mixed $votingSubject
28
     * @param \SpareParts\Overseer\Context\IVotingContext $votingContext
29
     * @return \SpareParts\Overseer\IVotingResult
30
     * @throws \SpareParts\Overseer\InvalidVotingResultException
31
     */
32 7
    protected function innerVote($action, $votingSubject, IVotingContext $votingContext)
33
    {
34 7
        foreach ($this->votingAssemblies as $votingAssembly) {
35 7
            if (!($votingAssembly instanceof IVotingAbilityAwareAssembly)) {
36 1
                throw new InvalidArgumentException('Voting assemblies provided to voting manager must implement IVotingAbilityAwareAssembly interface!');
37
            }
38
39 6
            if ($votingAssembly->canVoteOn($action, $votingSubject, $votingContext)) {
40 5
                return $votingAssembly->commenceVote($votingSubject, $votingContext);
41
            }
42
        }
43
44 1
        throw new InvalidVotingResultException('No voting assembly for subject::action: '.
45 1
            (string) $votingSubject.'::'.$action);
46
    }
47
}
48