generator icon indicating copy to clipboard operation
generator copied to clipboard

Ignore inaccessible class child nodes

Open herndlm opened this issue 3 years ago • 8 comments
trafficstars

Based on the idea that was voiced in https://github.com/szepeviktor/phpstan-wordpress/issues/99#issuecomment-1112996660

It should be safe to not include private constants/properties/methods of classes. And if the class is final, protected ones can be ignored too IMO.

Fyi this only makes the wordpress-stubs around 0.1M smaller, so it won't change much in regard to parsing performance there.

What do you think?

herndlm avatar May 02 '22 13:05 herndlm

What do you think?

I think this could be resolved in PHPStan. BTW PHPStan is written in PHP so it is not expected to be as fast as C code.

The current maintenance effort is over my personal max.

szepeviktor avatar May 02 '22 14:05 szepeviktor

the performance problems should be fixed in phpstan for sure. this PR was meant to just clean up the stubs a bit further which is not really related and makes sense anyways IMO. it could also be made configurable with a "include_inaccessible_class_nodes" config (a couple of lines more I already prepared).

but it's also fine to keep it as it is of course, this is your stubs generator :) but maybe you also want to remove the "PR welcome" message from the README then.

herndlm avatar May 02 '22 14:05 herndlm

Martin! We were forced to fork this project as we had problems. https://github.com/php-stubs/generator/commits/master

Stubs could be modified here: https://github.com/php-stubs/wordpress-stubs/blob/master/visitor.php#L37

I'll merge this as soon as any other person is complaining about private methods.

Okay?

szepeviktor avatar May 02 '22 14:05 szepeviktor

  1. if you want to remove a node I think you have to do this via leaveNode instead, see https://github.com/nikic/PHP-Parser/blob/v4.13.2/lib/PhpParser/NodeVisitor.php#L45
  2. sure, that's fine! feel free to keep it open, or also just close it if you want. I also don't have a problem if you say you don't need/want this :)

herndlm avatar May 02 '22 14:05 herndlm

To be honest I do not know what will happen by this PR. Thousands use WP core stubs!

szepeviktor avatar May 02 '22 14:05 szepeviktor

Actually this generator is a highly unstable project. I do not dare to touch it!!! I'm not a businessman nor a developer, I sit here at home and think. For me theory is not practice.

You must be brave enough to touch daily work of thousands.

szepeviktor avatar May 02 '22 14:05 szepeviktor

@herndlm Have you seen the actual diff?

164 insertions(+), 2959 deletions(-)

szepeviktor avatar May 02 '22 14:05 szepeviktor

I briefly scrolled through it, yeah. Was looking fine to me. But please let's not argue over this, if it's too risky then it shall not be touched and over :) or, as you suggested, work can be continued if more people want/need this.

herndlm avatar May 02 '22 14:05 herndlm

I would be in favour of removing these inaccessible nodes by default. Perhaps with a config flag to not exclude them in cases where they are needed?

johnbillion avatar Feb 08 '23 18:02 johnbillion

If it breaks anybody's code then they can ask Viktor for a refund.

johnbillion avatar Feb 08 '23 18:02 johnbillion

with a config flag

Let's do this.

szepeviktor avatar Feb 08 '23 18:02 szepeviktor

rebased on master and added the config change I had apparently lying around since May :D

herndlm avatar Feb 08 '23 20:02 herndlm

Thank you! Does --help talk about include_inaccessible_class_nodes?

szepeviktor avatar Feb 08 '23 20:02 szepeviktor

I realized that what I pushed was not ready yet, now it is, including the help adaption.

herndlm avatar Feb 08 '23 20:02 herndlm

but let me add a test case for that, sorry :) UPDATE: now I'm ok with it

herndlm avatar Feb 08 '23 20:02 herndlm

Thank you.

szepeviktor avatar Feb 08 '23 20:02 szepeviktor

Released as https://github.com/php-stubs/generator/releases/tag/v0.8.3

szepeviktor avatar Feb 08 '23 20:02 szepeviktor

Nice one

johnbillion avatar Feb 08 '23 22:02 johnbillion