Completed
Pull Request — master (#4)
by Ondrej
01:56
created
src/AbstractVotingManager.php 2 patches
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -6,42 +6,42 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -42,6 +42,6 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
src/Context/IdentityContext.php 1 patch
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -7,43 +7,43 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
src/Context/IIdentityContext.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -7,14 +7,14 @@
 block discarded – undo
7 7
 interface IIdentityContext extends IVotingContext
8 8
 {
9 9
 
10
-    /**
11
-     * @return string|int|null
12
-     */
13
-    public function getId();
10
+	/**
11
+	 * @return string|int|null
12
+	 */
13
+	public function getId();
14 14
 
15 15
 
16
-    /**
17
-     * @return string[]
18
-     */
19
-    public function getRoles();
16
+	/**
17
+	 * @return string[]
18
+	 */
19
+	public function getRoles();
20 20
 }
Please login to merge, or discard this patch.
src/Voter/RoleVoter.php 2 patches
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -8,50 +8,50 @@
 block discarded – undo
8 8
 
9 9
 final class RoleVoter implements IVoter
10 10
 {
11
-    /**
12
-     * @var string[]
13
-     */
14
-    private $allowedRoles;
15
-
16
-    /**
17
-     * @var VotingDecisionEnum
18
-     */
19
-    private $resultDecision;
20
-
21
-    /**
22
-     * @var mixed|null
23
-     */
24
-    private $reason;
25
-
26
-
27
-    /**
28
-     * RoleVoter constructor.
29
-     * @param VotingDecisionEnum $resultDecision
30
-     * @param string|string[] $allowedRoles
31
-     * @param mixed $reason
32
-     */
33
-    public function __construct(VotingDecisionEnum $resultDecision, $allowedRoles, $reason = null)
34
-    {
35
-        $this->allowedRoles = (array) $allowedRoles;
36
-        $this->resultDecision = $resultDecision;
37
-        $this->reason = $reason;
38
-    }
39
-
40
-
41
-    /**
42
-     * @param mixed $votingSubject
43
-     * @param \SpareParts\Overseer\Context\IVotingContext $votingContext
44
-     * @return ISingleVoterResult
45
-     */
46
-    public function vote($votingSubject, IVotingContext $votingContext)
47
-    {
48
-        if (!($votingContext instanceof IIdentityContext)) {
49
-            throw new InvalidArgumentException('RoleVoter can be used only with specific voting context, implementing IIdentityContext.');
50
-        }
51
-
52
-        if (array_intersect($votingContext->getRoles(), $this->allowedRoles)) {
53
-            return new SingleVoterResult($this->resultDecision, $this->reason);
54
-        }
55
-        return null;
56
-    }
11
+	/**
12
+	 * @var string[]
13
+	 */
14
+	private $allowedRoles;
15
+
16
+	/**
17
+	 * @var VotingDecisionEnum
18
+	 */
19
+	private $resultDecision;
20
+
21
+	/**
22
+	 * @var mixed|null
23
+	 */
24
+	private $reason;
25
+
26
+
27
+	/**
28
+	 * RoleVoter constructor.
29
+	 * @param VotingDecisionEnum $resultDecision
30
+	 * @param string|string[] $allowedRoles
31
+	 * @param mixed $reason
32
+	 */
33
+	public function __construct(VotingDecisionEnum $resultDecision, $allowedRoles, $reason = null)
34
+	{
35
+		$this->allowedRoles = (array) $allowedRoles;
36
+		$this->resultDecision = $resultDecision;
37
+		$this->reason = $reason;
38
+	}
39
+
40
+
41
+	/**
42
+	 * @param mixed $votingSubject
43
+	 * @param \SpareParts\Overseer\Context\IVotingContext $votingContext
44
+	 * @return ISingleVoterResult
45
+	 */
46
+	public function vote($votingSubject, IVotingContext $votingContext)
47
+	{
48
+		if (!($votingContext instanceof IIdentityContext)) {
49
+			throw new InvalidArgumentException('RoleVoter can be used only with specific voting context, implementing IIdentityContext.');
50
+		}
51
+
52
+		if (array_intersect($votingContext->getRoles(), $this->allowedRoles)) {
53
+			return new SingleVoterResult($this->resultDecision, $this->reason);
54
+		}
55
+		return null;
56
+	}
57 57
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@
 block discarded – undo
32 32
      */
33 33
     public function __construct(VotingDecisionEnum $resultDecision, $allowedRoles, $reason = null)
34 34
     {
35
-        $this->allowedRoles = (array) $allowedRoles;
35
+        $this->allowedRoles = (array)$allowedRoles;
36 36
         $this->resultDecision = $resultDecision;
37 37
         $this->reason = $reason;
38 38
     }
Please login to merge, or discard this patch.
src/Voter/IVoter.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -6,10 +6,10 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
src/Voter/ClosureVoter.php 1 patch
Indentation   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -8,54 +8,54 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
src/Voter/ConstVoter.php 1 patch
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -8,36 +8,36 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
src/IVotingResult.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -5,8 +5,8 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
src/GenericVotingManager.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -14,15 +14,15 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.