Skip to content

Dectect reading class constants in PHPDoc - #2436

Open
rvanvelzen wants to merge 1 commit into
phpstan:2.3.xfrom
rvanvelzen:phpdoc-private-const
Open

rvanvelzen wants to merge 1 commit into
phpstan:2.3.xfrom
rvanvelzen:phpdoc-private-const

Conversation

@rvanvelzen

Copy link
Copy Markdown
Contributor

@phpstan-bot

Copy link
Copy Markdown
Collaborator

You've opened the pull request against the latest branch 1.11.x. If your code is relevant on 1.10.x and you want it to be released sooner, please rebase your pull request and change its target to 1.10.x.

@rvanvelzen
rvanvelzen force-pushed the phpdoc-private-const branch from e0a1848 to d898658 Compare June 6, 2023 07:29

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I really like this, it's almost perfect. What gives me a little pause is that all PHPDocs are now parsed multiple times which would lead to performance problems. The correct way to access them is through FileTypeMapper. Also you shouldn't have to do any regexes, but correctly resolve the class name with NameScope.

Of course the issue is that the thing returned by FileTypeMapper is ResolvedPhpDocBlock. Which is about accessing the useful PHPDoc things like ParamTag and many others.

One way to solve this would be to add getClassConstFetches on ResolvedPhpDocBlock. But the class is a bit tricky to work with - because it can be created multiple ways (create, createEmpty, merge), we need to be careful every time a new property is added.

@rvanvelzen
rvanvelzen force-pushed the phpdoc-private-const branch from d898658 to 493aba4 Compare June 6, 2023 07:59
@ondrejmirtes
ondrejmirtes changed the base branch from 1.11.x to 2.3.x October 31, 2026 14:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants