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 detection of default arguments to functions e.g. ! isset( $args[ 'numberposts' ] ) && get_posts( $args ) #2461

Closed
claimableperch opened this issue Jun 18, 2024 · 3 comments

Comments

@claimableperch
Copy link

Is your feature request related to a problem?

Post retrieval limited to 5 posts made its way into production briefly.

Describe the solution you'd like

AbstractFunctionRestrictionSniff to make a call to [ static::class, 'defaulted_callback' ] in the case of that function being defined in sub-classes, making it simple to construct sniffs which warn of certain default arguments - such as 'numberposts' in PostsPerPageSniff.

  • [?] I intend to create a pull request to implement this feature.
@jrfnl
Copy link
Member

jrfnl commented Jun 18, 2024

@claimableperch Thanks for opening this issue, but it is completely unclear to me what you are suggesting. On the one hand you talk about "your" code (post retrieval ... made it to production), on the other hand you talk about an abstract sniff, without it being clear what you expect to happen. And the "subject" of the issue mentioning some code pattern without any context, also doesn't help.

Let's take a step back:

  • What is the code pattern in the "code under scan" (=your code) which you would hope WPCS to detect ? i.e. please add one or more code samples of code which should be flagged.
  • Once that pattern is clear, let's talk about whether this is possible and if so, how.

@jrfnl
Copy link
Member

jrfnl commented Aug 20, 2024

Marking this as close candidate as without more information, this ticket is not actionable.

@claimableperch
Copy link
Author

Add detection of default arguments to functions

e.g. When ! isset( $args[ 'numberposts' ] ) Then get_posts( $args ) will get you five posts.

I guess I was just wishing that wp_parse_args( $args, $defaults ) rang around and dragged me out of hyperspace by itself.

It's really more an IDE-completion sort of thing. But unless you filter them all, it also isn't. Real question is why I posted it to this repository. So I guess it's all too real.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants