Skip to content

Match attributes on methods and functions with allowInMethods and allowInFunctions - #428

Merged
spaze merged 2 commits into
mainfrom
spaze/attributes-on-methods-allow-in-methods
Jul 17, 2026
Merged

Match attributes on methods and functions with allowInMethods and allowInFunctions#428
spaze merged 2 commits into
mainfrom
spaze/attributes-on-methods-allow-in-methods

Conversation

@spaze

@spaze spaze commented Jul 17, 2026

Copy link
Copy Markdown
Owner

A disallowed attribute placed on a method or a function is technically not in the method or the function, so $scope->getFunction() returns null and the name compared against the allowInMethods (and aliases) patterns would always be empty, never matching anything. The name is now resolved from the node when there's no function in the scope, the same way allowInMethodsWithAttributes already reads the attributes off the node, and produces the same name the reflection-based branches would produce for the same symbol.

This also means allowExceptInMethods (and aliases) can now report an attribute placed on a matching method or function, which was previously always allowed.

Close #427

spaze added 2 commits July 17, 2026 01:59
…allowInFunctions`

A disallowed attribute placed on a method or a function is technically not *in* the method or the function, so `$scope->getFunction()` returns `null` and the name compared against the `allowInMethods` (and aliases) patterns would always be empty, never matching anything. The name is now resolved from the node when there's no function in the scope, the same way `allowInMethodsWithAttributes` already reads the attributes off the node, and produces the same name the reflection-based branches would produce for the same symbol.

This also means `allowExceptInMethods` (and aliases) can now report an attribute placed on a matching method or function, which was previously always allowed.

Close #427
The item pointed to `docs/allow-in-methods.md`, the same file as the by-name item above it, most likely a copy-paste leftover, while the attributes variant has its own file in `docs/allow-in-methods-with-attributes.md`.
@spaze spaze self-assigned this Jul 17, 2026
Copilot AI review requested due to automatic review settings July 17, 2026 00:16

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes name-based allowInMethods / allowInFunctions matching for attributes placed on method/function declarations by resolving the symbol name from the AST node when $scope->getFunction() is null, aligning behavior with the existing attribute-based allow mechanisms and enabling allowExceptInMethods to correctly report such cases.

Changes:

  • Update Allowed::callMatches() to accept the current AST node and derive method/function names from ClassMethod / Function_ nodes when needed.
  • Add a dedicated fixture and rule test covering allowInMethods, allowExceptInMethods, and allowInFunctions for attribute placements (on class/method/property/nested function/top-level function).
  • Update documentation to clarify that attribute allow/disallow-by-name applies to attributes placed on methods/functions as well as inside them, and fix the README link to the correct “with-attributes” doc.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/Allowed/Allowed.php Threads the AST node into call-context matching and adds node-based name resolution for method/function declaration nodes.
tests/Usages/AttributeUsagesAllowInMethodsTest.php Adds coverage for allow/except matching on attributes applied directly to method/function declarations.
tests/src/AttributeMethods.php Provides a fixture exercising allowed/disallowed attribute placements across methods, nested functions, properties, classes, and functions.
README.md Corrects the README link for the “methods/functions with given attributes” feature.
docs/allow-in-methods.md Documents that allowInMethods/allowExceptInMethods apply to attributes on method/function declarations as well as inside bodies.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@spaze
spaze merged commit 46cd043 into main Jul 17, 2026
151 checks passed
@spaze
spaze deleted the spaze/attributes-on-methods-allow-in-methods branch July 17, 2026 00:21
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.

allowInMethods doesn't match the decorated method for attributes placed on methods

2 participants