@@ -5,43 +5,43 @@ |
||
5 | 5 | |
6 | 6 | class VotingResult implements IVotingResult |
7 | 7 | { |
8 | - /** |
|
9 | - * @var VotingDecisionEnum |
|
10 | - */ |
|
11 | - private $decision; |
|
12 | - |
|
13 | - /** |
|
14 | - * @var ISingleVoterResult[] |
|
15 | - */ |
|
16 | - private $partialResults; |
|
17 | - |
|
18 | - |
|
19 | - /** |
|
20 | - * VotingResult constructor. |
|
21 | - * @param VotingDecisionEnum $decision |
|
22 | - * @param ISingleVoterResult[] $partialResults |
|
23 | - */ |
|
24 | - public function __construct(VotingDecisionEnum $decision, $partialResults) |
|
8 | + /** |
|
9 | + * @var VotingDecisionEnum |
|
10 | + */ |
|
11 | + private $decision; |
|
12 | + |
|
13 | + /** |
|
14 | + * @var ISingleVoterResult[] |
|
15 | + */ |
|
16 | + private $partialResults; |
|
17 | + |
|
18 | + |
|
19 | + /** |
|
20 | + * VotingResult constructor. |
|
21 | + * @param VotingDecisionEnum $decision |
|
22 | + * @param ISingleVoterResult[] $partialResults |
|
23 | + */ |
|
24 | + public function __construct(VotingDecisionEnum $decision, $partialResults) |
|
25 | 25 | { |
26 | - $this->decision = $decision; |
|
27 | - $this->partialResults = $partialResults; |
|
28 | - } |
|
29 | - |
|
30 | - |
|
31 | - /** |
|
32 | - * @return VotingDecisionEnum |
|
33 | - */ |
|
34 | - public function getDecision() |
|
35 | - { |
|
36 | - return $this->decision; |
|
37 | - } |
|
38 | - |
|
39 | - |
|
40 | - /** |
|
41 | - * @return ISingleVoterResult[] |
|
42 | - */ |
|
43 | - public function getPartialResults() |
|
44 | - { |
|
45 | - return $this->partialResults; |
|
46 | - } |
|
26 | + $this->decision = $decision; |
|
27 | + $this->partialResults = $partialResults; |
|
28 | + } |
|
29 | + |
|
30 | + |
|
31 | + /** |
|
32 | + * @return VotingDecisionEnum |
|
33 | + */ |
|
34 | + public function getDecision() |
|
35 | + { |
|
36 | + return $this->decision; |
|
37 | + } |
|
38 | + |
|
39 | + |
|
40 | + /** |
|
41 | + * @return ISingleVoterResult[] |
|
42 | + */ |
|
43 | + public function getPartialResults() |
|
44 | + { |
|
45 | + return $this->partialResults; |
|
46 | + } |
|
47 | 47 | } |
@@ -5,8 +5,8 @@ |
||
5 | 5 | |
6 | 6 | interface ISingleVoterResult extends IResult |
7 | 7 | { |
8 | - /** |
|
9 | - * @return mixed |
|
10 | - */ |
|
11 | - public function getReason(); |
|
8 | + /** |
|
9 | + * @return mixed |
|
10 | + */ |
|
11 | + public function getReason(); |
|
12 | 12 | } |
13 | 13 | \ No newline at end of file |
@@ -6,42 +6,42 @@ |
||
6 | 6 | class SingleVoterResult implements ISingleVoterResult |
7 | 7 | { |
8 | 8 | |
9 | - /** |
|
10 | - * @var VotingDecisionEnum |
|
11 | - */ |
|
12 | - private $decision; |
|
13 | - |
|
14 | - /** |
|
15 | - * @var mixed |
|
16 | - */ |
|
17 | - private $reason; |
|
18 | - |
|
19 | - |
|
20 | - /** |
|
21 | - * SingleVoterResult constructor. |
|
22 | - * @param VotingDecisionEnum $decision |
|
23 | - * @param mixed $reason |
|
24 | - */ |
|
25 | - public function __construct(VotingDecisionEnum $decision, $reason = null) |
|
26 | - { |
|
27 | - $this->decision = $decision; |
|
28 | - $this->reason = $reason; |
|
29 | - } |
|
30 | - |
|
31 | - |
|
32 | - /** |
|
33 | - * @return VotingDecisionEnum |
|
34 | - */ |
|
35 | - public function getDecision() |
|
36 | - { |
|
37 | - return $this->decision; |
|
38 | - } |
|
39 | - |
|
40 | - /** |
|
41 | - * @return mixed |
|
42 | - */ |
|
43 | - public function getReason() |
|
44 | - { |
|
45 | - return $this->reason; |
|
46 | - } |
|
9 | + /** |
|
10 | + * @var VotingDecisionEnum |
|
11 | + */ |
|
12 | + private $decision; |
|
13 | + |
|
14 | + /** |
|
15 | + * @var mixed |
|
16 | + */ |
|
17 | + private $reason; |
|
18 | + |
|
19 | + |
|
20 | + /** |
|
21 | + * SingleVoterResult constructor. |
|
22 | + * @param VotingDecisionEnum $decision |
|
23 | + * @param mixed $reason |
|
24 | + */ |
|
25 | + public function __construct(VotingDecisionEnum $decision, $reason = null) |
|
26 | + { |
|
27 | + $this->decision = $decision; |
|
28 | + $this->reason = $reason; |
|
29 | + } |
|
30 | + |
|
31 | + |
|
32 | + /** |
|
33 | + * @return VotingDecisionEnum |
|
34 | + */ |
|
35 | + public function getDecision() |
|
36 | + { |
|
37 | + return $this->decision; |
|
38 | + } |
|
39 | + |
|
40 | + /** |
|
41 | + * @return mixed |
|
42 | + */ |
|
43 | + public function getReason() |
|
44 | + { |
|
45 | + return $this->reason; |
|
46 | + } |
|
47 | 47 | } |
48 | 48 | \ No newline at end of file |
@@ -4,8 +4,8 @@ |
||
4 | 4 | |
5 | 5 | interface IResult |
6 | 6 | { |
7 | - /** |
|
8 | - * @return VotingDecisionEnum |
|
9 | - */ |
|
10 | - public function getDecision(); |
|
7 | + /** |
|
8 | + * @return VotingDecisionEnum |
|
9 | + */ |
|
10 | + public function getDecision(); |
|
11 | 11 | } |
@@ -42,7 +42,7 @@ |
||
42 | 42 | ) { |
43 | 43 | parent::__construct($strategy, $voters); |
44 | 44 | |
45 | - $this->actionList = (array) $actions; |
|
45 | + $this->actionList = (array)$actions; |
|
46 | 46 | $this->subjectClassName = $subjectClassName; |
47 | 47 | $this->contextClassName = $contextClassName; |
48 | 48 | } |
@@ -9,64 +9,64 @@ |
||
9 | 9 | class VotingAbilityAwareAssembly extends VotingAssembly implements IVotingAbilityAwareAssembly |
10 | 10 | { |
11 | 11 | |
12 | - /** |
|
13 | - * @var string |
|
14 | - */ |
|
15 | - protected $subjectClassName; |
|
12 | + /** |
|
13 | + * @var string |
|
14 | + */ |
|
15 | + protected $subjectClassName; |
|
16 | 16 | |
17 | - /** |
|
18 | - * @var string |
|
19 | - */ |
|
20 | - protected $contextClassName; |
|
17 | + /** |
|
18 | + * @var string |
|
19 | + */ |
|
20 | + protected $contextClassName; |
|
21 | 21 | |
22 | - /** |
|
23 | - * @var string[] |
|
24 | - */ |
|
25 | - protected $actionList; |
|
22 | + /** |
|
23 | + * @var string[] |
|
24 | + */ |
|
25 | + protected $actionList; |
|
26 | 26 | |
27 | 27 | |
28 | - /** |
|
29 | - * @param \SpareParts\Overseer\StrategyEnum $strategy |
|
30 | - * @param IVoter[] $voters |
|
31 | - * @param string|string[] $actions |
|
32 | - * @param string $contextClassName |
|
33 | - * @param string $subjectClassName |
|
34 | - */ |
|
35 | - public function __construct( |
|
36 | - StrategyEnum $strategy, |
|
37 | - array $voters, |
|
38 | - $actions = null, |
|
39 | - $subjectClassName = null, |
|
40 | - $contextClassName = null |
|
41 | - ) { |
|
42 | - parent::__construct($strategy, $voters); |
|
28 | + /** |
|
29 | + * @param \SpareParts\Overseer\StrategyEnum $strategy |
|
30 | + * @param IVoter[] $voters |
|
31 | + * @param string|string[] $actions |
|
32 | + * @param string $contextClassName |
|
33 | + * @param string $subjectClassName |
|
34 | + */ |
|
35 | + public function __construct( |
|
36 | + StrategyEnum $strategy, |
|
37 | + array $voters, |
|
38 | + $actions = null, |
|
39 | + $subjectClassName = null, |
|
40 | + $contextClassName = null |
|
41 | + ) { |
|
42 | + parent::__construct($strategy, $voters); |
|
43 | 43 | |
44 | - $this->actionList = (array) $actions; |
|
45 | - $this->subjectClassName = $subjectClassName; |
|
46 | - $this->contextClassName = $contextClassName; |
|
47 | - } |
|
44 | + $this->actionList = (array) $actions; |
|
45 | + $this->subjectClassName = $subjectClassName; |
|
46 | + $this->contextClassName = $contextClassName; |
|
47 | + } |
|
48 | 48 | |
49 | 49 | |
50 | - /** |
|
51 | - * @param string $actionName |
|
52 | - * @param object $subject |
|
53 | - * @param \SpareParts\Overseer\Context\IVotingContext $context |
|
54 | - * @return bool |
|
55 | - */ |
|
56 | - public function canVoteOn($actionName, $subject, IVotingContext $context) |
|
57 | - { |
|
58 | - if ($this->subjectClassName && !($subject instanceof $this->subjectClassName)) { |
|
59 | - return false; |
|
60 | - } |
|
50 | + /** |
|
51 | + * @param string $actionName |
|
52 | + * @param object $subject |
|
53 | + * @param \SpareParts\Overseer\Context\IVotingContext $context |
|
54 | + * @return bool |
|
55 | + */ |
|
56 | + public function canVoteOn($actionName, $subject, IVotingContext $context) |
|
57 | + { |
|
58 | + if ($this->subjectClassName && !($subject instanceof $this->subjectClassName)) { |
|
59 | + return false; |
|
60 | + } |
|
61 | 61 | |
62 | - if ($this->contextClassName && !($context instanceof $this->contextClassName)) { |
|
63 | - return false; |
|
64 | - } |
|
62 | + if ($this->contextClassName && !($context instanceof $this->contextClassName)) { |
|
63 | + return false; |
|
64 | + } |
|
65 | 65 | |
66 | - if ($this->actionList && !in_array($actionName, $this->actionList)) { |
|
67 | - return false; |
|
68 | - } |
|
69 | - return true; |
|
70 | - } |
|
66 | + if ($this->actionList && !in_array($actionName, $this->actionList)) { |
|
67 | + return false; |
|
68 | + } |
|
69 | + return true; |
|
70 | + } |
|
71 | 71 | |
72 | 72 | } |
@@ -13,11 +13,11 @@ |
||
13 | 13 | { |
14 | 14 | |
15 | 15 | |
16 | - /** |
|
17 | - * @param string $actionName |
|
18 | - * @param mixed $subject |
|
19 | - * @param \SpareParts\Overseer\Context\IVotingContext $context |
|
20 | - * @return bool |
|
21 | - */ |
|
22 | - public function canVoteOn($actionName, $subject, IVotingContext $context); |
|
16 | + /** |
|
17 | + * @param string $actionName |
|
18 | + * @param mixed $subject |
|
19 | + * @param \SpareParts\Overseer\Context\IVotingContext $context |
|
20 | + * @return bool |
|
21 | + */ |
|
22 | + public function canVoteOn($actionName, $subject, IVotingContext $context); |
|
23 | 23 | } |
@@ -6,10 +6,10 @@ |
||
6 | 6 | interface IVotingAssembly |
7 | 7 | { |
8 | 8 | |
9 | - /** |
|
10 | - * @param mixed $votingSubject |
|
11 | - * @param \SpareParts\Overseer\Context\IVotingContext $votingContext |
|
12 | - * @return \SpareParts\Overseer\IVotingResult |
|
13 | - */ |
|
14 | - public function commenceVote($votingSubject, IVotingContext $votingContext); |
|
9 | + /** |
|
10 | + * @param mixed $votingSubject |
|
11 | + * @param \SpareParts\Overseer\Context\IVotingContext $votingContext |
|
12 | + * @return \SpareParts\Overseer\IVotingResult |
|
13 | + */ |
|
14 | + public function commenceVote($votingSubject, IVotingContext $votingContext); |
|
15 | 15 | } |
@@ -6,42 +6,42 @@ |
||
6 | 6 | |
7 | 7 | abstract class AbstractVotingManager |
8 | 8 | { |
9 | - /** |
|
10 | - * @var IVotingAbilityAwareAssembly[] |
|
11 | - */ |
|
12 | - private $votingAssemblies; |
|
13 | - |
|
14 | - |
|
15 | - /** |
|
16 | - * VotingManager constructor. |
|
17 | - * @param IVotingAbilityAwareAssembly[] $votingAssemblies |
|
18 | - */ |
|
19 | - public function __construct(array $votingAssemblies) |
|
20 | - { |
|
21 | - $this->votingAssemblies = $votingAssemblies; |
|
22 | - } |
|
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 | - protected function innerVote($action, $votingSubject, IVotingContext $votingContext) |
|
33 | - { |
|
34 | - foreach ($this->votingAssemblies as $votingAssembly) { |
|
35 | - if (!($votingAssembly instanceof IVotingAbilityAwareAssembly)) { |
|
36 | - throw new InvalidArgumentException('Voting assemblies provided to voting manager must implement IVotingAbilityAwareAssembly interface!'); |
|
37 | - } |
|
38 | - |
|
39 | - if ($votingAssembly->canVoteOn($action, $votingSubject, $votingContext)) { |
|
40 | - return $votingAssembly->commenceVote($votingSubject, $votingContext); |
|
41 | - } |
|
42 | - } |
|
43 | - |
|
44 | - throw new InvalidVotingResultException('No voting assembly for subject::action: '. |
|
45 | - (string) $votingSubject.'::'.$action); |
|
46 | - } |
|
9 | + /** |
|
10 | + * @var IVotingAbilityAwareAssembly[] |
|
11 | + */ |
|
12 | + private $votingAssemblies; |
|
13 | + |
|
14 | + |
|
15 | + /** |
|
16 | + * VotingManager constructor. |
|
17 | + * @param IVotingAbilityAwareAssembly[] $votingAssemblies |
|
18 | + */ |
|
19 | + public function __construct(array $votingAssemblies) |
|
20 | + { |
|
21 | + $this->votingAssemblies = $votingAssemblies; |
|
22 | + } |
|
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 | + protected function innerVote($action, $votingSubject, IVotingContext $votingContext) |
|
33 | + { |
|
34 | + foreach ($this->votingAssemblies as $votingAssembly) { |
|
35 | + if (!($votingAssembly instanceof IVotingAbilityAwareAssembly)) { |
|
36 | + throw new InvalidArgumentException('Voting assemblies provided to voting manager must implement IVotingAbilityAwareAssembly interface!'); |
|
37 | + } |
|
38 | + |
|
39 | + if ($votingAssembly->canVoteOn($action, $votingSubject, $votingContext)) { |
|
40 | + return $votingAssembly->commenceVote($votingSubject, $votingContext); |
|
41 | + } |
|
42 | + } |
|
43 | + |
|
44 | + throw new InvalidVotingResultException('No voting assembly for subject::action: '. |
|
45 | + (string) $votingSubject.'::'.$action); |
|
46 | + } |
|
47 | 47 | } |
@@ -42,6 +42,6 @@ |
||
42 | 42 | } |
43 | 43 | |
44 | 44 | throw new InvalidVotingResultException('No voting assembly for subject::action: '. |
45 | - (string) $votingSubject.'::'.$action); |
|
45 | + (string)$votingSubject.'::'.$action); |
|
46 | 46 | } |
47 | 47 | } |
@@ -7,43 +7,43 @@ |
||
7 | 7 | class IdentityContext implements IIdentityContext |
8 | 8 | { |
9 | 9 | |
10 | - /** |
|
11 | - * @var mixed |
|
12 | - */ |
|
13 | - private $id; |
|
14 | - |
|
15 | - /** |
|
16 | - * @var string[] |
|
17 | - */ |
|
18 | - private $roles; |
|
19 | - |
|
20 | - |
|
21 | - /** |
|
22 | - * VotingContext constructor. |
|
23 | - * @param mixed $id |
|
24 | - * @param string[] $roles |
|
25 | - */ |
|
26 | - public function __construct($id, array $roles) |
|
27 | - { |
|
28 | - $this->id = $id; |
|
29 | - $this->roles = $roles; |
|
30 | - } |
|
31 | - |
|
32 | - |
|
33 | - /** |
|
34 | - * @return mixed |
|
35 | - */ |
|
36 | - public function getId() |
|
37 | - { |
|
38 | - return $this->id; |
|
39 | - } |
|
40 | - |
|
41 | - |
|
42 | - /** |
|
43 | - * @return string[] |
|
44 | - */ |
|
45 | - public function getRoles() |
|
46 | - { |
|
47 | - return $this->roles; |
|
48 | - } |
|
10 | + /** |
|
11 | + * @var mixed |
|
12 | + */ |
|
13 | + private $id; |
|
14 | + |
|
15 | + /** |
|
16 | + * @var string[] |
|
17 | + */ |
|
18 | + private $roles; |
|
19 | + |
|
20 | + |
|
21 | + /** |
|
22 | + * VotingContext constructor. |
|
23 | + * @param mixed $id |
|
24 | + * @param string[] $roles |
|
25 | + */ |
|
26 | + public function __construct($id, array $roles) |
|
27 | + { |
|
28 | + $this->id = $id; |
|
29 | + $this->roles = $roles; |
|
30 | + } |
|
31 | + |
|
32 | + |
|
33 | + /** |
|
34 | + * @return mixed |
|
35 | + */ |
|
36 | + public function getId() |
|
37 | + { |
|
38 | + return $this->id; |
|
39 | + } |
|
40 | + |
|
41 | + |
|
42 | + /** |
|
43 | + * @return string[] |
|
44 | + */ |
|
45 | + public function getRoles() |
|
46 | + { |
|
47 | + return $this->roles; |
|
48 | + } |
|
49 | 49 | } |