You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
0 commit comments