-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[Security] Introduce template for Voter phpdoc #49033
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
a69cb3b
to
a51b7fa
Compare
Thank you @VincentLanglet. |
Sorry for an old ping. Am I missing something or we dont have support for a Voter that has more than one attribute. Right? |
Not sure if this PR is the right forum for that question, but… Sure, a voter can support more than one attribute. |
I know, I should have opened an issue.
Yes, but this feature does not support that as far as I an see. Ie, I dot know what php doc annotation I can write to this class. class ProjectVoter extends Voter
{
public const VIEW = 'project_view';
public const WRITE = 'project_write';
public const ADMIN = 'project_admin';
// ... Both these are wrong: /**
* @extends Voter<'project_view', Project>
* @extends Voter<'project_write', Project>
* @extends Voter<'project_admin', Project>
*/
class ProjectVoter extends Voter /**
* @extends Voter<'project_view'|'project_write'|'project_admin', Project>
*/
class ProjectVoter extends Voter |
The template is the same than in the phpstan-symfony stubs
Why is this wrong @Nyholm ? I personally use the syntax
to avoid listing all the constant. ( |
That union of literals is a valid subtype of |
That is a big help. Thank you!
I'll try again. I was sure phpstan was complaining. Sorry for the old pings and thank you for the help! |
This template allows phpstan/psam/PHPStorm to fully understand the type of
$attribute
and$subject
when writing a Voter. For instance, if I writeI can annotate the Voter as
Voter<'EDIT', User>
and$subject->getId()
when writing inside thevoteOnAttribute
.The last two points are considered as valid because of the comment
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.