Skip to content
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

Add phpstan-no-private to catch calls of seemingly private functions #776

Open
westonruter opened this issue Jul 10, 2023 · 2 comments · May be fixed by #1729
Open

Add phpstan-no-private to catch calls of seemingly private functions #776

westonruter opened this issue Jul 10, 2023 · 2 comments · May be fixed by #1729
Labels
Infrastructure Issues for the overall performance plugin infrastructure [Plugin] Performance Lab Issue relates to work in the Performance Lab Plugin only [Type] Enhancement A suggestion for improvement of an existing feature

Comments

@westonruter
Copy link
Member

Feature Description

As suggested by @swissspidy in #730 (comment):

I can also highly recommend https://packagist.org/packages/swissspidy/phpstan-no-private to catch calls of seemingly private functions.

Nevertheless, I noted:

I love this package, but I wonder if this is the best for Performance Lab considering that the code in question will end up in core and thus it is expected that many calls to internal/private functions will be made? As it stands right now...

And in response, @swissspidy:

Good point! 😃

I think it can't hurt to use it anyway, since not everything will land in core. Places where usage is OK can be ignored in the PHPStan config accordingly. But maybe in another PR :-)

All the Perflab_SQLite_ reports are actually false positives! I'll get this fixed in a new release. (Edit: see swissspidy/phpstan-no-private#2)
They are not properly documented though. A private function ...() method does not need @access private annotations. That's against the coding standards.

@westonruter westonruter added [Type] Enhancement A suggestion for improvement of an existing feature Infrastructure Issues for the overall performance plugin infrastructure labels Jul 10, 2023
@felixarntz felixarntz added the [Plugin] Performance Lab Issue relates to work in the Performance Lab Plugin only label Jul 19, 2023
@swissspidy
Copy link
Member

Especially in OD there are lots of functions/methods/classes marked as private but used in other places of the plugin. This currently triggers an error, but that doesn't seem right. I'll need to investigate that first, see swissspidy/phpstan-no-private#23

Legit errors I spotted at first glance:

  • _wp_image_meta_replace_original usage in plugins/webp-uploads/hooks.php
  • WP_HTML_Text_Replacement usage in plugins/optimization-detective/class-od-html-tag-processor.php

@westonruter
Copy link
Member Author

  • WP_HTML_Text_Replacement usage in plugins/optimization-detective/class-od-html-tag-processor.php

This is an intentional private usage.

@swissspidy swissspidy linked a pull request Dec 10, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Infrastructure Issues for the overall performance plugin infrastructure [Plugin] Performance Lab Issue relates to work in the Performance Lab Plugin only [Type] Enhancement A suggestion for improvement of an existing feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants