Skip to content

Commit 5a4fbe1

Browse files
committed
correct cs
voter has vote and getvote tests correction update
1 parent 3dcdb19 commit 5a4fbe1

37 files changed

+973
-241
lines changed

src/Symfony/Component/Security/Core/Authorization/AccessDecision.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ public function isDenied(): bool
5151
return VoterInterface::ACCESS_DENIED === $this->access;
5252
}
5353

54-
5554
/**
5655
* @return string[]
5756
*/
@@ -99,4 +98,4 @@ private function getVotesByAccess(int $access): array
9998
{
10099
return array_filter($this->votes, static fn (Vote $vote): bool => $vote->getAccess() === $access);
101100
}
102-
}
101+
}

src/Symfony/Component/Security/Core/Authorization/AccessDecisionManager.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function getDecision(TokenInterface $token, array $attributes, mixed $obj
4545
{
4646
// Special case for AccessListener, do not remove the right side of the condition before 6.0
4747
if (\count($attributes) > 1 && !$allowMultipleAttributes) {
48-
throw new InvalidArgumentException(sprintf('Passing more than one Security attribute to "%s()" is not supported.', __METHOD__));
48+
throw new InvalidArgumentException(\sprintf('Passing more than one Security attribute to "%s()" is not supported.', __METHOD__));
4949
}
5050

5151
if (method_exists($this->strategy, 'getDecision')) {
@@ -83,12 +83,11 @@ public function decide(TokenInterface $token, array $attributes, mixed $object =
8383
private function collectVotes(TokenInterface $token, array $attributes, mixed $object): \Traversable
8484
{
8585
foreach ($this->getVoters($attributes, $object) as $voter) {
86-
$vote = $voter->vote($token, $object, $attributes);
87-
if (! $vote instanceOf Vote)
88-
{
89-
$vote = new Vote($vote);
86+
if(method_exists($voter, 'getVote')) {
87+
yield $voter->getVote($token, $object, $attributes);
88+
} else {
89+
yield new Vote($voter->vote($token, $object, $attributes));
9090
}
91-
yield $vote;
9291
}
9392
}
9493

src/Symfony/Component/Security/Core/Authorization/AuthorizationCheckerInterface.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace Symfony\Component\Security\Core\Authorization;
1313

14-
use Symfony\Component\Security\Core\Authorization\AccessDecision;
1514
/**
1615
* The AuthorizationCheckerInterface.
1716
*

src/Symfony/Component/Security/Core/Authorization/Strategy/AffirmativeStrategy.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111

1212
namespace Symfony\Component\Security\Core\Authorization\Strategy;
1313

14+
use Symfony\Component\Security\Core\Authorization\AccessDecision;
1415
use Symfony\Component\Security\Core\Authorization\Voter\Vote;
1516
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
16-
use Symfony\Component\Security\Core\Authorization\AccessDecision;
1717

1818
/**
1919
* Grants access if any voter returns an affirmative response.
@@ -33,7 +33,7 @@ public function __construct(
3333

3434
public function decide(\Traversable $results): bool
3535
{
36-
return $this->getDecision(new \ArrayIterator(array_map(fn($vote) => new Vote($vote), iterator_to_array($results))))->isGranted();
36+
return $this->getDecision(new \ArrayIterator(array_map(fn ($vote) => new Vote($vote), iterator_to_array($results))))->isGranted();
3737
}
3838

3939
public function getDecision(\Traversable $votes): AccessDecision
@@ -46,7 +46,7 @@ public function getDecision(\Traversable $votes): AccessDecision
4646
$currentVotes[] = $vote;
4747

4848
if ($vote->isGranted()) {
49-
return new AccessDecision(VoterInterface::ACCESS_GRANTED,$currentVotes);
49+
return new AccessDecision(VoterInterface::ACCESS_GRANTED, $currentVotes);
5050
}
5151

5252
if ($vote->isDenied()) {
@@ -55,10 +55,10 @@ public function getDecision(\Traversable $votes): AccessDecision
5555
}
5656

5757
if ($deny > 0) {
58-
return new AccessDecision(VoterInterface::ACCESS_DENIED,$currentVotes);
58+
return new AccessDecision(VoterInterface::ACCESS_DENIED, $currentVotes);
5959
}
6060

61-
return new AccessDecision($this->allowIfAllAbstainDecisions ? VoterInterface::ACCESS_GRANTED : VoterInterface::ACCESS_DENIED,$currentVotes);
61+
return new AccessDecision($this->allowIfAllAbstainDecisions ? VoterInterface::ACCESS_GRANTED : VoterInterface::ACCESS_DENIED, $currentVotes);
6262
}
6363

6464
public function __toString(): string

src/Symfony/Component/Security/Core/Authorization/Strategy/ConsensusStrategy.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function __construct(
4242

4343
public function decide(\Traversable $results): bool
4444
{
45-
return $this->getDecision(new \ArrayIterator(array_map(fn($vote) => new Vote($vote), iterator_to_array($results))))->isGranted();
45+
return $this->getDecision(new \ArrayIterator(array_map(fn ($vote) => new Vote($vote), iterator_to_array($results))))->isGranted();
4646
}
4747

4848
public function getDecision(\Traversable $votes): AccessDecision
@@ -62,18 +62,18 @@ public function getDecision(\Traversable $votes): AccessDecision
6262
}
6363

6464
if ($grant > $deny) {
65-
return new AccessDecision(VoterInterface::ACCESS_GRANTED,$currentVotes);
65+
return new AccessDecision(VoterInterface::ACCESS_GRANTED, $currentVotes);
6666
}
6767

6868
if ($deny > $grant) {
69-
return new AccessDecision(VoterInterface::ACCESS_DENIED,$currentVotes);
69+
return new AccessDecision(VoterInterface::ACCESS_DENIED, $currentVotes);
7070
}
7171

7272
if ($grant > 0) {
73-
return new AccessDecision($this->allowIfEqualGrantedDeniedDecisions ? VoterInterface::ACCESS_GRANTED : VoterInterface::ACCESS_DENIED,$currentVotes);
73+
return new AccessDecision($this->allowIfEqualGrantedDeniedDecisions ? VoterInterface::ACCESS_GRANTED : VoterInterface::ACCESS_DENIED, $currentVotes);
7474
}
7575

76-
return new AccessDecision($this->allowIfAllAbstainDecisions ? VoterInterface::ACCESS_GRANTED : VoterInterface::ACCESS_DENIED,$currentVotes);
76+
return new AccessDecision($this->allowIfAllAbstainDecisions ? VoterInterface::ACCESS_GRANTED : VoterInterface::ACCESS_DENIED, $currentVotes);
7777
}
7878

7979
public function __toString(): string

src/Symfony/Component/Security/Core/Authorization/Strategy/PriorityStrategy.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function __construct(
3434

3535
public function decide(\Traversable $results): bool
3636
{
37-
return $this->getDecision(new \ArrayIterator(array_map(fn($vote) => new Vote($vote), iterator_to_array($results))))->isGranted();
37+
return $this->getDecision(new \ArrayIterator(array_map(fn ($vote) => new Vote($vote), iterator_to_array($results))))->isGranted();
3838
}
3939

4040
public function getDecision(\Traversable $votes): AccessDecision
@@ -45,15 +45,15 @@ public function getDecision(\Traversable $votes): AccessDecision
4545
foreach ($votes as $vote) {
4646
$currentVotes[] = $vote;
4747
if ($vote->isGranted()) {
48-
return new AccessDecision(VoterInterface::ACCESS_GRANTED,$currentVotes);
48+
return new AccessDecision(VoterInterface::ACCESS_GRANTED, $currentVotes);
4949
}
5050

5151
if ($vote->isDenied()) {
52-
return new AccessDecision(VoterInterface::ACCESS_DENIED,$currentVotes);
52+
return new AccessDecision(VoterInterface::ACCESS_DENIED, $currentVotes);
5353
}
5454
}
5555

56-
return new AccessDecision($this->allowIfAllAbstainDecisions ? VoterInterface::ACCESS_GRANTED : VoterInterface::ACCESS_DENIED,$currentVotes);
56+
return new AccessDecision($this->allowIfAllAbstainDecisions ? VoterInterface::ACCESS_GRANTED : VoterInterface::ACCESS_DENIED, $currentVotes);
5757
}
5858

5959
public function __toString(): string

src/Symfony/Component/Security/Core/Authorization/Strategy/ScoringStrategy.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
1717

1818
/**
19-
* Grants access if vote results greated than 0
19+
* Grants access if vote results greated than 0.
2020
*
2121
* If all voters abstained from voting, the decision will be based on the
2222
* allowIfAllAbstainDecisions property value (defaults to false).
@@ -32,7 +32,7 @@ public function __construct(
3232

3333
public function decide(\Traversable $results): bool
3434
{
35-
return $this->getDecision(new \ArrayIterator(array_map(fn($vote) => new Vote($vote), iterator_to_array($results))))->isGranted();
35+
return $this->getDecision(new \ArrayIterator(array_map(fn ($vote) => new Vote($vote), iterator_to_array($results))))->isGranted();
3636
}
3737

3838
public function getDecision(\Traversable $votes): AccessDecision
@@ -47,14 +47,14 @@ public function getDecision(\Traversable $votes): AccessDecision
4747
}
4848

4949
if ($score > 0) {
50-
return new AccessDecision(VoterInterface::ACCESS_GRANTED,$currentVotes, 'score = ' . $score);
50+
return new AccessDecision(VoterInterface::ACCESS_GRANTED, $currentVotes, 'score = '.$score);
5151
}
5252

5353
if ($score < 0) {
54-
return new AccessDecision(VoterInterface::ACCESS_DENIED,$currentVotes, 'score = ' . $score);
54+
return new AccessDecision(VoterInterface::ACCESS_DENIED, $currentVotes, 'score = '.$score);
5555
}
5656

57-
return new AccessDecision($this->allowIfAllAbstainDecisions ? VoterInterface::ACCESS_GRANTED : VoterInterface::ACCESS_DENIED,$currentVotes);
57+
return new AccessDecision($this->allowIfAllAbstainDecisions ? VoterInterface::ACCESS_GRANTED : VoterInterface::ACCESS_DENIED, $currentVotes);
5858
}
5959

6060
public function __toString(): string

src/Symfony/Component/Security/Core/Authorization/Strategy/UnanimousStrategy.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function __construct(
3333

3434
public function decide(\Traversable $results): bool
3535
{
36-
return $this->getDecision(new \ArrayIterator(array_map(fn($vote) => new Vote($vote), iterator_to_array($results))))->isGranted();
36+
return $this->getDecision(new \ArrayIterator(array_map(fn ($vote) => new Vote($vote), iterator_to_array($results))))->isGranted();
3737
}
3838

3939
public function getDecision(\Traversable $votes): AccessDecision
@@ -46,7 +46,7 @@ public function getDecision(\Traversable $votes): AccessDecision
4646
$currentVotes[] = $vote;
4747

4848
if ($vote->isDenied()) {
49-
return new AccessDecision(VoterInterface::ACCESS_DENIED,$currentVotes);
49+
return new AccessDecision(VoterInterface::ACCESS_DENIED, $currentVotes);
5050
}
5151

5252
if ($vote->isGranted()) {
@@ -56,10 +56,10 @@ public function getDecision(\Traversable $votes): AccessDecision
5656

5757
// no deny votes
5858
if ($grant > 0) {
59-
return new AccessDecision(VoterInterface::ACCESS_GRANTED,$currentVotes);
59+
return new AccessDecision(VoterInterface::ACCESS_GRANTED, $currentVotes);
6060
}
6161

62-
return new AccessDecision($this->allowIfAllAbstainDecisions ? VoterInterface::ACCESS_GRANTED : VoterInterface::ACCESS_DENIED,$currentVotes);
62+
return new AccessDecision($this->allowIfAllAbstainDecisions ? VoterInterface::ACCESS_GRANTED : VoterInterface::ACCESS_DENIED, $currentVotes);
6363
}
6464

6565
public function __toString(): string

src/Symfony/Component/Security/Core/Authorization/TraceableAccessDecisionManager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ public function decide(TokenInterface $token, array $attributes, mixed $object =
8888
/**
8989
* Adds voter vote and class to the voter details.
9090
*
91-
* @param array $attributes attributes used for the vote
92-
* @param VoteInterface|int $vote vote of the voter
91+
* @param array $attributes attributes used for the vote
92+
* @param VoteInterface|int $vote vote of the voter
9393
*/
9494
public function addVoterVote(VoterInterface $voter, array $attributes, VoteInterface|int $vote): void
9595
{

src/Symfony/Component/Security/Core/Authorization/Voter/AuthenticatedVoter.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,17 @@ public function __construct(
3939
}
4040

4141
public function vote(TokenInterface $token, mixed $subject, array $attributes): int
42+
{
43+
return $this->getVote($token, $subject, $attributes)->getAccess();
44+
}
45+
46+
public function getVote(TokenInterface $token, mixed $subject, array $attributes): VoteInterface
4247
{
4348
if ($attributes === [self::PUBLIC_ACCESS]) {
44-
return VoterInterface::ACCESS_GRANTED;
49+
return new Vote(VoterInterface::ACCESS_GRANTED);
4550
}
4651

47-
$result = VoterInterface::ACCESS_ABSTAIN;
52+
$result = new Vote(VoterInterface::ACCESS_ABSTAIN);
4853
foreach ($attributes as $attribute) {
4954
if (null === $attribute || (self::IS_AUTHENTICATED_FULLY !== $attribute
5055
&& self::IS_AUTHENTICATED_REMEMBERED !== $attribute
@@ -54,29 +59,29 @@ public function vote(TokenInterface $token, mixed $subject, array $attributes):
5459
continue;
5560
}
5661

57-
$result = VoterInterface::ACCESS_DENIED;
62+
$result = new Vote(VoterInterface::ACCESS_DENIED);
5863

5964
if (self::IS_AUTHENTICATED_FULLY === $attribute
6065
&& $this->authenticationTrustResolver->isFullFledged($token)) {
61-
return VoterInterface::ACCESS_GRANTED;
66+
return new Vote(VoterInterface::ACCESS_GRANTED);
6267
}
6368

6469
if (self::IS_AUTHENTICATED_REMEMBERED === $attribute
6570
&& ($this->authenticationTrustResolver->isRememberMe($token)
6671
|| $this->authenticationTrustResolver->isFullFledged($token))) {
67-
return VoterInterface::ACCESS_GRANTED;
72+
return new Vote(VoterInterface::ACCESS_GRANTED);
6873
}
6974

7075
if (self::IS_AUTHENTICATED === $attribute && $this->authenticationTrustResolver->isAuthenticated($token)) {
71-
return VoterInterface::ACCESS_GRANTED;
76+
return new Vote(VoterInterface::ACCESS_GRANTED);
7277
}
7378

7479
if (self::IS_REMEMBERED === $attribute && $this->authenticationTrustResolver->isRememberMe($token)) {
75-
return VoterInterface::ACCESS_GRANTED;
80+
return new Vote(VoterInterface::ACCESS_GRANTED);
7681
}
7782

7883
if (self::IS_IMPERSONATOR === $attribute && $token instanceof SwitchUserToken) {
79-
return VoterInterface::ACCESS_GRANTED;
84+
return new Vote(VoterInterface::ACCESS_GRANTED);
8085
}
8186
}
8287

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy