@@ -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 | } |
@@ -10,64 +10,64 @@ |
||
| 10 | 10 | class VotingAbilityAwareAssembly extends VotingAssembly implements IVotingAbilityAwareAssembly |
| 11 | 11 | { |
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * @var string |
|
| 15 | - */ |
|
| 16 | - protected $subjectClassName; |
|
| 13 | + /** |
|
| 14 | + * @var string |
|
| 15 | + */ |
|
| 16 | + protected $subjectClassName; |
|
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * @var string |
|
| 20 | - */ |
|
| 21 | - protected $contextClassName; |
|
| 18 | + /** |
|
| 19 | + * @var string |
|
| 20 | + */ |
|
| 21 | + protected $contextClassName; |
|
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * @var string[] |
|
| 25 | - */ |
|
| 26 | - protected $actionList; |
|
| 23 | + /** |
|
| 24 | + * @var string[] |
|
| 25 | + */ |
|
| 26 | + protected $actionList; |
|
| 27 | 27 | |
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * @param \SpareParts\Overseer\StrategyEnum $strategy |
|
| 31 | - * @param IVoter[] $voters |
|
| 32 | - * @param string|string[] $actions |
|
| 33 | - * @param string $contextClassName |
|
| 34 | - * @param string $subjectClassName |
|
| 35 | - */ |
|
| 36 | - public function __construct( |
|
| 37 | - StrategyEnum $strategy, |
|
| 38 | - array $voters, |
|
| 39 | - $actions = null, |
|
| 40 | - $contextClassName = IIdentityContext::class, |
|
| 41 | - $subjectClassName = null |
|
| 42 | - ) { |
|
| 43 | - parent::__construct($strategy, $voters); |
|
| 29 | + /** |
|
| 30 | + * @param \SpareParts\Overseer\StrategyEnum $strategy |
|
| 31 | + * @param IVoter[] $voters |
|
| 32 | + * @param string|string[] $actions |
|
| 33 | + * @param string $contextClassName |
|
| 34 | + * @param string $subjectClassName |
|
| 35 | + */ |
|
| 36 | + public function __construct( |
|
| 37 | + StrategyEnum $strategy, |
|
| 38 | + array $voters, |
|
| 39 | + $actions = null, |
|
| 40 | + $contextClassName = IIdentityContext::class, |
|
| 41 | + $subjectClassName = null |
|
| 42 | + ) { |
|
| 43 | + parent::__construct($strategy, $voters); |
|
| 44 | 44 | |
| 45 | - $this->actionList = (array) $actions; |
|
| 46 | - $this->subjectClassName = $subjectClassName; |
|
| 47 | - $this->contextClassName = $contextClassName; |
|
| 48 | - } |
|
| 45 | + $this->actionList = (array) $actions; |
|
| 46 | + $this->subjectClassName = $subjectClassName; |
|
| 47 | + $this->contextClassName = $contextClassName; |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @param string $actionName |
|
| 53 | - * @param object $subject |
|
| 54 | - * @param \SpareParts\Overseer\Context\IVotingContext $context |
|
| 55 | - * @return bool |
|
| 56 | - */ |
|
| 57 | - public function canVoteOn($actionName, $subject, IVotingContext $context) |
|
| 58 | - { |
|
| 59 | - if ($this->subjectClassName && !($subject instanceof $this->subjectClassName)) { |
|
| 60 | - return false; |
|
| 61 | - } |
|
| 51 | + /** |
|
| 52 | + * @param string $actionName |
|
| 53 | + * @param object $subject |
|
| 54 | + * @param \SpareParts\Overseer\Context\IVotingContext $context |
|
| 55 | + * @return bool |
|
| 56 | + */ |
|
| 57 | + public function canVoteOn($actionName, $subject, IVotingContext $context) |
|
| 58 | + { |
|
| 59 | + if ($this->subjectClassName && !($subject instanceof $this->subjectClassName)) { |
|
| 60 | + return false; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - if ($this->contextClassName && !($context instanceof $this->contextClassName)) { |
|
| 64 | - return false; |
|
| 65 | - } |
|
| 63 | + if ($this->contextClassName && !($context instanceof $this->contextClassName)) { |
|
| 64 | + return false; |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - if ($this->actionList && !in_array($actionName, $this->actionList)) { |
|
| 68 | - return false; |
|
| 69 | - } |
|
| 70 | - return true; |
|
| 71 | - } |
|
| 67 | + if ($this->actionList && !in_array($actionName, $this->actionList)) { |
|
| 68 | + return false; |
|
| 69 | + } |
|
| 70 | + return true; |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | 73 | } |
@@ -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 | } |
@@ -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 | } |