8000 psalm correction · symfony/symfony@ed7ef4d · GitHub
[go: up one dir, main page]

Skip to content

Commit ed7ef4d

Browse files
committed
psalm correction
fabpot use interface
1 parent dbdad7b commit ed7ef4d

14 files changed

+54
-24
lines changed

src/Symfony/Bundle/SecurityBundle/Tests/DataCollector/SecurityDataCollectorTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,4 +464,8 @@ final class DummyVoter implements VoterInterface
464464
public function vote(TokenInterface $token, mixed $subject, array $attributes): int
465465
{
466466
}
467+
468+
public function getVote(TokenInterface $token, mixed $subject, array $attributes): VoterInterface
469+
{
470+
}
467471
}

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

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111

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

14-
use Symfony\Component\Security\Core\Authorization\Voter\Vote;
15-
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
14+
use Symfony\Component\Security\Core\Authorization\Voter\VoteInterface;
1615
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
1716

1817
/**
@@ -24,8 +23,8 @@
2423
final class AccessDecision
2524
{
2625
/**
27-
* @param int $access One of the VoterInterface constants (ACCESS_GRANTED, ACCESS_ABSTAIN, ACCESS_DENIED)
28-
* @param Vote[] $votes
26+
* @param int $access One of the VoterInterface constants (ACCESS_GRANTED, ACCESS_ABSTAIN, ACCESS_DENIED)
27+
* @param VoteInterface[] $votes
2928
*/
3029
public function __construct(
3130
private readonly int $access,
@@ -60,42 +59,42 @@ public function getMessage(): string
6059
}
6160

6261
/**
63-
* @return Vote[]
62+
* @return VoteInterface[]
6463
*/
6564
public function getVotes(): array
6665
{
6766
return $this->votes;
6867
}
6968

7069
/**
71-
* @return Vote[]
70+
* @return VoteInterface[]
7271
*/
7372
public function getGrantedVotes(): array
7473
{
75-
return $this->getVotesByAccess(Voter::ACCESS_GRANTED);
74+
return $this->getVotesByAccess(VoterInterface::ACCESS_GRANTED);
7675
}
7776

7877
/**
79-
* @return Vote[]
78+
* @return VoteInterface[]
8079
*/
8180
public function getAbstainedVotes(): array
8281
{
83-
return $this->getVotesByAccess(Voter::ACCESS_ABSTAIN);
82+
return $this->getVotesByAccess(VoterInterface::ACCESS_ABSTAIN);
8483
}
8584

8685
/**
87-
* @return Vote[]
86+
* @return VoteInterface[]
8887
*/
8988
public function getDeniedVotes(): array
9089
{
91-
return $this->getVotesByAccess(Voter::ACCESS_DENIED);
90+
return $this->getVotesByAccess(VoterInterface::ACCESS_DENIED);
9291
}
9392

9493
/**
95-
* @return Vote[]
94+
* @return VoteInterface[]
9695
*/
9796
private function getVotesByAccess(int $access): array
9897
{
99-
return array_filter($this->votes, static fn (Vote $vote): bool => $vote->getAccess() === $access);
98+
return array_filter($this->votes, static fn (VoteInterface $vote): bool => $vote->getAccess() === $access);
10099
}
101100
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Component\Security\Core\Authorization\AccessDecision;
1515
use Symfony\Component\Security\Core\Authorization\Voter\Vote;
16+
use Symfony\Component\Security\Core\Authorization\Voter\VoteInterface;
1617
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
1718

