Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d576797

Browse filesBrowse files
minor #49033 [Security] Introduce template for Voter phpdoc (VincentLanglet)
This PR was merged into the 6.3 branch. Discussion ---------- [Security] Introduce template for Voter phpdoc | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | no | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | Fix #... <!-- prefix each issue number with "Fix #", no need to create an issue if none exists, explain below instead --> | License | MIT | Doc PR | symfony/symfony-docs#... <!-- required for new features --> This template allows phpstan/psam/PHPStorm to fully understand the type of `$attribute` and `$subject` when writing a Voter. For instance, if I write ``` return $subject instance User && $attribute === 'EDIT'; ``` I can annotate the Voter as `Voter<'EDIT', User>` and - Static analysis will check that supports is doing the right checks. - PHPStorm will autocomplete calls like `$subject->getId()` when writing inside the `voteOnAttribute`. - SA tools will not complain about non existing methods on mixed. The last two points are considered as valid because of the comment > It is safe to assume that $attribute and $subject already passed the "supports()" method check. Since this is an important point for Sf, all those annotations are supported by both psalm and phpstan, and understood (or ignored for psalm-assert-if-true) by PHPStorm. Commits ------- a51b7fa Introduce stub for Voter
2 parents 2ee39b3 + a51b7fa commit d576797
Copy full SHA for d576797

File tree

Expand file treeCollapse file tree

1 file changed

+10
-1
lines changed
Filter options
  • src/Symfony/Component/Security/Core/Authorization/Voter
Expand file treeCollapse file tree

1 file changed

+10
-1
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Core/Authorization/Voter/Voter.php
+10-1Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
*
1919
* @author Roman Marintšenko <inoryy@gmail.com>
2020
* @author Grégoire Pineau <lyrixx@lyrixx.info>
21+
*
22+
* @template TAttribute of string
23+
* @template TSubject of mixed
2124
*/
2225
abstract class Voter implements VoterInterface, CacheableVoterInterface
2326
{
@@ -74,13 +77,19 @@ public function supportsType(string $subjectType): bool
7477
/**
7578
* Determines if the attribute and subject are supported by this voter.
7679
*
77-
* @param $subject The subject to secure, e.g. an object the user wants to access or any other PHP type
80+
* @param mixed $subject The subject to secure, e.g. an object the user wants to access or any other PHP type
81+
*
82+
* @psalm-assert-if-true TSubject $subject
83+
* @psalm-assert-if-true TAttribute $attribute
7884
*/
7985
abstract protected function supports(string $attribute, mixed $subject): bool;
8086

8187
/**
8288
* Perform a single access check operation on a given attribute, subject and token.
8389
* It is safe to assume that $attribute and $subject already passed the "supports()" method check.
90+
*
91+
* @param TAttribute $attribute
92+
* @param TSubject $subject
8493
*/
8594
abstract protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token): bool;
8695
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.