@@ -4,58 +4,58 @@ |
||
4 | 4 | |
5 | 5 | final class VotingDecisionEnum |
6 | 6 | { |
7 | - /** |
|
8 | - * @var string |
|
9 | - */ |
|
10 | - private $value; |
|
11 | - |
|
12 | - /** |
|
13 | - * @var self[] |
|
14 | - */ |
|
15 | - static private $registry = []; |
|
16 | - |
|
17 | - private function __construct($value) |
|
18 | - { |
|
19 | - $this->value = $value; |
|
20 | - } |
|
21 | - |
|
22 | - |
|
23 | - /** |
|
24 | - * @return self |
|
25 | - */ |
|
26 | - public static function ALLOWED() |
|
27 | - { |
|
28 | - return static::instance('allowed'); |
|
29 | - } |
|
30 | - |
|
31 | - |
|
32 | - /** |
|
33 | - * @return self |
|
34 | - */ |
|
35 | - public static function DENIED() |
|
36 | - { |
|
37 | - return static::instance('denied'); |
|
38 | - } |
|
39 | - |
|
40 | - |
|
41 | - /** |
|
42 | - * @param $string |
|
43 | - * @return self |
|
44 | - */ |
|
45 | - private static function instance($string) |
|
46 | - { |
|
47 | - if (!isset(static::$registry[$string])) { |
|
48 | - static::$registry[$string] = new static($string); |
|
49 | - } |
|
50 | - return static::$registry[$string]; |
|
51 | - } |
|
52 | - |
|
53 | - |
|
54 | - /** |
|
55 | - * @return string |
|
56 | - */ |
|
57 | - public function __toString() |
|
58 | - { |
|
59 | - return $this->value; |
|
60 | - } |
|
7 | + /** |
|
8 | + * @var string |
|
9 | + */ |
|
10 | + private $value; |
|
11 | + |
|
12 | + /** |
|
13 | + * @var self[] |
|
14 | + */ |
|
15 | + static private $registry = []; |
|
16 | + |
|
17 | + private function __construct($value) |
|
18 | + { |
|
19 | + $this->value = $value; |
|
20 | + } |
|
21 | + |
|
22 | + |
|
23 | + /** |
|
24 | + * @return self |
|
25 | + */ |
|
26 | + public static function ALLOWED() |
|
27 | + { |
|
28 | + return static::instance('allowed'); |
|
29 | + } |
|
30 | + |
|
31 | + |
|
32 | + /** |
|
33 | + * @return self |
|
34 | + */ |
|
35 | + public static function DENIED() |
|
36 | + { |
|
37 | + return static::instance('denied'); |
|
38 | + } |
|
39 | + |
|
40 | + |
|
41 | + /** |
|
42 | + * @param $string |
|
43 | + * @return self |
|
44 | + */ |
|
45 | + private static function instance($string) |
|
46 | + { |
|
47 | + if (!isset(static::$registry[$string])) { |
|
48 | + static::$registry[$string] = new static($string); |
|
49 | + } |
|
50 | + return static::$registry[$string]; |
|
51 | + } |
|
52 | + |
|
53 | + |
|
54 | + /** |
|
55 | + * @return string |
|
56 | + */ |
|
57 | + public function __toString() |
|
58 | + { |
|
59 | + return $this->value; |
|
60 | + } |
|
61 | 61 | } |
62 | 62 | \ No newline at end of file |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | /** |
13 | 13 | * @var self[] |
14 | 14 | */ |
15 | - static private $registry = []; |
|
15 | + static private $registry = [ ]; |
|
16 | 16 | |
17 | 17 | private function __construct($value) |
18 | 18 | { |
@@ -53,10 +53,10 @@ discard block |
||
53 | 53 | */ |
54 | 54 | private static function instance($string) |
55 | 55 | { |
56 | - if (!isset(static::$registry[$string])) { |
|
57 | - static::$registry[$string] = new static($string); |
|
56 | + if (!isset(static::$registry[ $string ])) { |
|
57 | + static::$registry[ $string ] = new static($string); |
|
58 | 58 | } |
59 | - return static::$registry[$string]; |
|
59 | + return static::$registry[ $string ]; |
|
60 | 60 | } |
61 | 61 | |
62 | 62 |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | { |
90 | 90 | foreach ($this->voters as $voter) { |
91 | 91 | if (($lastResult = $voter->vote($votingSubject, $votingContext)) !== null) { |
92 | - return new VotingResult($lastResult->getDecision(), [$lastResult]); |
|
92 | + return new VotingResult($lastResult->getDecision(), [$lastResult]); |
|
93 | 93 | } |
94 | 94 | } |
95 | 95 | throw new InvalidVotingResultException('Voting assembly did not decide on any result!'); |
@@ -103,13 +103,13 @@ discard block |
||
103 | 103 | */ |
104 | 104 | private function strategyAllowUnlessDenied($votingSubject, $votingContext) |
105 | 105 | { |
106 | - $results = []; |
|
106 | + $results = []; |
|
107 | 107 | foreach ($this->voters as $name => $voter) { |
108 | 108 | if (($lastResult = $voter->vote($votingSubject, $votingContext)) !== null) { |
109 | - $results[] = $lastResult; |
|
110 | - if ($lastResult->getDecision() === VotingDecisionEnum::DENIED()) { |
|
111 | - return new VotingResult(VotingDecisionEnum::DENIED(), $results); |
|
112 | - } |
|
109 | + $results[] = $lastResult; |
|
110 | + if ($lastResult->getDecision() === VotingDecisionEnum::DENIED()) { |
|
111 | + return new VotingResult(VotingDecisionEnum::DENIED(), $results); |
|
112 | + } |
|
113 | 113 | } |
114 | 114 | } |
115 | 115 | return new VotingResult(VotingDecisionEnum::ALLOWED(), $results); |
@@ -123,16 +123,16 @@ discard block |
||
123 | 123 | */ |
124 | 124 | private function strategyDenyUnlessAllowed($votingSubject, $votingContext) |
125 | 125 | { |
126 | - $results = []; |
|
127 | - foreach ($this->voters as $name => $voter) { |
|
128 | - if (($lastResult = $voter->vote($votingSubject, $votingContext)) !== null) { |
|
129 | - $results[] = $lastResult; |
|
130 | - if ($lastResult->getDecision() === VotingDecisionEnum::ALLOWED()) { |
|
131 | - return new VotingResult(VotingDecisionEnum::ALLOWED(), $results); |
|
132 | - } |
|
133 | - } |
|
134 | - } |
|
135 | - return new VotingResult(VotingDecisionEnum::DENIED(), $results); |
|
126 | + $results = []; |
|
127 | + foreach ($this->voters as $name => $voter) { |
|
128 | + if (($lastResult = $voter->vote($votingSubject, $votingContext)) !== null) { |
|
129 | + $results[] = $lastResult; |
|
130 | + if ($lastResult->getDecision() === VotingDecisionEnum::ALLOWED()) { |
|
131 | + return new VotingResult(VotingDecisionEnum::ALLOWED(), $results); |
|
132 | + } |
|
133 | + } |
|
134 | + } |
|
135 | + return new VotingResult(VotingDecisionEnum::DENIED(), $results); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 |