1819
/**
@@ -41,7 +42,7 @@ public function getDecision(\Traversable $votes): AccessDecision
4142
$currentVotes = [];
4243
$deny = 0;
4344

44-
/** @var Vote $vote */
45+
/** @var VoteInterface $vote */
4546
foreach ($votes as $vote) {
4647
$currentVotes[] = $vote;
4748

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Component\Security\Core\Authorization\AccessDecision;
1515
use Symfony\Component\Security\Core\Authorization\Voter\Vote;
16+
use Symfony\Component\Security\Core\Authorization\Voter\VoteInterface;
1617
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
1718

1819
/**
@@ -51,7 +52,7 @@ public function getDecision(\Traversable $votes): AccessDecision
5152
$grant = 0;
5253
$deny = 0;
5354

54-
/** @var Vote $vote */
55+
/** @var VoteInterface $vote */
5556
foreach ($votes as $vote) {
5657
$currentVotes[] = $vote;
5758
if ($vote->isGranted()) {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Component\Security\Core\Authorization\AccessDecision;
1515
use Symfony\Component\Security\Core\Authorization\Voter\Vote;
16+
use Symfony\Component\Security\Core\Authorization\Voter\VoteInterface;
1617
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
1718

1819
/**
@@ -41,7 +42,7 @@ public function getDecision(\Traversable $votes): AccessDecision
4142
{
4243
$currentVotes = [];
4344

44-
/** @var Vote $vote */
45+
/** @var VoteInterface $vote */
4546
foreach ($votes as $vote) {
4647
$currentVotes[] = $vote;
4748
if ($vote->isGranted()) {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Component\Security\Core\Authorization\AccessDecision;
1515
use Symfony\Component\Security\Core\Authorization\Voter\Vote;
16+
use Symfony\Component\Security\Core\Authorization\Voter\VoteInterface;
1617
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
1718

1819
/**
@@ -40,7 +41,7 @@ public function getDecision(\Traversable $votes): AccessDecision
4041
$currentVotes = [];
4142
$score = 0;
4243

43-
/** @var Vote $vote */
44+
/** @var VoteInterface $vote */
4445
foreach ($votes as $vote) {
4546
$currentVotes[] = $vote;
4647
$score += $vote->getAccess();

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Component\Security\Core\Authorization\AccessDecision;
1515
use Symfony\Component\Security\Core\Authorization\Voter\Vote;
16+
use Symfony\Component\Security\Core\Authorization\Voter\VoteInterface;
1617
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
1718

1819
/**
@@ -41,7 +42,7 @@ public function getDecision(\Traversable $votes): AccessDecision
4142
$currentVotes = [];
4243
$grant = 0;
4344

44-
/** @var Vote $vote */
45+
/** @var VoteInterface $vote */
4546
foreach ($votes as $vote) {
4647
$currentVotes[] = $vote;
4748

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public function decide(TokenInterface $token, array $attributes, mixed $object =
9393
*/
9494
public function addVoterVote(VoterInterface $voter, array $attributes, VoteInterface|int $vote): void
9595
{
96-
if (!$vote instanceof Vote) {
96+
if (!$vote instanceof VoteInterface) {
9797
$vote = new Vote($vote);
9898
}
9999

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*
1919
* @author Fabien Potencier <fabien@symfony.com>
2020
*
21-
* method Vote getVote(TokenInterface $token, mixed $subject, array $attributes)
21+
* @method VoteInterface getVote(TokenInterface $token, mixed $subject, array $attributes)
2222
*/
2323
interface VoterInterface
2424
{

src/Symfony/Component/Security/Core/Event/VoteEvent.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@
2525
*/
2626
final class VoteEvent extends Event
2727
{
28+
private VoteInterface $vote;
29+
2830
public function __construct(
2931
private VoterInterface $voter,
3032
private mixed $subject,
3133
private array $attributes,
32-
private Vote|int $vote,
34+
VoteInterface|int $vote,
3335
) {
34-
if (!$vote instanceof Vote) {
35-
$this->vote = new Vote($vote);
36-
}
36+
$this->vote = $vote instanceof VoteInterface ? $vote : new Vote($vote);
3737
}
3838

3939
public function getVoter(): VoterInterface

src/Symfony/Component/Security/Core/Test/AccessDecisionStrategyTestCase.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Symfony\Component\Security\Core\Authorization\Strategy\AccessDecisionStrategyInterface;
2020
use Symfony\Component\Security\Core\Authorization\Voter\Vote;
2121
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
22+
use Symfony\Component\Security\Core\Exception\LogicException;
2223

2324
/**
2425
* Abstract test case for access decision strategies.
@@ -93,6 +94,11 @@ public function vote(TokenInterface $token, $subject, array $attributes): int
9394
{
9495
return $this->vote;
9596
}
97+
98+
public function __call($function, $args)
99+
{
100+
throw new LogicException('This function must not be acceded.');
101+
}
96102
};
97103
}
98104

src/Symfony/Component/Security/Core/Tests/Authorization/AccessDecisionManagerTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,11 @@ public function vote(TokenInterface $token, $subject, array $attributes): int
354354
{
355355
return $this->vote;
356356
}
357+
358+
public function __call($function, $args)
359+
{
360+
throw new LogicException('This function must not be acceded.');
361+
}
357362
};
358363
}
359364

src/Symfony/Component/Security/Core/Tests/Authorization/Strategy/ScoringStrategyTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Symfony\Component\Security\Core\Authorization\Voter\Vote;
1212
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
1313
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
14+
use Symfony\Component\Security\Core\Exception\LogicException;
1415

1516
class ScoringStrategyTest extends TestCase
1617
{
@@ -100,6 +101,11 @@ public function vote(TokenInterface $token, $subject, array $attributes): int
100101
{
101102
return $this->vote;
102103
}
104+
105+
public function __call($function, $args)
106+
{
107+
throw new LogicException('This function must not be acceded.');
108+
}
103109
};
104110
}
105111

src/Symfony/Component/Security/Core/Tests/Fixtures/DummyVoter.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,16 @@
1212
namespace Symfony\Component\Security\Core\Tests\Fixtures;
1313

1414
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
15+
use Symfony\Component\Security\Core\Authorization\Voter\Vote;
1516
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
1617

1718
final class DummyVoter implements VoterInterface
1819
{
1920
public function vote(TokenInterface $token, $subject, array $attributes): int
2021
{
2122
}
23+
24+
public function getVote(TokenInterface $token, mixed $subject, array $attributes): VoterInterface
25+
{
26+
}
2227
}

0 commit comments

Comments
 (0)
0