-
-
Notifications
You must be signed in to change notification settings - Fork 483
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
False positive "High pagination limit" when posts_per_page
is set to a function.
#2027
Comments
This example is a tricky one because PHPCS isn't aware of the context. It doesn't parse your code and tracks what you used and where. PHPCS cannot know if the EDITLooking at the sniff it doesn't do any sort of calculations, just compares the values here. And you don't have a value but a statement that does something (in your case returns the lowest value of the expression). |
@dingo-d exactly my point. Since we can't know the context, but see that |
You can easily do that either by excluding that sniff in your ruleset <rule ref="WordPress.WP">
<exclude name="WordPress.WP.PostsPerPage.posts_per_page_posts_per_page"/>
</rule> Or ignoring that line with a comment function get_query_args( int $first, int $last, int $default_min = 10 ) : array {
return array(
// other query args...
'posts_per_page' => min( max( $first, $last ), $default_min ), // phpcs:ignore WordPress.WP.PostsPerPage.posts_per_page_posts_per_page
);
} |
Thanks, I am aware how to silence the sniff. However, I believe it to be a false positive, which is why I opened the issue. |
This is odd, I'm not getting that error. I tried adding your code example to the unit test file, and I tried sniffing a test file with The value that is picked up in your case is Can you share your ruleset? |
I have been able to reproduce the issue and a fix will be included in WPCS 3.0.0. @dingo-d I believe the reason you couldn't reproduce the issue is because you tested with PHP 7.x, while the behaviour in PHP for text to number comparisons has changed in PHP 8.0: https://3v4l.org/nOlYL#veol |
Bug Description
When setting
posts_per_page
to a function, wpcs logs "Detected high pagination limit,posts_per_page
is set to..." warning.It should be treated like
-1
, and have no error shown.Minimal Code Snippet
The issue happens when running this command:
... over a file containing this code:
Error Code
WordPress.WP.PostsPerPage.posts_per_page_posts_per_page
Custom ruleset
Environment
Tested Against
develop
branch?develop
branch of WPCS.The text was updated successfully, but these errors were encountered: