Skip to content

Can get method/function attributes for params of disallowed classes #315

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

Merged
merged 1 commit into from
Mar 3, 2025

Conversation

spaze
Copy link
Owner

@spaze spaze commented Mar 2, 2025

When a disallowed classname is detected in method or function params, and it is allowed by method/function attributes, this change will allow to get the method/func attributes. It's way hacky as it seems to be not possible natively in PHPStan because $scope->getFunction() returns null for FullyQualified nodes in method/func parameter types. So we store the method name in ClassMethod rule, use it in Allowed service when set, and unset the function name in InClassMethodNode which is a virtual node which marks the beginning of the method body. Similar for functions in Function_ and InFunctionBody.

Close #314

When a disallowed classname is detected in method or function params, and it is allowed by method/function attributes, this change will allow to get the method/func attributes. It's way hacky as it seems to be not possible natively in PHPStan because `$scope->getFunction()` returns null for `FullyQualified` nodes in method/func parameter types. So we store the method name in `ClassMethod` rule, use it in `Allowed` service when set, and unset the function name in `InClassMethodNode` which is a virtual node which marks the beginning of the method body. Similar for functions in `Function_` and `InFunctionBody`.

Close #314
@spaze spaze self-assigned this Mar 2, 2025
@spaze spaze marked this pull request as ready for review March 2, 2025 16:22
@spaze spaze merged commit b24661b into main Mar 3, 2025
124 checks passed
@spaze spaze deleted the spaze/method-attrs-for-disallowed-classes-params branch March 3, 2025 21:14
@spaze
Copy link
Owner Author

spaze commented Mar 3, 2025

Followup to #296, released in 4.4.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

allowInMethodsWithAttributes does not work on method parameters
1 participant