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

DB/DirectDatabaseQuery: implement PHPCSUtils and support modern PHP #2186

Merged
merged 7 commits into from
Jan 8, 2023

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Jan 7, 2023

DB/DirectDatabaseQuery: remove redundant code

This code is a remnant of the old-style custom ignore comment mechanism which was removed in #2063.

DB/DirectDatabaseQuery: add missing test case

... to cover the one uncovered line.

DB/DirectDatabaseQuery: implement PHPCSUtils

👉 This change will be easier to review while ignoring whitespace changes.

DB/DirectDatabaseQuery: add support for PHP 8.0+ nullsafe object operator

Prevent false negatives in case someone would use the PHP 8.0 nullsafe object operator on the $wpdb variable.

Also makes the token walking more stable by preventing an unrelated object operator from being recognized as if it were an operator operating on the $wpdb object (false positive).

Includes tests.

DB/DirectDatabaseQuery: bug fix - code style independent token walking

Don't allow the sniff to get confused by comments.

Related to #763

Includes tests.

DB/DirectDatabaseQuery: bug fix - finding end of statement

Prevent false positives from walking too far when a database query statement is ended by a PHP close tag.

Includes unit tests.

DB/DirectDatabaseQuery: bug fix - ignore TRUNCATE queries

Prevent unsolvable false positives for TRUNCATE queries. Those cannot be cached and need a direct DB query. (second opinion appreciated!)

Includes unit tests.

Fixes #1947

This code is a remnant of the old-style custom ignore comment mechanism which was removed in 2063.
... to cover the one uncovered line.
👉 This change will be easier to review while ignoring whitespace changes.
…ator

Prevent false negatives in case someone would use the PHP 8.0 nullsafe object operator on the `$wpdb` variable.

Also makes the token walking more stable by preventing an unrelated object operator from being recognized as if it were an operator operating on the `$wpdb` object (false positive).

Includes tests.
Don't allow the sniff to get confused by comments.

Related to 763

Includes tests.
Prevent false positives from walking too far when a database query statement is ended by a PHP close tag.

Includes unit tests.
Prevent unsolvable false positives for `TRUNCATE` queries. Those cannot be cached and need a direct DB query. (second opinion appreciated!)

Includes unit tests.

Fixes 1947
@jrfnl
Copy link
Member Author

jrfnl commented Jan 7, 2023

Note: this sniff is not that stable as the token walking is not very strict. Realistically, it could do with a complete rewrite, but that is outside the scope of what I was trying to achieve now.

Also just saw #864, which makes me question the TRUNCATE change. As I said above, second opinion very much appreciated.

Copy link
Member

@dingo-d dingo-d left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with TRUNCATE not being flagged.

In most cases people using raw SQL know why they are doing it and if they know how to configure PHPCS they'll just exclude the error for where it's being used anyhow so 🤷🏼‍♂️

Copy link
Member

@GaryJones GaryJones left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GaryJones GaryJones merged commit c8a7ac1 into develop Jan 8, 2023
@GaryJones GaryJones deleted the feature/directdbquery-phpcsutils-and-modern-php branch January 8, 2023 20:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DirectDatabaseQuery: don't demand caching or forbid direct DB calls for TRUNCATE
3 participants