Skip to content

Use the new getAttributes() API to get attributes#311

Draft
spaze wants to merge 2 commits intomainfrom
spaze/new-api-get-attributes
Draft

Use the new getAttributes() API to get attributes#311
spaze wants to merge 2 commits intomainfrom
spaze/new-api-get-attributes

Conversation

@spaze
Copy link
Copy Markdown
Owner

@spaze spaze commented Feb 22, 2025

The API is used instead of code added in #296 and is available starting with PHPStan 2.1.3 so I'll need to decide when to merge this and when or how to remove support for earlier versions.

Seems like the last real 1.12.x release 1.12.28 was in Jul 17, 2025, I'd say it's time to call it.

@spaze spaze self-assigned this Feb 22, 2025
@spaze spaze force-pushed the spaze/new-api-get-attributes branch from 1006365 to 62c1df9 Compare February 24, 2025 23:46
@spaze spaze force-pushed the spaze/new-api-get-attributes branch from 62c1df9 to 891410b Compare March 4, 2025 02:17
@spaze spaze force-pushed the spaze/new-api-get-attributes branch 3 times, most recently from 9524b18 to 4ece18a Compare April 11, 2025 00:25
@spaze spaze force-pushed the spaze/new-api-get-attributes branch 3 times, most recently from 8e2df34 to f59ba27 Compare May 15, 2025 21:34
@spaze spaze requested a review from Copilot July 13, 2025 00:40
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR migrates attribute handling to PHPStan’s native getAttributes() API (available in PHPStan 2.1.3+), removes legacy BetterReflection usage, and upgrades related dependencies.

  • Switch Reflector and BetterReflection adapters to PHPStan’s ReflectionProvider and AttributeReflection
  • Replace PhpParser\Node\UseUse with PhpParser\Node\UseItem for php-parser 5.0+
  • Update tests and bump phpstan/phpstan to ^2.1.3 and nikic/php-parser to ^5.0

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/Usages/NamespaceUsagesAllowInClassWithAttributesTest.php Pass Node\Name instead of string to setCurrentFunctionName()
src/Usages/NamespaceUsages.php Replace UseUse with UseItem
src/Identifier/Identifier.php Swap BetterReflection Reflector for PHPStan ReflectionProvider
src/HelperRules/SetCurrentFunctionNameHelperRule.php Change setter to accept PhpParser\Node\Name
src/Allowed/GetAttributesWhenInSignature.php Use ReflectionProvider and update return types
src/Allowed/Allowed.php Remove BetterReflection, use ReflectionProvider and AttributeReflection
composer.json Require phpstan/phpstan:^2.1.3 and nikic/php-parser:^5.0
Comments suppressed due to low confidence (1)

src/Allowed/Allowed.php:253

  • Here too, getFunction expects a string but node->namespacedName is a Name object. Use ->toString() (e.g., getFunction($node->namespacedName->toString(), $scope)) to avoid type mismatch.
	}

Comment thread src/Allowed/GetAttributesWhenInSignature.php Outdated
@spaze spaze force-pushed the spaze/new-api-get-attributes branch 2 times, most recently from 3f2e4cf to 12d8b4b Compare August 25, 2025 21:47
@spaze spaze force-pushed the spaze/new-api-get-attributes branch from 12d8b4b to 2559ea4 Compare February 25, 2026 01:59
@spaze spaze force-pushed the spaze/new-api-get-attributes branch 2 times, most recently from 9c450ac to 7ad72bb Compare March 13, 2026 23:21
@spaze spaze force-pushed the spaze/new-api-get-attributes branch from 7ad72bb to faf4ef2 Compare April 9, 2026 23:10
spaze added 2 commits April 19, 2026 01:43
The API is available starting with PHPStan 2.1.3 https://github.com/phpstan/phpstan/releases/tag/2.1.3 so I'll need to decide when to merge this and when or how to remove support for earlier versions.

Also require nikic/php-parser 5.0+ because first PHPStan 2.x requires and uses it and second, Function_::namespacedName is not available in earlier versions.
@spaze spaze force-pushed the spaze/new-api-get-attributes branch from faf4ef2 to b35861e Compare April 19, 2026 00:03
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.

2 participants