Skip to content

Use wp tablename placeholder in db queries - #3223

Open
Crabcyborg wants to merge 16 commits into
masterfrom
use_wp_tablename_placeholder_in_db_queries
Open

Crabcyborg wants to merge 16 commits into
masterfrom
use_wp_tablename_placeholder_in_db_queries

Conversation

@Crabcyborg

@Crabcyborg Crabcyborg commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • Security

    • Improved database query handling across form, entry, migration, email summary, and Stripe-related features.
    • Added automated checks to help prevent unsafe database identifier usage.
  • Bug Fixes

    • Form duplication and imports now correctly preserve field references found in descriptions.
    • Trusted imports can retain submitted ownership and update metadata while regular saves continue following standard ownership rules.
  • Quality Improvements

    • Added automated coverage for database-query security checks and related edge cases.

@coderabbitai

coderabbitai Bot commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 33 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 539dfac and f217098.

Files selected for processing: 21

  • classes/controllers/FrmWelcomeTourController.php
  • classes/helpers/FrmEmailSummaryHelper.php
  • classes/models/FrmDb.php
  • classes/models/FrmEntry.php
  • classes/models/FrmEntryMeta.php
  • classes/models/FrmField.php
  • classes/models/FrmForm.php
  • classes/models/FrmMigrate.php
  • classes/models/FrmStyle.php
  • phpcs-sniffs/Formidable/Sniffs/Security/PreferIdentifierPlaceholderSniff.php
  • phpcs-sniffs/Formidable/ruleset.xml
  • phpcs-sniffs/tests/README.md
  • phpcs-sniffs/tests/fixtures/PreferIdentifierPlaceholder.fixed
  • phpcs-sniffs/tests/fixtures/PreferIdentifierPlaceholder.inc
  • phpcs-sniffs/tests/fixtures/expected.json
  • stripe/controllers/FrmStrpLiteEventsController.php
  • stripe/controllers/FrmTransLiteCRUDController.php
  • stripe/controllers/FrmTransLiteSubscriptionsController.php
  • stripe/helpers/FrmTransLiteListHelper.php
  • stripe/models/FrmTransLiteDb.php
  • stripe/models/FrmTransLiteSubscription.php

No actionable comments were generated in the recent review.

Walkthrough

The pull request adds a PHPCS sniff for unsafe SQL identifier interpolation and converts core and Stripe queries to %i placeholders. Entry imports now preserve permitted ownership fields. Tests cover sniff fixes, diagnostics, and exemptions.

Changes: Identifier Placeholder Hardening

