From 2673231f49129dc96ff3f8b27a9ec9b957c179e6 Mon Sep 17 00:00:00 2001 From: Mike Letellier Date: Mon, 19 Jan 2026 21:03:55 -0400 Subject: [PATCH 1/2] Update empty on param sniff to catch all params --- classes/controllers/FrmAddonsController.php | 2 +- classes/models/FrmDb.php | 2 +- classes/models/FrmForm.php | 2 +- classes/models/FrmFormApi.php | 2 +- .../RedundantEmptyOnParameterSniff.php | 51 +++++++++++++++---- stripe/models/FrmStrpLiteAuth.php | 2 +- 6 files changed, 47 insertions(+), 14 deletions(-) diff --git a/classes/controllers/FrmAddonsController.php b/classes/controllers/FrmAddonsController.php index b6f51c6cf1..08f9547130 100644 --- a/classes/controllers/FrmAddonsController.php +++ b/classes/controllers/FrmAddonsController.php @@ -771,7 +771,7 @@ public static function get_addon_for_license( $addons, $license ) { $download_id = $license->download_id; $plugin = array(); - if ( ! $download_id && ! empty( $addons ) ) { + if ( ! $download_id && $addons ) { foreach ( $addons as $addon ) { if ( strtolower( $license->plugin_name ) === strtolower( $addon['title'] ) ) { return $addon; diff --git a/classes/models/FrmDb.php b/classes/models/FrmDb.php index 0f8850ede4..6c49cfcb53 100644 --- a/classes/models/FrmDb.php +++ b/classes/models/FrmDb.php @@ -741,7 +741,7 @@ public static function check_cache( $cache_key, $group = '', $query = '', $type $found = null; $results = wp_cache_get( $cache_key, $group, false, $found ); - if ( ( $found === true && $results !== false ) || empty( $query ) ) { + if ( ( $found === true && $results !== false ) || ! $query ) { return $results; } diff --git a/classes/models/FrmForm.php b/classes/models/FrmForm.php index 171175a989..f99c6be98b 100644 --- a/classes/models/FrmForm.php +++ b/classes/models/FrmForm.php @@ -1250,7 +1250,7 @@ public static function is_form_loaded( $form, $this_load, $global_load ) { $frm_vars['forms_loaded'][] = $small_form; - if ( $this_load && empty( $global_load ) ) { + if ( $this_load && ! $global_load ) { $global_load = true; $frm_vars['load_css'] = true; } diff --git a/classes/models/FrmFormApi.php b/classes/models/FrmFormApi.php index 0f5fc8a71d..9d89f145bd 100644 --- a/classes/models/FrmFormApi.php +++ b/classes/models/FrmFormApi.php @@ -285,7 +285,7 @@ public function get_addon_for_license( $license_plugin, $addons = array() ) { $download_id = $license_plugin->download_id; $plugin = array(); - if ( ! $download_id && ! empty( $addons ) ) { + if ( ! $download_id && $addons ) { foreach ( $addons as $addon ) { if ( is_array( $addon ) && ! empty( $addon['title'] ) && strtolower( $license_plugin->plugin_name ) === strtolower( $addon['title'] ) ) { return $addon; diff --git a/phpcs-sniffs/Formidable/Sniffs/CodeAnalysis/RedundantEmptyOnParameterSniff.php b/phpcs-sniffs/Formidable/Sniffs/CodeAnalysis/RedundantEmptyOnParameterSniff.php index e86d1f153a..5a0cd9f99e 100644 --- a/phpcs-sniffs/Formidable/Sniffs/CodeAnalysis/RedundantEmptyOnParameterSniff.php +++ b/phpcs-sniffs/Formidable/Sniffs/CodeAnalysis/RedundantEmptyOnParameterSniff.php @@ -237,19 +237,25 @@ private function getFunctionParameters( File $phpcsFile, $functionToken ) { private function isInIfCondition( File $phpcsFile, $stackPtr ) { $tokens = $phpcsFile->getTokens(); - // Find the opening parenthesis that contains this empty() call. - // We need to find the parenthesis that belongs to an if/elseif statement. + // Track parenthesis nesting to find the outermost condition parenthesis. + $parenDepth = 0; + for ( $i = $stackPtr - 1; $i >= 0; $i-- ) { $code = $tokens[ $i ]['code']; - // Skip whitespace and the "!" operator. - if ( $code === T_WHITESPACE || $code === T_BOOLEAN_NOT ) { + // Track parenthesis nesting. + if ( $code === T_CLOSE_PARENTHESIS ) { + ++$parenDepth; continue; } - // If we hit an open parenthesis, check if it belongs to if/elseif. if ( $code === T_OPEN_PARENTHESIS ) { - // Check what's before this parenthesis. + if ( $parenDepth > 0 ) { + --$parenDepth; + continue; + } + + // This is an unmatched open paren - check if it belongs to if/elseif. $beforeParen = $phpcsFile->findPrevious( T_WHITESPACE, $i - 1, null, true ); if ( false !== $beforeParen ) { @@ -264,10 +270,37 @@ private function isInIfCondition( File $phpcsFile, $stackPtr ) { return false; } - // If we hit something else (like another function call), stop. - if ( $code !== T_OPEN_PARENTHESIS ) { - return false; + // Skip tokens that are valid inside an if condition. + if ( $code === T_WHITESPACE + || $code === T_BOOLEAN_NOT + || $code === T_BOOLEAN_AND + || $code === T_BOOLEAN_OR + || $code === T_LOGICAL_AND + || $code === T_LOGICAL_OR + || $code === T_VARIABLE + || $code === T_STRING + || $code === T_LNUMBER + || $code === T_DNUMBER + || $code === T_CONSTANT_ENCAPSED_STRING + || $code === T_TRUE + || $code === T_FALSE + || $code === T_NULL + || $code === T_ISSET + || $code === T_EMPTY + || $code === T_IS_EQUAL + || $code === T_IS_NOT_EQUAL + || $code === T_IS_IDENTICAL + || $code === T_IS_NOT_IDENTICAL + || $code === T_GREATER_THAN + || $code === T_LESS_THAN + || $code === T_IS_GREATER_OR_EQUAL + || $code === T_IS_SMALLER_OR_EQUAL + ) { + continue; } + + // Hit something unexpected, stop searching. + return false; } return false; diff --git a/stripe/models/FrmStrpLiteAuth.php b/stripe/models/FrmStrpLiteAuth.php index 6a33ede442..423396f8e9 100644 --- a/stripe/models/FrmStrpLiteAuth.php +++ b/stripe/models/FrmStrpLiteAuth.php @@ -341,7 +341,7 @@ private static function update_intent_pricing( $form_id, &$intents ) { $actions = FrmStrpLiteActionsController::get_actions_before_submit( $form_id ); - if ( ! $actions || empty( $intents ) ) { + if ( ! $actions || ! $intents ) { return; } From e6d1ed95253638f321fe32e7f4c52fecabe47fa0 Mon Sep 17 00:00:00 2001 From: Mike Letellier Date: Mon, 19 Jan 2026 21:12:39 -0400 Subject: [PATCH 2/2] Update it to also catch params by ref --- classes/models/FrmEntryValidate.php | 2 +- classes/models/fields/FrmFieldType.php | 2 +- .../Sniffs/CodeAnalysis/RedundantEmptyOnParameterSniff.php | 5 +++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/classes/models/FrmEntryValidate.php b/classes/models/FrmEntryValidate.php index 1015233633..45aabd2a77 100644 --- a/classes/models/FrmEntryValidate.php +++ b/classes/models/FrmEntryValidate.php @@ -547,7 +547,7 @@ public static function spam_check( $exclude, $values, &$errors ) { return; } - if ( $exclude || empty( $values['item_meta'] ) || ! empty( $errors ) ) { + if ( $exclude || empty( $values['item_meta'] ) || $errors ) { // only check spam if there are no other errors return; } diff --git a/classes/models/fields/FrmFieldType.php b/classes/models/fields/FrmFieldType.php index d8b84ada7e..c7b0dc8e04 100644 --- a/classes/models/fields/FrmFieldType.php +++ b/classes/models/fields/FrmFieldType.php @@ -132,7 +132,7 @@ protected function set_type( $type ) { if ( empty( $this->type ) ) { $this->type = $this->get_field_column( 'type' ); - if ( empty( $this->type ) && ! empty( $type ) ) { + if ( empty( $this->type ) && $type ) { $this->type = $type; } } diff --git a/phpcs-sniffs/Formidable/Sniffs/CodeAnalysis/RedundantEmptyOnParameterSniff.php b/phpcs-sniffs/Formidable/Sniffs/CodeAnalysis/RedundantEmptyOnParameterSniff.php index 5a0cd9f99e..687a83f7ed 100644 --- a/phpcs-sniffs/Formidable/Sniffs/CodeAnalysis/RedundantEmptyOnParameterSniff.php +++ b/phpcs-sniffs/Formidable/Sniffs/CodeAnalysis/RedundantEmptyOnParameterSniff.php @@ -295,6 +295,11 @@ private function isInIfCondition( File $phpcsFile, $stackPtr ) { || $code === T_LESS_THAN || $code === T_IS_GREATER_OR_EQUAL || $code === T_IS_SMALLER_OR_EQUAL + || $code === T_OBJECT_OPERATOR + || $code === T_NULLSAFE_OBJECT_OPERATOR + || $code === T_OPEN_SQUARE_BRACKET + || $code === T_CLOSE_SQUARE_BRACKET + || $code === T_DOUBLE_COLON ) { continue; }