-
-
Notifications
You must be signed in to change notification settings - Fork 127
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
Indexer: fix #[\Attribute]
resolution
#2476
Indexer: fix #[\Attribute]
resolution
#2476
Conversation
In consideration that we might want to do more with attributes in the future we might as well fix it properly. I have seen that for implementations of the class there is a Maybe we could use this for attributes and also fix the issue described above with the namespace not being taken into consideration. |
@mamazu thanks for suggestion. |
@@ -54,7 +54,7 @@ public function indexAttributes(ClassRecord $record, ClassDeclaration $node): vo | |||
continue; | |||
} | |||
/** @phpstan-ignore-next-line */ | |||
if ($attribute->name?->getText() === 'Attribute') { | |||
if ((string) $attribute->name?->getResolvedName() === \Attribute::class) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getResolvedName is however potentially enormously inefficient. For this case it's probably enough to just check both variations? cc @mamazu
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dantleech if we check both 'Attribute'
and '\Attribute'
(and nothing else) then Not\Attribute
still remains considered attribute.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw. I did not checked how much the indexing time increases after this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would be relative to the numnber of attributes in the source tree i guess
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, it could be expensive. I haven't thought about it too much and just having a "good enough" solution would probably be sufficient.
I mean the current solution would also not pick up attributes if they have a renaming use statement like so:
use Attribute as PhpAttribute;
use SomeOtherPackage\Attribute;
#[PhpAttribute]
class MyClass{}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Independently of the discussion about expensiveness I added such example to the test.
#[\Attribute]
#[\Attribute]
resolution
Performance is probably "fine" we already do this for all class references, so a fee more shouldn't hurt. |
Now Symfony |
Oh we might want to bump the indexer version to force reindexing when people upgrade, but no biggie |
Oh that's why it wasn't showing on my project. Was wondering why. :D Thanks for fixing that (It probably also affects more symfony attributes) like |
It's not perfect because
still can be considered attribute.