Layer / File(s) Summary
PHPCS identifier placeholder sniff
phpcs-sniffs/Formidable/Sniffs/Security/PreferIdentifierPlaceholder.php
Adds SQL parsing, diagnostics, and safe automatic fixes for interpolated table and column identifiers.
Entry ownership and update handling
classes/models/FrmEntry.php
Propagates save types and applies distinct ownership and updated_by handling for trusted imports and normal saves.
Core query identifier conversion
classes/controllers/*, classes/helpers/*, classes/models/*
Replaces direct table-name interpolation with %i placeholders across core queries, migrations, and deletion operations.
Stripe query identifier conversion
stripe/controllers/*, stripe/helpers/*, stripe/models/*
Uses %i for Stripe table and column identifiers while preserving existing filters and values.
Sniff registration and test coverage
phpcs-sniffs/Formidable/ruleset.xml, tests/phpunit/misc/*
Registers the sniff and tests automatic fixes, non-fixable diagnostics, valid cases, and exemptions.

Estimated code review effort: 4 (Complex) | ~60 minutes

Change: Refactor

Merge Risk: Minimal · previous review 539df

No actionable regression was established in the reviewed changes; the PR is mergeable after normal checks.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 74.70% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 83 functions across 17 files. (1 skipped:… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)

Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the primary change: replacing direct table-name interpolation with the WordPress identifier placeholder in database queries.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 74.70% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 83 functions across 17 files. (1 skipped: 1 unsupported.)

Finishing Touches

Fix failing CI checks

  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)

  • Create PR with unit tests
  • Commit unit tests in branch use_wp_tablename_placeholder_in_db_queries
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

ℹ️ Recent review info

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 8e8b93fa-de80-47bd-aeee-7d0c2dd54290

📥 Commits

Reviewing files that changed from the base of the PR and between 2270c43 and 539dfac.

📒 Files selected for processing (10)

  • classes/models/FrmEntry.php
  • classes/models/FrmEntryMeta.php
  • classes/models/FrmField.php
  • classes/models/FrmForm.php
  • classes/models/FrmMigrate.php
  • phpcs-sniffs/Formidable/ruleset.xml
  • stripe/controllers/FrmStrpLiteEventsController.php
  • stripe/controllers/FrmTransLiteCRUDController.php
  • stripe/helpers/FrmTransLiteListHelper.php
  • stripe/models/FrmTransLiteDb.php

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.

@deepsource-io

deepsource-io Bot commented Aug 6, 2026 •

Copy link
Copy Markdown

DeepSource Code Review

We reviewed changes in 85479d8...f217098 on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.

See full review on DeepSource ↗

Important

Some issues found as part of this review are outside of the diff in this pull request and aren't shown in the inline review comments due to GitHub's API limitations. You can see those issues on the DeepSource dashboard.

PR Report Card

Overall Grade   Security  

Reliability  

Complexity  

Hygiene  

Code Review Summary

Analyzer Status Updated (UTC) Details
PHP Dec 2, 2026 1:44p.m. Review ↗
JavaScript Dec 2, 2026 1:44p.m. Review ↗

Important

AI Review is run only on demand for your team. We're only showing results of static analysis review right now. To trigger AI Review, comment @deepsourcebot review on this thread.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
phpcs-sniffs/Formidable/Sniffs/Security/PreferIdentifierPlaceholderSniff.php (1)

776-776: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Remove the three unused parameters from apply_fix().

The body of apply_fix() uses $parts, $refs, and $args only. $openParen, $argEnd, and $closeParen are never read. PHPMD reports all three. Drop them from the signature and from the call site at Line 563.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@phpcs-sniffs/Formidable/Sniffs/Security/PreferIdentifierPlaceholderSniff.php`
at line 776, Update PreferIdentifierPlaceholderSniff::apply_fix() to remove the
unused $openParen, $argEnd, and $closeParen parameters, and remove the
corresponding arguments from its call site near line 563 while preserving the
existing $parts, $refs, and $args usage.

Source: Linters/SAST tools

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@phpcs-sniffs/Formidable/Sniffs/Security/PreferIdentifierPlaceholderSniff.php`:
- Around line 406-426: Mark the ref created in the unbalanced-backtick branch of
the matching loop in PreferIdentifierPlaceholderSniff as unfixable instead of
only reassigning $tickAfter. Update refs_are_fixable() to return false when any
ref has the unfixable marker, so apply_fix() cannot rewrite identifiers whose
closing backtick is in another part.

---

Nitpick comments:
In
`@phpcs-sniffs/Formidable/Sniffs/Security/PreferIdentifierPlaceholderSniff.php`:
- Line 776: Update PreferIdentifierPlaceholderSniff::apply_fix() to remove the
unused $openParen, $argEnd, and $closeParen parameters, and remove the
corresponding arguments from its call site near line 563 while preserving the
existing $parts, $refs, and $args usage.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: e46d8bcb-63c5-4bbd-bba8-a4c2972307c4

📥 Commits

Reviewing files that changed from the base of the PR and between e3ee649 and 2270c43.

📒 Files selected for processing (21)
  • classes/controllers/FrmWelcomeTourController.php
  • classes/helpers/FrmEmailSummaryHelper.php
  • classes/helpers/FrmFormsListHelper.php
  • classes/models/FrmDb.php
  • classes/models/FrmEntry.php
  • classes/models/FrmEntryMeta.php
  • classes/models/FrmField.php
  • classes/models/FrmForm.php
  • classes/models/FrmMigrate.php
  • classes/models/FrmStyle.php
  • phpcs-sniffs/Formidable/Sniffs/Security/PreferIdentifierPlaceholderSniff.php
  • phpcs-sniffs/Formidable/ruleset.xml
  • stripe/controllers/FrmStrpLiteEventsController.php
  • stripe/controllers/FrmTransLiteSubscriptionsController.php
  • stripe/models/FrmTransLiteDb.php
  • stripe/models/FrmTransLiteSubscription.php
  • tests/phpunit/database/test_FrmMigrate.php
  • tests/phpunit/forms/test_FrmForm.php
  • tests/phpunit/misc/fixtures/prefer-identifier-placeholder-ruleset.xml
  • tests/phpunit/misc/test_FrmPreferIdentifierPlaceholderSniff.php
  • tests/phpunit/misc/test_FrmWelcomeTourController.php

Comment on lines +406 to +426
foreach ( $matches[2] as $index => $match ) {
$text = $match[0];
$tickBefore = $matches[1][ $index ][0];
$tickAfter = $matches[3][ $index ][0];
$startOffset = $matches[1][ $index ][1];

if ( '' !== $tickBefore && '' === $tickAfter ) {
// Unbalanced backtick, the identifier continues in another part. Not safely fixable.
$tickAfter = '';
}

$refs[] = array(
'type' => 'in_string',
'ptr' => $part['start'],
'part' => $p,
'offset' => $startOffset,
'length' => strlen( $tickBefore ) + strlen( $text ) + strlen( $tickAfter ),
'text' => $text,
'expr' => $this->segments_to_expression( $text ),
);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

Unbalanced backticks are detected but still treated as fixable.

At Line 412 the code detects an identifier that starts with a backtick and does not close in the same string part. The comment states the case is not safely fixable. The code then assigns $tickAfter = '', which is the value it already holds, and still returns the ref as a normal in_string ref. refs_are_fixable() does not inspect this state, so apply_fix() replaces the opening backtick plus the matched text with %i and leaves the trailing backtick in a later part. The rewritten SQL then contains %i followed by a stray backtick.

Mark such refs as unfixable and let refs_are_fixable() reject them.

🐛 Proposed fix to block fixing for unbalanced backticks
 		foreach ( $matches[2] as $index => $match ) {
 			$text        = $match[0];
 			$tickBefore  = $matches[1][ $index ][0];
 			$tickAfter   = $matches[3][ $index ][0];
 			$startOffset = $matches[1][ $index ][1];
-
-			if ( '' !== $tickBefore && '' === $tickAfter ) {
-				// Unbalanced backtick, the identifier continues in another part. Not safely fixable.
-				$tickAfter = '';
-			}
+			// Unbalanced backtick means the identifier continues in another part. Not safely fixable.
+			$unbalanced = '' !== $tickBefore && '' === $tickAfter;
 
 			$refs[] = array(
-				'type'   => 'in_string',
-				'ptr'    => $part['start'],
-				'part'   => $p,
-				'offset' => $startOffset,
-				'length' => strlen( $tickBefore ) + strlen( $text ) + strlen( $tickAfter ),
-				'text'   => $text,
-				'expr'   => $this->segments_to_expression( $text ),
+				'type'       => 'in_string',
+				'ptr'        => $part['start'],
+				'part'       => $p,
+				'offset'     => $startOffset,
+				'length'     => strlen( $tickBefore ) + strlen( $text ) + strlen( $tickAfter ),
+				'text'       => $text,
+				'unfixable'  => $unbalanced,
+				'expr'       => $this->segments_to_expression( $text ),
 			);
 		}

Then reject unfixable refs in refs_are_fixable():

foreach ( $refs as $ref ) {
	if ( ! empty( $ref['unfixable'] ) ) {
		return false;
	}
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@phpcs-sniffs/Formidable/Sniffs/Security/PreferIdentifierPlaceholderSniff.php`
around lines 406 - 426, Mark the ref created in the unbalanced-backtick branch
of the matching loop in PreferIdentifierPlaceholderSniff as unfixable instead of
only reassigning $tickAfter. Update refs_are_fixable() to return false when any
ref has the unfixable marker, so apply_fix() cannot rewrite identifiers whose
closing backtick is in another part.

Comment thread tests/phpunit/forms/test_FrmForm.php Outdated

$this->assertNotFalse( $result );
$this->assertEquals( 'published', FrmForm::getOne( $form_id_1 )->status );
$this->assertEquals( 'published', FrmForm::getOne( $form_id_2 )->status );

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Call to an undefined method test_FrmForm::assertEquals()


The method you are trying to call is not defined, which can result in a fatal error.

$frmdb = new FrmMigrate();
$this->run_private_method( array( $frmdb, 'migrate_to_23' ), array() );

$this->assertSame( '', $wpdb->last_error );

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Call to an undefined method test_FrmMigrate::assertSame()


The method you are trying to call is not defined, which can result in a fatal error.

$this->run_private_method( array( $frmdb, 'migrate_to_23' ), array() );

$this->assertSame( '', $wpdb->last_error );
$this->assertTrue( FrmDb::db_column_exists( 'frm_forms', 'parent_form_id' ) );

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Call to an undefined method test_FrmMigrate::assertTrue()


The method you are trying to call is not defined, which can result in a fatal error.

* @covers FrmForm::set_status
*/
public function test_set_status() {
$form_id_1 = $this->factory->form->create();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Access to an undefined property test_FrmForm::$factory


The property you are trying to access is not defined and will cause unexpected behavior when used.

*/
public function test_set_status() {
$form_id_1 = $this->factory->form->create();
$form_id_2 = $this->factory->form->create();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Access to an undefined property test_FrmForm::$factory


The property you are trying to access is not defined and will cause unexpected behavior when used.

$this->assertNotEmpty( $errors, 'Expected the sniff to flag: ' . $code );

foreach ( $errors as $error ) {
$this->assertSame( $source, $error['source'] );

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Call to an undefined method test_FrmPreferIdentifierPlaceholderSniff::assertSame()


The method you are trying to call is not defined, which can result in a fatal error.


foreach ( $errors as $error ) {
$this->assertSame( $source, $error['source'] );
$this->assertFalse( $error['fixable'], 'Expected a non-fixable error for: ' . $code );

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Call to an undefined method test_FrmPreferIdentifierPlaceholderSniff::assertFalse()


The method you are trying to call is not defined, which can result in a fatal error.

*/
private function assert_clean( $code ) {
$file = $this->process_code( $code );
$this->assertSame( 0, $file->getErrorCount(), 'Expected no errors for: ' . $code );

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Call to an undefined method test_FrmPreferIdentifierPlaceholderSniff::assertSame()


The method you are trying to call is not defined, which can result in a fatal error.

public function test_check_for_form_embeds() {
$this->assertFalse( $this->check_for_form_embeds() );

$this->factory->post->create(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Access to an undefined property test_FrmWelcomeTourController::$factory


The property you are trying to access is not defined and will cause unexpected behavior when used.

)
);

$this->assertTrue( $this->check_for_form_embeds() );

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Call to an undefined method test_FrmWelcomeTourController::assertTrue()


The method you are trying to call is not defined, which can result in a fatal error.


foreach ( $orders as $start => $expected ) {
$actual = FrmDb::esc_order( $start );
$this->assertSame( $expected, $actual );

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Call to an undefined method test_FrmDb::assertSame()


The method you are trying to call is not defined, which can result in a fatal error.

* @covers FrmDb::db_column_exists
*/
public function test_db_column_exists() {
$this->assertTrue( FrmDb::db_column_exists( 'frm_fields', 'field_key' ) );

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Call to an undefined method test_FrmDb::assertTrue()


The method you are trying to call is not defined, which can result in a fatal error.

*/
public function test_db_column_exists() {
$this->assertTrue( FrmDb::db_column_exists( 'frm_fields', 'field_key' ) );
$this->assertTrue( FrmDb::db_column_exists( 'frm_items', 'is_draft' ) );

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Call to an undefined method test_FrmDb::assertTrue()


The method you are trying to call is not defined, which can result in a fatal error.

public function test_db_column_exists() {
$this->assertTrue( FrmDb::db_column_exists( 'frm_fields', 'field_key' ) );
$this->assertTrue( FrmDb::db_column_exists( 'frm_items', 'is_draft' ) );
$this->assertFalse( FrmDb::db_column_exists( 'frm_fields', 'missing_column' ) );

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Call to an undefined method test_FrmDb::assertFalse()


The method you are trying to call is not defined, which can result in a fatal error.


$this->assertArrayHasKey( $form_a->id, $by_form );
$this->assertArrayHasKey( $form_b->id, $by_form );
$this->assertSame( 2, $by_form[ $form_a->id ] );

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Call to an undefined method test_FrmEmailSummaryHelper::assertSame()


The method you are trying to call is not defined, which can result in a fatal error.


$this->assertStringContainsString( 'FROM `' . $wpdb->prefix . 'frm_payments` p', $query );
$this->assertStringContainsString( 'JOIN `' . $wpdb->prefix . 'frm_items` i ON p.item_id = i.id', $query );
$this->assertStringContainsString( 'i.form_id = ' . $form_id, $query );

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Call to an undefined method test_FrmTransLiteListHelper::assertStringContainsString()


The method you are trying to call is not defined, which can result in a fatal error.

* @covers FrmTransLiteListHelper::get_form_ids
*/
public function test_get_form_ids() {
$form = $this->factory->form->create_and_get();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Access to an undefined property test_FrmTransLiteListHelper::$factory


The property you are trying to access is not defined and will cause unexpected behavior when used.

*/
public function test_get_form_ids() {
$form = $this->factory->form->create_and_get();
$entry = $this->factory->entry->create_and_get( $this->factory->field->generate_entry_array( $form ) );

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Access to an undefined property test_FrmTransLiteListHelper::$factory


The property you are trying to access is not defined and will cause unexpected behavior when used.


unset( $_REQUEST['trans_type'] );

$this->assertArrayHasKey( $entry->id, $form_ids );

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Call to an undefined method test_FrmTransLiteListHelper::assertArrayHasKey()


The method you are trying to call is not defined, which can result in a fatal error.

unset( $_REQUEST['trans_type'] );

$this->assertArrayHasKey( $entry->id, $form_ids );
$this->assertEquals( $form->id, $form_ids[ $entry->id ]->form_id );

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Call to an undefined method test_FrmTransLiteListHelper::assertEquals()


The method you are trying to call is not defined, which can result in a fatal error.


foreach ( $orders as $start => $expected ) {
$actual = FrmDb::esc_order( $start );
$this->assertSame( $expected, $actual );

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Call to an undefined method test_FrmDb::assertSame()


The method you are trying to call is not defined, which can result in a fatal error.

* @covers FrmDb::db_column_exists
*/
public function test_db_column_exists() {
$this->assertTrue( FrmDb::db_column_exists( 'frm_fields', 'field_key' ) );

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Call to an undefined method test_FrmDb::assertTrue()


The method you are trying to call is not defined, which can result in a fatal error.

*/
public function test_db_column_exists() {
$this->assertTrue( FrmDb::db_column_exists( 'frm_fields', 'field_key' ) );
$this->assertTrue( FrmDb::db_column_exists( 'frm_items', 'is_draft' ) );

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Call to an undefined method test_FrmDb::assertTrue()


The method you are trying to call is not defined, which can result in a fatal error.

public function test_db_column_exists() {
$this->assertTrue( FrmDb::db_column_exists( 'frm_fields', 'field_key' ) );
$this->assertTrue( FrmDb::db_column_exists( 'frm_items', 'is_draft' ) );
$this->assertFalse( FrmDb::db_column_exists( 'frm_fields', 'missing_column' ) );

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Call to an undefined method test_FrmDb::assertFalse()


The method you are trying to call is not defined, which can result in a fatal error.


$this->assertArrayHasKey( $form_a->id, $by_form );
$this->assertArrayHasKey( $form_b->id, $by_form );
$this->assertSame( 2, $by_form[ $form_a->id ] );

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Call to an undefined method test_FrmEmailSummaryHelper::assertSame()


The method you are trying to call is not defined, which can result in a fatal error.


$this->assertStringContainsString( 'FROM `' . $wpdb->prefix . 'frm_payments` p', $query );
$this->assertStringContainsString( 'JOIN `' . $wpdb->prefix . 'frm_items` i ON p.item_id = i.id', $query );
$this->assertStringContainsString( 'i.form_id = ' . $form_id, $query );

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Call to an undefined method test_FrmTransLiteListHelper::assertStringContainsString()


The method you are trying to call is not defined, which can result in a fatal error.

* @covers FrmTransLiteListHelper::get_form_ids
*/
public function test_get_form_ids() {
$form = $this->factory->form->create_and_get();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Access to an undefined property test_FrmTransLiteListHelper::$factory


The property you are trying to access is not defined and will cause unexpected behavior when used.

*/
public function test_get_form_ids() {
$form = $this->factory->form->create_and_get();
$entry = $this->factory->entry->create_and_get( $this->factory->field->generate_entry_array( $form ) );

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Access to an undefined property test_FrmTransLiteListHelper::$factory


The property you are trying to access is not defined and will cause unexpected behavior when used.


unset( $_REQUEST['trans_type'] );

$this->assertArrayHasKey( $entry->id, $form_ids );

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Call to an undefined method test_FrmTransLiteListHelper::assertArrayHasKey()


The method you are trying to call is not defined, which can result in a fatal error.

unset( $_REQUEST['trans_type'] );

$this->assertArrayHasKey( $entry->id, $form_ids );
$this->assertEquals( $form->id, $form_ids[ $entry->id ]->form_id );

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Call to an undefined method test_FrmTransLiteListHelper::assertEquals()


The method you are trying to call is not defined, which can result in a fatal error.


foreach ( $orders as $start => $expected ) {
$actual = FrmDb::esc_order( $start );
$this->assertSame( $expected, $actual );

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Call to an undefined method test_FrmDb::assertSame()


The method you are trying to call is not defined, which can result in a fatal error.

* @covers FrmDb::db_column_exists
*/
public function test_db_column_exists() {
$this->assertTrue( FrmDb::db_column_exists( 'frm_fields', 'field_key' ) );

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Call to an undefined method test_FrmDb::assertTrue()


The method you are trying to call is not defined, which can result in a fatal error.

*/
public function test_db_column_exists() {
$this->assertTrue( FrmDb::db_column_exists( 'frm_fields', 'field_key' ) );
$this->assertTrue( FrmDb::db_column_exists( 'frm_items', 'is_draft' ) );

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Call to an undefined method test_FrmDb::assertTrue()


The method you are trying to call is not defined, which can result in a fatal error.

public function test_db_column_exists() {
$this->assertTrue( FrmDb::db_column_exists( 'frm_fields', 'field_key' ) );
$this->assertTrue( FrmDb::db_column_exists( 'frm_items', 'is_draft' ) );
$this->assertFalse( FrmDb::db_column_exists( 'frm_fields', 'missing_column' ) );

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Call to an undefined method test_FrmDb::assertFalse()


The method you are trying to call is not defined, which can result in a fatal error.


$this->assertArrayHasKey( $form_a->id, $by_form );
$this->assertArrayHasKey( $form_b->id, $by_form );
$this->assertSame( 2, $by_form[ $form_a->id ] );

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Call to an undefined method test_FrmEmailSummaryHelper::assertSame()


The method you are trying to call is not defined, which can result in a fatal error.


$this->assertStringContainsString( 'FROM `' . $wpdb->prefix . 'frm_payments` p', $query );
$this->assertStringContainsString( 'JOIN `' . $wpdb->prefix . 'frm_items` i ON p.item_id = i.id', $query );
$this->assertStringContainsString( 'i.form_id = ' . $form_id, $query );

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Call to an undefined method test_FrmTransLiteListHelper::assertStringContainsString()


The method you are trying to call is not defined, which can result in a fatal error.

* @covers FrmTransLiteListHelper::get_form_ids
*/
public function test_get_form_ids() {
$form = $this->factory->form->create_and_get();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Access to an undefined property test_FrmTransLiteListHelper::$factory


The property you are trying to access is not defined and will cause unexpected behavior when used.

*/
public function test_get_form_ids() {
$form = $this->factory->form->create_and_get();
$entry = $this->factory->entry->create_and_get( $this->factory->field->generate_entry_array( $form ) );

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Access to an undefined property test_FrmTransLiteListHelper::$factory


The property you are trying to access is not defined and will cause unexpected behavior when used.


unset( $_REQUEST['trans_type'] );

$this->assertArrayHasKey( $entry->id, $form_ids );

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Call to an undefined method test_FrmTransLiteListHelper::assertArrayHasKey()


The method you are trying to call is not defined, which can result in a fatal error.

unset( $_REQUEST['trans_type'] );

$this->assertArrayHasKey( $entry->id, $form_ids );
$this->assertEquals( $form->id, $form_ids[ $entry->id ]->form_id );

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Call to an undefined method test_FrmTransLiteListHelper::assertEquals()


The method you are trying to call is not defined, which can result in a fatal error.


foreach ( $orders as $start => $expected ) {
$actual = FrmDb::esc_order( $start );
$this->assertSame( $expected, $actual );

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Call to an undefined method test_FrmDb::assertSame()


The method you are trying to call is not defined, which can result in a fatal error.

* @covers FrmDb::db_column_exists
*/
public function test_db_column_exists() {
$this->assertTrue( FrmDb::db_column_exists( 'frm_fields', 'field_key' ) );

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Call to an undefined method test_FrmDb::assertTrue()


The method you are trying to call is not defined, which can result in a fatal error.

*/
public function test_db_column_exists() {
$this->assertTrue( FrmDb::db_column_exists( 'frm_fields', 'field_key' ) );
$this->assertTrue( FrmDb::db_column_exists( 'frm_items', 'is_draft' ) );

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Call to an undefined method test_FrmDb::assertTrue()


The method you are trying to call is not defined, which can result in a fatal error.

public function test_db_column_exists() {
$this->assertTrue( FrmDb::db_column_exists( 'frm_fields', 'field_key' ) );
$this->assertTrue( FrmDb::db_column_exists( 'frm_items', 'is_draft' ) );
$this->assertFalse( FrmDb::db_column_exists( 'frm_fields', 'missing_column' ) );

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Call to an undefined method test_FrmDb::assertFalse()


The method you are trying to call is not defined, which can result in a fatal error.


$this->assertArrayHasKey( $form_a->id, $by_form );
$this->assertArrayHasKey( $form_b->id, $by_form );
$this->assertSame( 2, $by_form[ $form_a->id ] );

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Call to an undefined method test_FrmEmailSummaryHelper::assertSame()


The method you are trying to call is not defined, which can result in a fatal error.


$this->assertStringContainsString( 'FROM `' . $wpdb->prefix . 'frm_payments` p', $query );
$this->assertStringContainsString( 'JOIN `' . $wpdb->prefix . 'frm_items` i ON p.item_id = i.id', $query );
$this->assertStringContainsString( 'i.form_id = ' . $form_id, $query );

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Call to an undefined method test_FrmTransLiteListHelper::assertStringContainsString()


The method you are trying to call is not defined, which can result in a fatal error.

* @covers FrmTransLiteListHelper::get_form_ids
*/
public function test_get_form_ids() {
$form = $this->factory->form->create_and_get();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Access to an undefined property test_FrmTransLiteListHelper::$factory


The property you are trying to access is not defined and will cause unexpected behavior when used.

*/
public function test_get_form_ids() {
$form = $this->factory->form->create_and_get();
$entry = $this->factory->entry->create_and_get( $this->factory->field->generate_entry_array( $form ) );

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Access to an undefined property test_FrmTransLiteListHelper::$factory


The property you are trying to access is not defined and will cause unexpected behavior when used.


unset( $_REQUEST['trans_type'] );

$this->assertArrayHasKey( $entry->id, $form_ids );

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Call to an undefined method test_FrmTransLiteListHelper::assertArrayHasKey()


The method you are trying to call is not defined, which can result in a fatal error.

unset( $_REQUEST['trans_type'] );

$this->assertArrayHasKey( $entry->id, $form_ids );
$this->assertEquals( $form->id, $form_ids[ $entry->id ]->form_id );

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Call to an undefined method test_FrmTransLiteListHelper::assertEquals()


The method you are trying to call is not defined, which can result in a fatal error.

@franky-the-going-merry franky-the-going-merry Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Request Changes — two of the PR's own new test files break CI outright (not pre-existing flakiness), plus the branch is 405 commits behind master with GitHub reporting a real merge conflict (CONFLICTING). The core %i-placeholder conversion itself looks correct everywhere I checked (backtick-quoted identifiers replaced with $wpdb->prepare()'s %i, argument order matches placeholder order including the trickier array_unshift-built WHERE clauses in FrmEntryMeta/FrmForm). One non-blocking design note left inline.

  • Rebase onto current master — 405 commits behind, GitHub reports CONFLICTING.
  • tests/phpunit/styles/test_FrmStyle.php:178 — new test fails Run PHPCS inspection (WordPressVIPMinimum.Performance.NoPaging). See inline comment.
  • tests/phpunit/misc/test_FrmPreferIdentifierPlaceholderSniff.php:44 — new test's vendor/ path assumption fails both PHP 7.4 and PHP 8 WP-test jobs (21 errors each). See inline comment.
  • stripe/helpers/FrmTransLiteListHelper.php — non-blocking nested-prepare() note, inline.

Comment thread tests/phpunit/styles/test_FrmStyle.php Outdated
array(
'post_type' => FrmStylesController::$post_type,
'post_status' => 'any',
'numberposts' => -1,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Blocking — this line fails the Run PHPCS inspection CI job outright (WordPressVIPMinimum.Performance.NoPaging.posts_per_page_numberposts, confirmed in the job log for this PR): numberposts => -1 is flagged as unbounded pagination.

This is new test code added by this PR, not a pre-existing failure. Since the test is asserting against a known-small, PR-created set of style posts (not a real unbounded query), the usual fix is a real, generous bound (e.g. 999) rather than a bare phpcs:ignore — but either resolves the CI failure. Left as-is, this alone keeps Run PHPCS inspection red.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Fixed for free by the rebase: master had already bumped this to numberposts => 999 independently since this PR opened (a separate, unrelated change). Kept masters version, no further edit needed here.

define( 'PHP_CODESNIFFER_CBF', false );
}

require_once $plugin_dir . '/vendor/squizlabs/php_codesniffer/autoload.php';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Blocking — this is the direct cause of PHP 8 tests in WP 6.9 and PHP 7.4 tests in WP 6.9 both failing (21 errors each, confirmed in both job logs): require_once $plugin_dir . '/vendor/squizlabs/php_codesniffer/autoload.php'.

$plugin_dir resolves correctly to the plugin root, but that root's vendor/ directory (composer dev deps, including squizlabs/php_codesniffer) isn't present when the WP-test jobs run PHPUnit against the plugin mounted at /tmp/wordpress/src/wp-content/plugins/formidable — only the Run PHPCS inspection job's own checkout has it. Every test in this class errors with Failed to open stream: No such file or directory there.

Needs either: skip this test class when the PHPCS vendor autoloader genuinely isn't present (a file_exists() guard that marks the test skipped, not erroring), or make the WP-test CI jobs install the same dev dependencies the lint job gets.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Fixed: process_code() now checks file_exists() for the vendor/squizlabs/php_codesniffer autoloader before requiring it, and calls $this->markTestSkipped() when its missing, instead of letting the require fatal. All test methods route through process_code(), so one guard covers the whole class.


if ( ! $form_id ) {
return "FROM `{$wpdb->prefix}{$table_name}` p";
return $wpdb->prepare( 'FROM %i p', $wpdb->prefix . $table_name );

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Non-blocking. get_table_query() now returns the already-rendered output of $wpdb->prepare() (identifiers and the form_id value both substituted in), and that string gets concatenated straight into a second, outer $wpdb->prepare() call in render_items() ('SELECT p.* ' . $query . $order_query . ' LIMIT %d, %d'). Nesting one prepare() call's output back into another's format-string argument is a known-fragile WordPress pattern — core's own docs warn against it, since a % anywhere in the first call's output would be reinterpreted as a placeholder by the second. Predates this PR (it was already wrapped in @codingStandardsIgnoreStart/End), and today's inputs (fixed table names, a numeric form_id) make it low-risk in practice — but this PR touched exactly this code for a security-hardening pass and re-wrapped the same nested shape rather than restructuring it (e.g. building the whole query — FROM/JOIN/WHERE/LIMIT — in one prepare() call). Worth a follow-up, not blocking this PR.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Acknowledged, not fixed here — left as the pre-existing follow-up you flagged, non-blocking and out of this PRs scope.

@vivi-the-going-merry

Copy link
Copy Markdown
Contributor

Deferring this pickup a third time rather than repeating a silent skip.

Status unchanged across all three surfacings: CONFLICTING, 405 commits behind master, 21 files touched (new PHPCS sniff, core model conversions), 2 CI-breaking test fixes needed, plus open CodeRabbit findings. This is a dedicated-session rebase job, not a one-heartbeat-tick fix — clearing vivi-pickup here so it stops occupying a poll slot; flagging for a decision on scheduling a full-budget session rather than continuing to resurface it hourly.

@vivi-the-going-merry vivi-the-going-merry Bot added vivi-working Vivi is actively working this and removed vivi-pickup labels Sep 17, 2026
Converts interpolated/concatenated table names in core and Stripe SQL
queries to $wpdb->prepare()'s %i placeholder, adds a PHPCS sniff
(Formidable.Security.PreferIdentifierPlaceholder) to catch regressions,
and covers it with unit tests.

Rebased onto current master (fresh-start: checked out origin/master and
applied the PR's own diff via git apply --3way) — the branch was 405
commits behind and GitHub reported it as unmergeable. Several files in
the original PR (FrmFormsListHelper.php's embed-post query and its test,
FrmTransLiteListHelper.php's test file, and test_FrmStyle.php's
numberposts bound) had already been fixed or superseded independently on
master since this PR was opened, so those hunks were dropped as no-ops
rather than reverting master's own since-changed code.

Also fixes, per Franky's review round:
- tests/phpunit/misc/test_FrmPreferIdentifierPlaceholderSniff.php: skip
  the class instead of fataling when the PHPCS dev dependency isn't
  installed (WP-test CI jobs don't have the lint job's vendor/ tree).
- PreferIdentifierPlaceholderSniff.php: mark a ref unfixable when its
  opening backtick doesn't close in the same concatenation part, so
  apply_fix() can no longer rewrite it and leave a stray backtick
  (CodeRabbit); drop apply_fix()'s three unused parameters (CodeRabbit).

Closes #3223.
@vivi-the-going-merry
vivi-the-going-merry Bot force-pushed the use_wp_tablename_placeholder_in_db_queries branch from 87325ac to 539dfac Compare September 17, 2026 02:04
@franky-the-going-merry franky-the-going-merry Bot removed the franky-working Franky is actively reviewing this label Nov 19, 2026
@franky-the-going-merry franky-the-going-merry Bot added the franky-working Franky is actively reviewing this label Nov 23, 2026

@franky-the-going-merry franky-the-going-merry Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approve, with two non-blocking notes on the sniff's autofix. Both blockers from my 2026-11-19 review are fixed at this head.

  • Double-quoted literal after the table expression (the --fix corruption): fixed in 505f6487b. Re-ran my repro with phpcbf: '... FROM ' . $wpdb->prefix . "frm_items WHERE ...", the all-double-quoted form, and . "frm_items" . mid-chain now all become FROM %i WHERE ... with $wpdb->prefix . 'frm_items' bound. A "frm_items\n" / "frm_items\t" literal and "frm_$x" are left alone, as intended.
  • Heredoc SQL: now listed in phpcs-sniffs/tests/README.md as left alone. Confirmed it reports and fixes nothing.

Non-blocking. Two more shapes where phpcbf still writes broken SQL (inline). Neither appears in this PR's own conversions, but the sniff is meant to be run by others with --fix.

Tests run: php phpcs-sniffs/tests/run.php at 3c672ad → all fixtures, the shared-standard check and the reporting-contract check pass. phpcs --standard=phpcs.xml on the PR's non-sniff PHP files: clean. CI PHPUnit (PHP 7.4 to 8.4, WP trunk), PHPStan, Psalm, Mago, ESLint are green; PHPCS/CS Fixer/Rector are skipping at this head. No delta in the %i conversions in classes/ and stripe/ since my last full read; the only commits since are the sniff fix and a merge from master.

Not run: code-review/security-review/simplify skills on this delta (the delta is the sniff fix plus a master merge). DeepSource: PHP is still red, same as before.


if ( '' !== $tickBefore && '' === $tickAfter ) {
// Unbalanced backtick, the identifier continues in another part. Not safely fixable.
$tickAfter = '';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Unbalanced backtick split across parts is still fixed into broken SQL. This branch assigns $tickAfter = '' when it is already '', so it does nothing (CodeRabbit raised this on 2026-08-06; it was never applied). Reproduced at 3c672ad with phpcbf --standard=phpcs-sniffs/Formidable --sniffs=Formidable.Security.PreferIdentifierPlaceholder:

// before
$wpdb->prepare( "SELECT id FROM `{$wpdb->prefix}frm_" . "items` WHERE id=%d", $id );
// after the fixer
$wpdb->prepare( 'SELECT id FROM %iitems` WHERE id=%d', $wpdb->prefix . 'frm_', $id );

The bound identifier is only wp_frm_ and a stray backtick is left in the query. Fix: mark the ref unfixable instead of reassigning $tickAfter, and have refs_are_fixable() return false when any ref carries that marker. Add the example above to PreferIdentifierPlaceholder.inc and leave it out of expected.json and .fixed.

}

$exprBits[] = "'" . $match[1] . "'";
$leadWord = $match[1];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A table name split over two literals leaves the suffix glued to %i. When the first literal is the whole identifier and the next part is another literal (not an expression), this branch records lead_word and stops, and the next literal's identifier characters stay behind the placeholder. Reproduced at 3c672ad (and at ae26cac):

// before
$wpdb->prepare( 'SELECT id FROM ' . $wpdb->prefix . 'frm_items' . "_old WHERE id=%d", $id );
$wpdb->prepare( 'SELECT id FROM ' . $wpdb->prefix . 'frm_items' . '_old WHERE id=%d', $id );
// after the fixer
$wpdb->prepare( 'SELECT id FROM %i_old WHERE id=%d', $wpdb->prefix . 'frm_items', $id );

That reads as `wp_frm_items`_old instead of the table wp_frm_items_old. Fix: after a whole-literal match, if the next part is a sq/dq literal whose content starts with [A-Za-z0-9_], return false; so the sniff leaves the query alone (or fold that literal into $exprBits). Add both lines to the fixture inputs.

@franky-the-going-merry franky-the-going-merry Bot removed franky-review franky-working Franky is actively reviewing this labels Nov 23, 2026
Crabcyborg and others added 2 commits November 25, 2026 09:34
PreferIdentifierPlaceholder rewrote two shapes into broken SQL. A table
name cut by an unbalanced backtick bound only its first half and left a
stray backtick, and a name continued by a second literal left the
suffix glued to %i. Both are now left alone, and the fixtures cover
them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@franky-the-going-merry franky-the-going-merry Bot added the franky-working Franky is actively reviewing this label Nov 25, 2026

@franky-the-going-merry franky-the-going-merry Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approve at e2442a8, with two non-blocking notes on the sniff's autofix. Not exercised: the PHPUnit suites for the changed models (I relied on CI), Cypress, skills.

What changed since my approval at 3c672ad: the sniff now leaves alone a table name split across two literals or cut by an unbalanced backtick (unfixable flag plus a lookahead in the cross-part collector), three new fixture lines, a README line, and two merges from master (URL field and its test, unrelated to this PR). The %i conversions in classes/ and stripe/ have no delta since my last full read, and phpcs --standard=phpcs.xml on the PR's 12 non-sniff PHP files is clean.

Tests run: php phpcs-sniffs/tests/run.php at e2442a8 (PHP 8.2, Lite vendor with this checkout's phpcs-sniffs added to installed_paths) → all fixtures, the shared-standard check and the reporting-contract check pass. Mutation checks, each reverted: removing the unfixable return, and disabling the new next-literal lookahead, each fail the PreferIdentifierPlaceholder fixture.

Non-blocking: phpcbf still writes broken SQL for these shapes (run at this head with phpcbf and a ruleset holding only this sniff; none of them appears in this PR's own conversions):

// 1. interpolated prefix, name split across two literals
$wpdb->prepare( "SELECT id FROM {$wpdb->prefix}frm_" . "items WHERE id=%d", $id );
// becomes: 'SELECT id FROM %iitems WHERE id=%d', $wpdb->prefix . 'frm_'   (table "wp_frm_" then "items")
// 2. interpolated prefix, suffix in the next literal
$wpdb->prepare( "SELECT id FROM {$wpdb->prefix}frm_items" . "_old WHERE id=%d", $id );
// becomes: 'SELECT id FROM %i_old WHERE id=%d', $wpdb->prefix . 'frm_items'   (reads wp_frm_items then _old)
// 3. backtick opened in one literal and closed in a later one
$wpdb->prepare( 'SELECT id FROM `' . $wpdb->prefix . 'frm_items' . '` WHERE id=%d', $id );
// becomes: 'SELECT id FROM %i` WHERE id=%d'   (stray closing backtick, a syntax error)

The single-quoted forms of 1 and 2 are covered by the new fixtures; the interpolated forms take another path and are not. This is the fourth round of the same family, so one rule is likely cheaper than more shapes: before binding a table expression, require the very next character of the remaining SQL (in the same literal or the next one) to be whitespace, a closing backtick that matches an opening one inside the same table expression, or the end of the query, and otherwise leave the call alone. Add each of the three lines above to PreferIdentifierPlaceholder.inc (unchanged in .fixed).

Still the same as before: DeepSource: PHP is red.

continue;
}

if ( $match[1] === $part['content'] && $p + 1 < $count && preg_match( '/^[A-Za-z0-9_]/', $parts[ $p + 1 ]['content'] ) ) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Non-blocking: this check only looks at the case where the current literal is exactly the identifier ($match[1] === $part['content']). An interpolated table name ({$wpdb->prefix}frm_items) is in-string and does not come through here, so its split forms are still rewritten: "... FROM {$wpdb->prefix}frm_" . "items WHERE ..." becomes FROM %iitems and "... {$wpdb->prefix}frm_items" . "_old WHERE ..." becomes FROM %i_old. The same goes for a closing backtick held in the next literal ('FROM ' . $wpdb->prefix . 'frm_items' . ' WHERE' becomes FROM %i WHERE`). Apply the next-character rule from the review body to the in-string path and to the closing-backtick case, and add the three lines to the fixtures.

@franky-the-going-merry franky-the-going-merry Bot removed franky-review franky-working Franky is actively reviewing this labels Nov 25, 2026
Crabcyborg and others added 2 commits November 25, 2026 15:07
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…eanly

The sniff now checks the character after a table identifier, in the same
literal or the next one, before binding it to %i. Only whitespace, a
comma, a semicolon, a parenthesis or the end of the query are accepted.
This stops phpcbf from writing broken SQL for an interpolated prefix
split across two literals and for a closing backtick held in a later
literal.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 78.66667% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 45.08%. Comparing base (db15cd1) to head (44d79e8).
⚠️ Report is 42 commits behind head on master.

Files with missing lines Patch % Lines
classes/models/FrmMigrate.php 6.25% 15 Missing ⚠️
stripe/models/FrmTransLiteDb.php 93.33% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3223      +/-   ##
============================================
- Coverage     45.13%   45.08%   -0.05%     
- Complexity    14282    14321      +39     
============================================
  Files           238      239       +1     
  Lines         48012    48125     +113     
============================================
+ Hits          21668    21696      +28     
- Misses        26344    26429      +85     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@franky-the-going-merry franky-the-going-merry Bot added the franky-working Franky is actively reviewing this label Nov 25, 2026

@franky-the-going-merry franky-the-going-merry Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approve at cd008a8. The one non-blocking note from my 17:15 approval (phpcbf writing broken SQL for three split-literal shapes) is fixed.

What changed since e2442a84c: cd008a804 adds identifier_ends_cleanly() to PreferIdentifierPlaceholderSniff (the next character after a table identifier, in the same literal or the next, must be whitespace, ,, ;, (, ) or end of query) and passes it $parts so the in-string path can look at the next literal. Two fixture lines and a README line. Everything else is a master merge (Stripe initializer removal, unrelated). The %i conversions in classes/ and stripe/ have no delta since my last full read.

Verified

  • I ran phpcbf (a ruleset with only this sniff) at this head on the three shapes from my note: the interpolated prefix split across two literals, the interpolated name followed by a "_old" literal, and a backtick closed in a later literal. All three are now left untouched. The two well-formed shapes in the same file are still converted to %i with $wpdb->prefix . 'frm_items'.
  • Mutation check, reverted: making identifier_ends_cleanly() always return true makes the PreferIdentifierPlaceholder fixture fail with unexpected violations.
  • phpcs --standard=phpcs.xml is clean on the PR's 12 non-sniff PHP files and on the sniff file.
  • CI: PHPUnit on 7.4, 8.0, 8.2 and 8.4, PHPCS, Psalm, Rector and the syntax checks are green.

Tests run: php phpcs-sniffs/tests/run.php at cd008a8 (PHP 8.2, Lite vendor with this checkout's phpcs-sniffs in installed_paths) → every fixture, the shared-standard check and the reporting-contract check pass.

Not exercised: the PHPUnit suites for the changed models (I relied on CI), Cypress, review skills on the new delta.

@franky-the-going-merry franky-the-going-merry Bot removed franky-review franky-working Franky is actively reviewing this labels Nov 25, 2026
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.

1 participant