-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
SubNodeNames are known at static analysis time #1035
base: master
Are you sure you want to change the base?
Conversation
I can kind of see how this could be useful in theory, but it's not really clear to me where we'd see a benefit in practice. Can you share an example where e.g. this gets rid of a baseline suppression in phpstan-src or similar? |
see e.g. https://phpstan.org/r/9041358f-043d-4171-9780-f9d9b4b3c534 before this PR here, the unused property cannot be detected. after this PR we get
I can't give you such a example, as because of the dynamic use errors are not detected which would be otherwise. |
hmm.. I tried this PR on the whole phpstan-src codebase and it somehow has strange side-effects. I have another look |
9a5b30d
to
a73955f
Compare
@@ -29,6 +29,8 @@ class PrintableNewAnonClassNode extends Expr { | |||
/** @var Node\Stmt[] Statements */ | |||
public array $stmts; | |||
|
|||
private const SUBNODE_NAMES = ['attrGroups', 'flags', 'args', 'extends', 'implements', 'stmts']; |
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.
It would be great to assert the lists with a test, so the lists are never outdated/incomplete.
this PR turns the SubNodeNames into constant arrays and corresponding phpdocs, which makes them available to PHPStan at static analysis time.
this information is useful to better cover codebases which utilize PHP-Parser and in need of dynamic property lookups like
when the type of
$node
is known.closes #1033