Skip to content

Fix warning#60

Merged
guibranco merged 5 commits into
mainfrom
chore/fix-warning
Jun 18, 2026
Merged

Fix warning#60
guibranco merged 5 commits into
mainfrom
chore/fix-warning

Conversation

@guibranco

@guibranco guibranco commented Jun 18, 2026

Copy link
Copy Markdown
Owner

📑 Description

✅ Checks

  • My pull request adheres to the code style of this project
  • My code requires changes to the documentation
  • I have updated the documentation as required
  • All the tests have passed

☢️ Does this introduce a breaking change?

  • Yes
  • No

Summary by Sourcery

Bug Fixes:

  • Resolve a database query warning by wrapping non-parameterized export queries in a prepared statement call.

Modify the get_all_for_export function to always use $wpdb->prepare
for SQL query preparation, improving consistency and reducing the
risk of SQL injection. Previously, the function used a conditional
approach where $wpdb->prepare would not be called if no $values
were present. This change ensures that query preparation is uniform,
which enhances security and maintains best practices in database
interaction.
Simplify the query preparation logic in the get_all_for_export
function by eliminating the separate assignment of the $prepared
variable. This change directly prepares the SQL query in the
conditional block where $values are checked, streamlining
the code and improving readability. The refactoring ensures
that prepared statements are used consistently while
maintaining the same functionality.
Update phpcs ignore comments in `get_all_for_export` method to
include `PluginCheck.Security.DirectDB.UnescapedDBParameter`. This change
ensures compliance with the new security guidelines and helps prevent
potential security issues related to unescaped database parameters when
executing direct queries.
@sourcery-ai

sourcery-ai Bot commented Jun 18, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Ensures all export queries consistently use $wpdb->prepare(), even when no dynamic values are provided, aligning with WordPress coding standards and silencing related warnings.

Sequence diagram for standardized export query preparation

sequenceDiagram
    participant Caller
    participant SvaDb as SvaDb
    participant Wpdb as wpdb

    Caller->>SvaDb: get_all_for_export(args)
    alt values not empty
        SvaDb->>Wpdb: prepare(sql, values...)
        SvaDb->>Wpdb: get_results(prepared_sql, ARRAY_A)
    else values empty
        SvaDb->>Wpdb: prepare(sql)
        SvaDb->>Wpdb: get_results(prepared_sql, ARRAY_A)
    end
    SvaDb-->>Caller: rows array
Loading

File-Level Changes

Change Details Files
Standardized database export query execution to always use a prepared statement, even when no placeholder values are supplied.
  • Replaced direct $wpdb->get_results() call with a call that wraps the SQL in $wpdb->prepare() when no values array is present.
  • Updated PHPCS ignore annotations to match the new use of $wpdb->prepare() and PluginCheck expectations.
includes/class-sva-db.php

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai

coderabbitai Bot commented Jun 18, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@guibranco, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 57 minutes and 33 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more credits in the billing tab to continue.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: be23a0e6-fd82-4c8e-bebe-c62f1a92ec8a

📥 Commits

Reviewing files that changed from the base of the PR and between ed76890 and d29c426.

📒 Files selected for processing (1)
  • includes/class-sva-db.php
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/fix-warning

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • Calling $wpdb->prepare( $sql ) when there are no placeholders in $sql is unnecessary and can itself trigger WordPress warnings; consider reverting to $wpdb->get_results( $sql, ARRAY_A ) in the else branch and only adjusting the PHPCS ignore annotations to satisfy the new sniff.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Calling `$wpdb->prepare( $sql )` when there are no placeholders in `$sql` is unnecessary and can itself trigger WordPress warnings; consider reverting to `$wpdb->get_results( $sql, ARRAY_A )` in the `else` branch and only adjusting the PHPCS ignore annotations to satisfy the new sniff.

## Individual Comments

### Comment 1
<location path="includes/class-sva-db.php" line_range="399" />
<code_context>
 			$rows = $wpdb->get_results( $wpdb->prepare( $sql, ...$values ), ARRAY_A ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.PreparedSQL.NotPrepared,PluginCheck.Security.DirectDB.UnescapedDBParameter
 		} else {
-			$rows = $wpdb->get_results( $sql, ARRAY_A ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.PreparedSQL.NotPrepared,WordPress.DB.PreparedSQL.InterpolatedNotPrepared
+			$rows = $wpdb->get_results( $wpdb->prepare( $sql ), ARRAY_A ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.PreparedSQL.NotPrepared,PluginCheck.Security.DirectDB.UnescapedDBParameter
 		}

</code_context>
<issue_to_address>
**issue (bug_risk):** Using `$wpdb->prepare( $sql )` with no placeholders will likely trigger `_doing_it_wrong` and return false, breaking the query.

For the empty `$values` branch, avoid calling `prepare()` with only `$sql`. Instead, keep `get_results( $sql, ARRAY_A )` (with the PHPCS ignore) or otherwise bypass `prepare()` when there are no placeholders, so the query runs reliably and matches `$wpdb`’s intended usage.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread includes/class-sva-db.php
@sonarqubecloud

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown
Contributor

🔍 WordPress Plugin Check Report

⚠️ Status: Passed with warnings

📊 Report

🎯 Total Issues ❌ Errors ⚠️ Warnings
1 0 1

⚠️ Warnings (1)

📁 includes/class-sva-db.php (1 warning)
📍 Line 🔖 Check 💬 Message
397 PluginCheck.Security.DirectDB.UnescapedDBParameter Unescaped parameter $sql used in $wpdb->get_results()\n$sql assigned unsafely at line 394.

🤖 Generated by WordPress Plugin Check Action • Learn more about Plugin Check

@guibranco guibranco enabled auto-merge (squash) June 18, 2026 13:56
@gstraccini gstraccini Bot added the ☑️ auto-merge Automatic merging of pull requests (gstraccini-bot) label Jun 18, 2026
@guibranco guibranco merged commit 9905a42 into main Jun 18, 2026
16 checks passed
@guibranco guibranco deleted the chore/fix-warning branch June 18, 2026 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

☑️ auto-merge Automatic merging of pull requests (gstraccini-bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant