@@ -6,10 +6,10 @@ |
||
6 | 6 | interface IVoter |
7 | 7 | { |
8 | 8 | |
9 | - /** |
|
10 | - * @param mixed $votingSubject |
|
11 | - * @param \SpareParts\Overseer\Context\IVotingContext $votingContext |
|
12 | - * @return ISingleVoterResult |
|
13 | - */ |
|
14 | - public function vote($votingSubject, IVotingContext $votingContext); |
|
9 | + /** |
|
10 | + * @param mixed $votingSubject |
|
11 | + * @param \SpareParts\Overseer\Context\IVotingContext $votingContext |
|
12 | + * @return ISingleVoterResult |
|
13 | + */ |
|
14 | + public function vote($votingSubject, IVotingContext $votingContext); |
|
15 | 15 | } |
@@ -8,54 +8,54 @@ |
||
8 | 8 | |
9 | 9 | class ClosureVoter implements IVoter |
10 | 10 | { |
11 | - /** |
|
12 | - * @var \Closure |
|
13 | - */ |
|
14 | - private $authorizationClosure; |
|
15 | - |
|
16 | - |
|
17 | - /** |
|
18 | - * ClosureVoter constructor. |
|
19 | - * @param \Closure $authorizationClosure |
|
20 | - */ |
|
21 | - public function __construct(\Closure $authorizationClosure) |
|
22 | - { |
|
23 | - $this->authorizationClosure = $authorizationClosure; |
|
24 | - } |
|
25 | - |
|
26 | - |
|
27 | - /** |
|
28 | - * @param mixed $votingSubject |
|
29 | - * @param \SpareParts\Overseer\Context\IVotingContext $votingContext |
|
30 | - * @return ISingleVoterResult |
|
31 | - */ |
|
32 | - public function vote($votingSubject, IVotingContext $votingContext) |
|
33 | - { |
|
34 | - $closure = $this->authorizationClosure; |
|
35 | - $result = $closure($votingSubject, $votingContext); |
|
36 | - |
|
37 | - $result = $this->prepareResult($result); |
|
38 | - |
|
39 | - return $result; |
|
40 | - } |
|
41 | - |
|
42 | - |
|
43 | - /** |
|
44 | - * @param mixed $result |
|
45 | - * @return SingleVoterResult |
|
46 | - */ |
|
47 | - public function prepareResult($result) |
|
48 | - { |
|
49 | - if ($result === true) { |
|
50 | - $result = new SingleVoterResult(VotingDecisionEnum::ALLOWED()); |
|
51 | - return $result; |
|
52 | - } elseif ($result === false) { |
|
53 | - $result = new SingleVoterResult(VotingDecisionEnum::DENIED()); |
|
54 | - return $result; |
|
55 | - } elseif ($result instanceof VotingDecisionEnum) { |
|
56 | - $result = new SingleVoterResult($result); |
|
57 | - return $result; |
|
58 | - } |
|
59 | - return $result; |
|
60 | - } |
|
11 | + /** |
|
12 | + * @var \Closure |
|
13 | + */ |
|
14 | + private $authorizationClosure; |
|
15 | + |
|
16 | + |
|
17 | + /** |
|
18 | + * ClosureVoter constructor. |
|
19 | + * @param \Closure $authorizationClosure |
|
20 | + */ |
|
21 | + public function __construct(\Closure $authorizationClosure) |
|
22 | + { |
|
23 | + $this->authorizationClosure = $authorizationClosure; |
|
24 | + } |
|
25 | + |
|
26 | + |
|
27 | + /** |
|
28 | + * @param mixed $votingSubject |
|
29 | + * @param \SpareParts\Overseer\Context\IVotingContext $votingContext |
|
30 | + * @return ISingleVoterResult |
|
31 | + */ |
|
32 | + public function vote($votingSubject, IVotingContext $votingContext) |
|
33 | + { |
|
34 | + $closure = $this->authorizationClosure; |
|
35 | + $result = $closure($votingSubject, $votingContext); |
|
36 | + |
|
37 | + $result = $this->prepareResult($result); |
|
38 | + |
|
39 | + return $result; |
|
40 | + } |
|
41 | + |
|
42 | + |
|
43 | + /** |
|
44 | + * @param mixed $result |
|
45 | + * @return SingleVoterResult |
|
46 | + */ |
|
47 | + public function prepareResult($result) |
|
48 | + { |
|
49 | + if ($result === true) { |
|
50 | + $result = new SingleVoterResult(VotingDecisionEnum::ALLOWED()); |
|
51 | + return $result; |
|
52 | + } elseif ($result === false) { |
|
53 | + $result = new SingleVoterResult(VotingDecisionEnum::DENIED()); |
|
54 | + return $result; |
|
55 | + } elseif ($result instanceof VotingDecisionEnum) { |
|
56 | + $result = new SingleVoterResult($result); |
|
57 | + return $result; |
|
58 | + } |
|
59 | + return $result; |
|
60 | + } |
|
61 | 61 | } |
@@ -8,36 +8,36 @@ |
||
8 | 8 | |
9 | 9 | class ConstVoter implements IVoter |
10 | 10 | { |
11 | - /** |
|
12 | - * @var VotingDecisionEnum |
|
13 | - */ |
|
14 | - private $constDecision; |
|
15 | - |
|
16 | - /** |
|
17 | - * @var mixed |
|
18 | - */ |
|
19 | - private $constReason; |
|
20 | - |
|
21 | - |
|
22 | - /** |
|
23 | - * ConstVoter constructor. |
|
24 | - * @param VotingDecisionEnum $constDecision |
|
25 | - * @param mixed $constReason |
|
26 | - */ |
|
27 | - public function __construct(VotingDecisionEnum $constDecision, $constReason = null) |
|
28 | - { |
|
29 | - $this->constDecision = $constDecision; |
|
30 | - $this->constReason = $constReason; |
|
31 | - } |
|
32 | - |
|
33 | - |
|
34 | - /** |
|
35 | - * @param mixed $votingSubject |
|
36 | - * @param \SpareParts\Overseer\Context\IVotingContext $votingContext |
|
37 | - * @return ISingleVoterResult |
|
38 | - */ |
|
39 | - public function vote($votingSubject, IVotingContext $votingContext) |
|
40 | - { |
|
41 | - return new SingleVoterResult($this->constDecision, $this->constReason); |
|
42 | - } |
|
11 | + /** |
|
12 | + * @var VotingDecisionEnum |
|
13 | + */ |
|
14 | + private $constDecision; |
|
15 | + |
|
16 | + /** |
|
17 | + * @var mixed |
|
18 | + */ |
|
19 | + private $constReason; |
|
20 | + |
|
21 | + |
|
22 | + /** |
|
23 | + * ConstVoter constructor. |
|
24 | + * @param VotingDecisionEnum $constDecision |
|
25 | + * @param mixed $constReason |
|
26 | + */ |
|
27 | + public function __construct(VotingDecisionEnum $constDecision, $constReason = null) |
|
28 | + { |
|
29 | + $this->constDecision = $constDecision; |
|
30 | + $this->constReason = $constReason; |
|
31 | + } |
|
32 | + |
|
33 | + |
|
34 | + /** |
|
35 | + * @param mixed $votingSubject |
|
36 | + * @param \SpareParts\Overseer\Context\IVotingContext $votingContext |
|
37 | + * @return ISingleVoterResult |
|
38 | + */ |
|
39 | + public function vote($votingSubject, IVotingContext $votingContext) |
|
40 | + { |
|
41 | + return new SingleVoterResult($this->constDecision, $this->constReason); |
|
42 | + } |
|
43 | 43 | } |
@@ -5,8 +5,8 @@ |
||
5 | 5 | |
6 | 6 | interface IVotingResult extends IResult |
7 | 7 | { |
8 | - /** |
|
9 | - * @return ISingleVoterResult[] |
|
10 | - */ |
|
11 | - public function getPartialResults(); |
|
8 | + /** |
|
9 | + * @return ISingleVoterResult[] |
|
10 | + */ |
|
11 | + public function getPartialResults(); |
|
12 | 12 | } |
@@ -14,15 +14,15 @@ |
||
14 | 14 | final class GenericVotingManager extends AbstractVotingManager |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * @param string $action |
|
19 | - * @param mixed $votingSubject |
|
20 | - * @param \SpareParts\Overseer\Context\IVotingContext $votingContext |
|
21 | - * @return \SpareParts\Overseer\IVotingResult |
|
22 | - * @throws \SpareParts\Overseer\InvalidVotingResultException |
|
23 | - */ |
|
24 | - public function vote($action, $votingSubject, IVotingContext $votingContext) |
|
25 | - { |
|
26 | - return $this->innerVote($action, $votingSubject, $votingContext); |
|
27 | - } |
|
17 | + /** |
|
18 | + * @param string $action |
|
19 | + * @param mixed $votingSubject |
|
20 | + * @param \SpareParts\Overseer\Context\IVotingContext $votingContext |
|
21 | + * @return \SpareParts\Overseer\IVotingResult |
|
22 | + * @throws \SpareParts\Overseer\InvalidVotingResultException |
|
23 | + */ |
|
24 | + public function vote($action, $votingSubject, IVotingContext $votingContext) |
|
25 | + { |
|
26 | + return $this->innerVote($action, $votingSubject, $votingContext); |
|
27 | + } |
|
28 | 28 | } |