diff --git a/classes/controllers/FrmAddonsController.php b/classes/controllers/FrmAddonsController.php index 8aa2f54548..ba4e06c7c6 100644 --- a/classes/controllers/FrmAddonsController.php +++ b/classes/controllers/FrmAddonsController.php @@ -442,7 +442,7 @@ public static function get_pro_license() { $creds = get_option( $pro_cred_store ); } - if ( empty( $creds ) || ! is_array( $creds ) || ! isset( $creds['license'] ) ) { + if ( ! $creds || ! is_array( $creds ) || ! isset( $creds['license'] ) ) { return ''; } @@ -498,7 +498,7 @@ public static function is_license_expired() { $expires = $version_info['error']['expires'] ?? 0; - if ( empty( $expires ) || $expires > time() ) { + if ( ! $expires || $expires > time() ) { return false; } @@ -521,7 +521,7 @@ public static function is_license_expired() { public static function get_primary_license_info() { $installed_addons = apply_filters( 'frm_installed_addons', array() ); - if ( empty( $installed_addons ) || ! isset( $installed_addons['formidable_pro'] ) ) { + if ( ! $installed_addons || ! isset( $installed_addons['formidable_pro'] ) ) { return false; } @@ -551,7 +551,7 @@ public static function check_update( $transient ) { $installed_addons = apply_filters( 'frm_installed_addons', array() ); - if ( empty( $installed_addons ) ) { + if ( ! $installed_addons ) { return $transient; } @@ -643,7 +643,7 @@ protected static function fill_update_addon_info( $installed_addons ) { $new_license = $addon->license; - if ( empty( $new_license ) || in_array( $new_license, $checked_licenses, true ) ) { + if ( ! $new_license || in_array( $new_license, $checked_licenses, true ) ) { continue; } @@ -651,20 +651,20 @@ protected static function fill_update_addon_info( $installed_addons ) { $api = new FrmFormApi( $new_license ); - if ( empty( $version_info ) ) { + if ( ! $version_info ) { $version_info = $api->get_api_info(); continue; } $plugin = $api->get_addon_for_license( $addon, $version_info ); - if ( empty( $plugin ) ) { + if ( ! $plugin ) { continue; } $download_id = $plugin['id'] ?? 0; - if ( ! empty( $download_id ) && ! isset( $version_info[ $download_id ]['package'] ) ) { + if ( $download_id && ! isset( $version_info[ $download_id ]['package'] ) ) { // if this addon is using its own license, get the update url $addon_info = $api->get_api_info(); @@ -775,7 +775,7 @@ public static function get_addon_for_license( $addons, $license ) { $download_id = $license->download_id; $plugin = array(); - if ( empty( $download_id ) && ! empty( $addons ) ) { + if ( ! $download_id && ! empty( $addons ) ) { foreach ( $addons as $addon ) { if ( strtolower( $license->plugin_name ) === strtolower( $addon['title'] ) ) { return $addon; @@ -1303,7 +1303,7 @@ protected static function install_addon_permissions() { public static function connect_link() { $auth = get_option( 'frm_connect_token' ); - if ( empty( $auth ) ) { + if ( ! $auth ) { $auth = hash( 'sha512', wp_rand() ); update_option( 'frm_connect_token', $auth, 'no' ); } diff --git a/classes/controllers/FrmAppController.php b/classes/controllers/FrmAppController.php index 0029eee390..02062e6081 100644 --- a/classes/controllers/FrmAppController.php +++ b/classes/controllers/FrmAppController.php @@ -62,7 +62,7 @@ public static function add_admin_class( $classes ) { $page = str_replace( 'formidable-', '', FrmAppHelper::simple_get( 'page', 'sanitize_title' ) ); - if ( empty( $page ) || $page === 'formidable' ) { + if ( ! $page || $page === 'formidable' ) { $action = FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' ); if ( in_array( $action, array( 'settings', 'edit', 'list' ), true ) ) { @@ -72,7 +72,7 @@ public static function add_admin_class( $classes ) { } } - if ( ! empty( $page ) ) { + if ( $page ) { $classes .= ' frm-admin-page-' . $page; } } diff --git a/classes/controllers/FrmEmailStylesController.php b/classes/controllers/FrmEmailStylesController.php index af257491c7..2c1a3b1d1c 100644 --- a/classes/controllers/FrmEmailStylesController.php +++ b/classes/controllers/FrmEmailStylesController.php @@ -305,7 +305,7 @@ public static function ajax_send_test_email() { foreach ( $emails as $email ) { $email = trim( $email ); - if ( empty( $email ) || ! is_email( $email ) ) { + if ( ! $email || ! is_email( $email ) ) { continue; } $valid_emails[] = $email; diff --git a/classes/controllers/FrmEntriesController.php b/classes/controllers/FrmEntriesController.php index 9c12c6a966..b1807f9a9f 100644 --- a/classes/controllers/FrmEntriesController.php +++ b/classes/controllers/FrmEntriesController.php @@ -250,7 +250,7 @@ private static function get_columns_for_form( $form_id, &$columns ) { private static function add_subform_cols( $field, $form_id, &$columns ) { $sub_form_cols = FrmField::get_all_for_form( $field->field_options['form_select'] ); - if ( empty( $sub_form_cols ) ) { + if ( ! $sub_form_cols ) { return; } @@ -526,7 +526,7 @@ public static function hidden_columns( $result ) { $i = isset( $frm_vars['cols'] ) ? count( $frm_vars['cols'] ) : 0; $max_columns = 11; - if ( ! empty( $hidden ) ) { + if ( $hidden ) { $result = $hidden; $i = $i - count( $result ); } diff --git a/classes/controllers/FrmFieldsController.php b/classes/controllers/FrmFieldsController.php index 67e8fbb579..c542d948d9 100644 --- a/classes/controllers/FrmFieldsController.php +++ b/classes/controllers/FrmFieldsController.php @@ -20,7 +20,7 @@ public static function load_field() { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized $fields = isset( $_POST['field'] ) ? wp_unslash( $_POST['field'] ) : array(); - if ( empty( $fields ) ) { + if ( ! $fields ) { wp_die(); } @@ -738,7 +738,7 @@ public static function get_default_value_from_name( $field ) { public static function add_placeholder_to_select( $field ) { $placeholder = FrmField::get_option( $field, 'placeholder' ); - if ( empty( $placeholder ) ) { + if ( ! $placeholder ) { $placeholder = self::get_default_value_from_name( $field ); } @@ -1010,7 +1010,7 @@ private static function add_shortcodes_to_html( $field, array &$add_html ) { if ( is_numeric( $k ) && str_contains( $v, '=' ) ) { $add_html[] = $v; - } elseif ( ! empty( $k ) && isset( $add_html[ $k ] ) ) { + } elseif ( $k && isset( $add_html[ $k ] ) ) { $add_html[ $k ] = str_replace( $k . '="', $k . '="' . $v, $add_html[ $k ] ); } else { $add_html[ $k ] = $k . '="' . esc_attr( $v ) . '"'; diff --git a/classes/controllers/FrmFormActionsController.php b/classes/controllers/FrmFormActionsController.php index 84d9fca3f1..4a0f9d4668 100644 --- a/classes/controllers/FrmFormActionsController.php +++ b/classes/controllers/FrmFormActionsController.php @@ -328,7 +328,7 @@ public static function show_action_icon_link( $action_control, $allowed ) { public static function get_form_actions( $action = 'all' ) { $temp_actions = self::$registered_actions; - if ( empty( $temp_actions ) ) { + if ( ! $temp_actions ) { self::actions_init(); $temp_actions = self::$registered_actions->actions; } else { @@ -486,7 +486,7 @@ public static function fill_action() { $action_control = self::get_form_actions( $action_type ); - if ( empty( $action_control ) ) { + if ( ! $action_control ) { wp_die(); } @@ -588,7 +588,7 @@ public static function update_settings( $form_id ) { foreach ( $registered_actions as $registered_action ) { $action_ids = $registered_action->update_callback( $form_id ); - if ( ! empty( $action_ids ) ) { + if ( $action_ids ) { $new_actions[] = $action_ids; } } @@ -658,7 +658,7 @@ public static function trigger_actions( $event, $form, $entry, $type = 'all', $a ); $form_actions = FrmFormAction::get_action_for_form( ( is_object( $form ) ? $form->id : $form ), $type, $action_status ); - if ( empty( $form_actions ) ) { + if ( ! $form_actions ) { return; } diff --git a/classes/controllers/FrmFormTemplatesController.php b/classes/controllers/FrmFormTemplatesController.php index 47c9f3a119..2b4bd2fa63 100644 --- a/classes/controllers/FrmFormTemplatesController.php +++ b/classes/controllers/FrmFormTemplatesController.php @@ -407,7 +407,7 @@ public static function ajax_get_free_templates() { $email = FrmAppHelper::get_post_param( 'email', '', 'sanitize_email' ); - if ( empty( $email ) || ! is_email( $email ) ) { + if ( ! $email || ! is_email( $email ) ) { wp_send_json_error( array( 'message' => __( 'Please enter a valid email address.', 'formidable' ) ), WP_Http::BAD_REQUEST diff --git a/classes/controllers/FrmFormsController.php b/classes/controllers/FrmFormsController.php index 6f99bc68e1..4f231333ce 100644 --- a/classes/controllers/FrmFormsController.php +++ b/classes/controllers/FrmFormsController.php @@ -1131,7 +1131,7 @@ public static function get_shortcode_opts() { $shortcode = FrmAppHelper::get_post_param( 'shortcode', '', 'sanitize_text_field' ); - if ( empty( $shortcode ) ) { + if ( ! $shortcode ) { wp_die(); } @@ -2033,7 +2033,7 @@ public static function process_bulk_form_actions( $errors ) { $bulkaction = FrmAppHelper::get_param( 'action2', '', 'get', 'sanitize_title' ); } - if ( ! empty( $bulkaction ) && str_starts_with( $bulkaction, 'bulk_' ) ) { + if ( $bulkaction && str_starts_with( $bulkaction, 'bulk_' ) ) { FrmAppHelper::remove_get_action(); $bulkaction = str_replace( 'bulk_', '', $bulkaction ); @@ -2041,7 +2041,7 @@ public static function process_bulk_form_actions( $errors ) { $ids = FrmAppHelper::get_param( 'item-action', '', 'get', 'sanitize_text_field' ); - if ( empty( $ids ) ) { + if ( ! $ids ) { $errors[] = __( 'No forms were specified', 'formidable' ); return $errors; @@ -2070,7 +2070,7 @@ public static function process_bulk_form_actions( $errors ) { $message = self::bulk_untrash( $ids ); } - if ( ! empty( $message ) ) { + if ( $message ) { $errors['message'] = $message; } @@ -2105,7 +2105,7 @@ public static function route() { // phpcs:ignore Generic.Metrics.CyclomaticCompl $json_vars = htmlspecialchars_decode( nl2br( str_replace( '"', '"', wp_unslash( $_POST['frm_compact_fields'] ) ) ) ); $json_vars = json_decode( $json_vars, true ); - if ( empty( $json_vars ) ) { + if ( ! $json_vars ) { // json decoding failed so we should return an error message. $action = FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' ); @@ -2567,7 +2567,7 @@ public static function get_form_contents( $form, $title, $description, $atts ) { if ( apply_filters( 'frm_continue_to_new', true, $form->id, $params['action'] ) ) { self::show_form_after_submit( $pass_args ); } - } elseif ( ! empty( $errors ) ) { + } elseif ( $errors ) { self::show_form_after_submit( $pass_args ); } else { @@ -2848,7 +2848,7 @@ public static function get_met_on_submit_actions( $args, $event = 'create' ) { */ $met_actions = apply_filters( 'frm_get_met_on_submit_actions', $met_actions, $args ); - if ( empty( $met_actions ) ) { + if ( ! $met_actions ) { $met_actions = array( FrmOnSubmitHelper::get_fallback_action( $event ) ); } @@ -3442,7 +3442,7 @@ public static function front_head() { $version = FrmAppHelper::plugin_version(); $suffix = FrmAppHelper::js_suffix(); - if ( ! empty( $suffix ) && self::has_combo_js_file() ) { + if ( $suffix && self::has_combo_js_file() ) { wp_register_script( 'formidable', FrmAppHelper::plugin_url() . '/js/frm.min.js', array( 'jquery' ), $version, true ); } else { wp_register_script( 'formidable', FrmAppHelper::plugin_url() . "/js/formidable{$suffix}.js", array( 'jquery' ), $version, true ); diff --git a/classes/controllers/FrmInboxController.php b/classes/controllers/FrmInboxController.php index 25aa5176e3..2945a73c01 100644 --- a/classes/controllers/FrmInboxController.php +++ b/classes/controllers/FrmInboxController.php @@ -59,7 +59,7 @@ public static function dismiss_message() { $key = FrmAppHelper::get_param( 'key', '', 'post', 'sanitize_text_field' ); - if ( ! empty( $key ) ) { + if ( $key ) { $message = new FrmInbox(); $message->dismiss( $key ); diff --git a/classes/controllers/FrmStylesController.php b/classes/controllers/FrmStylesController.php index 5fde3fafd5..789e3a5f9c 100644 --- a/classes/controllers/FrmStylesController.php +++ b/classes/controllers/FrmStylesController.php @@ -855,7 +855,7 @@ public static function custom_css( $message = '', $extra_args = array() ) { 'id' => $id, ); - if ( ! empty( $settings ) ) { + if ( $settings ) { $textarea_params['class'] = 'hide-if-js'; } include FrmAppHelper::plugin_path() . '/classes/views/styles/custom_css.php'; @@ -1228,7 +1228,7 @@ public static function get_form_style( $form = 'default' ) { $style = FrmFormsHelper::get_form_style( $form ); // phpcs:ignore Universal.Operators.StrictComparisons - if ( empty( $style ) || 1 == $style ) { + if ( ! $style || 1 == $style ) { $style = 'default'; } diff --git a/classes/controllers/FrmXMLController.php b/classes/controllers/FrmXMLController.php index dc337716dd..c198be420f 100644 --- a/classes/controllers/FrmXMLController.php +++ b/classes/controllers/FrmXMLController.php @@ -98,12 +98,12 @@ public static function install_template() { $pages = $imported['posts']; } - if ( ! empty( $form ) ) { + if ( $form ) { // Create selected pages with the correct shortcodes. $pages = self::create_pages_for_import( $form ); } - if ( ! empty( $pages ) ) { + if ( $pages ) { $post_id = end( $pages ); $response['redirect'] = get_permalink( $post_id ); } @@ -228,7 +228,7 @@ private static function create_pages_for_import( $form ) { $shortcode = '[' . esc_html( $for ) . ' id=%1$s]'; } - if ( empty( $item_key ) ) { + if ( ! $item_key ) { // Don't create it if the shortcode won't show anything. continue; } @@ -427,7 +427,7 @@ public static function import_xml() { public static function export_xml() { $error = FrmAppHelper::permission_nonce_error( 'frm_edit_forms', 'export-xml', 'export-xml-nonce' ); - if ( ! empty( $error ) ) { + if ( $error ) { wp_die( esc_html( $error ) ); } @@ -656,7 +656,7 @@ private static function get_file_name( $args, $records ) { } else { $sitename = sanitize_key( get_bloginfo( 'name' ) ); - if ( ! empty( $sitename ) ) { + if ( $sitename ) { $sitename .= '.'; } @@ -679,7 +679,7 @@ private static function get_file_name( $args, $records ) { public static function generate_csv( $atts ) { $form_ids = $atts['ids']; - if ( empty( $form_ids ) ) { + if ( ! $form_ids ) { wp_die( esc_html__( 'Please select a form', 'formidable' ) ); } self::csv( reset( $form_ids ) ); @@ -730,7 +730,7 @@ public static function csv( $form_id = false, $search = '', $fid = '' ) { $item_id = FrmAppHelper::get_param( 'item_id', 0, 'get', 'sanitize_text_field' ); - if ( ! empty( $item_id ) ) { + if ( $item_id ) { $item_id = explode( ',', $item_id ); } @@ -753,7 +753,7 @@ public static function csv( $form_id = false, $search = '', $fid = '' ) { $entry_ids = FrmDb::get_col( $wpdb->prefix . 'frm_items it', $query ); unset( $query ); - if ( empty( $entry_ids ) ) { + if ( ! $entry_ids ) { esc_html_e( 'There are no entries for that form.', 'formidable' ); } else { FrmCSVExportHelper::generate_csv( compact( 'form', 'entry_ids', 'form_cols' ) ); diff --git a/classes/helpers/FrmAppHelper.php b/classes/helpers/FrmAppHelper.php index 354ed4bc47..50f9df298b 100644 --- a/classes/helpers/FrmAppHelper.php +++ b/classes/helpers/FrmAppHelper.php @@ -101,7 +101,7 @@ public static function site_name() { public static function make_affiliate_url( $url ) { $affiliate_id = self::get_affiliate(); - if ( ! empty( $affiliate_id ) ) { + if ( $affiliate_id ) { $url = str_replace( array( 'http://', 'https://' ), '', $url ); $url = 'http://www.shareasale.com/r.cfm?u=' . absint( $affiliate_id ) . '&b=841990&m=64739&afftrack=plugin&urllink=' . urlencode( $url ); } @@ -438,7 +438,7 @@ public static function is_form_builder_page( $check_for_settings = true ) { public static function is_formidable_admin() { $page = self::simple_get( 'page', 'sanitize_title' ); - if ( empty( $page ) ) { + if ( ! $page ) { return self::is_view_builder_page(); } @@ -526,7 +526,7 @@ public static function is_view_builder_page() { $post_type = self::simple_get( 'post_type', 'sanitize_title' ); - if ( empty( $post_type ) ) { + if ( ! $post_type ) { $post_id = self::simple_get( 'post', 'absint' ); $post = get_post( $post_id ); $post_type = $post ? $post->post_type : ''; @@ -1320,13 +1320,13 @@ public static function remove_get_action() { $action_name = isset( $_GET['action'] ) ? 'action' : ( isset( $_GET['action2'] ) ? 'action2' : '' ); - if ( empty( $action_name ) ) { + if ( ! $action_name ) { return; } $new_action = self::get_param( $action_name, '', 'get', 'sanitize_text_field' ); - if ( ! empty( $new_action ) ) { + if ( $new_action ) { $_SERVER['REQUEST_URI'] = str_replace( '&action=' . $new_action, '', self::get_server_value( 'REQUEST_URI' ) ); } } diff --git a/classes/helpers/FrmEntriesHelper.php b/classes/helpers/FrmEntriesHelper.php index 07172ae38a..d86cbfaeca 100644 --- a/classes/helpers/FrmEntriesHelper.php +++ b/classes/helpers/FrmEntriesHelper.php @@ -261,7 +261,7 @@ public static function prepare_display_value( $entry, $field, $atts ) { $field_value = array(); - if ( empty( $child_entries ) ) { + if ( ! $child_entries ) { return ''; } diff --git a/classes/helpers/FrmEntriesListHelper.php b/classes/helpers/FrmEntriesListHelper.php index e0b18ff041..d73e9db361 100644 --- a/classes/helpers/FrmEntriesListHelper.php +++ b/classes/helpers/FrmEntriesListHelper.php @@ -207,7 +207,7 @@ public function no_items() { ) ); - if ( ! empty( $s ) ) { + if ( $s ) { esc_html_e( 'No Entries Found', 'formidable' ); return; diff --git a/classes/helpers/FrmFormsHelper.php b/classes/helpers/FrmFormsHelper.php index d889ea1260..9b2405f53a 100644 --- a/classes/helpers/FrmFormsHelper.php +++ b/classes/helpers/FrmFormsHelper.php @@ -569,7 +569,7 @@ public static function get_custom_submit( $html, $form, $submit, $form_action, $ $classes = apply_filters( 'frm_submit_button_class', array(), $form ); - if ( ! empty( $classes ) ) { + if ( $classes ) { $classes = implode( ' ', $classes ); $button_class = 'frm_button_submit'; diff --git a/classes/helpers/FrmListHelper.php b/classes/helpers/FrmListHelper.php index c095213e76..ece6140347 100644 --- a/classes/helpers/FrmListHelper.php +++ b/classes/helpers/FrmListHelper.php @@ -332,7 +332,7 @@ public function views() { */ $views = apply_filters( 'views_' . $this->screen->id, $views ); - if ( empty( $views ) ) { + if ( ! $views ) { return; } @@ -689,7 +689,7 @@ protected function pagination( $which ) { $pagination_links_class = 'pagination-links'; - if ( ! empty( $infinite_scroll ) ) { + if ( $infinite_scroll ) { $pagination_links_class = ' hide-if-js'; } @@ -864,7 +864,7 @@ protected function get_primary_column_name() { */ $column = apply_filters( 'list_table_primary_column', $default, $this->screen->id ); - if ( empty( $column ) || ! isset( $columns[ $column ] ) ) { + if ( ! $column || ! isset( $columns[ $column ] ) ) { $column = $default; } diff --git a/classes/helpers/FrmOnSubmitHelper.php b/classes/helpers/FrmOnSubmitHelper.php index 22d0386920..04bedc01b6 100644 --- a/classes/helpers/FrmOnSubmitHelper.php +++ b/classes/helpers/FrmOnSubmitHelper.php @@ -303,7 +303,7 @@ public static function maybe_migrate_submit_settings_to_action( $form_id ) { // Check if form already has form actions to avoid creating duplicates. $has_actions = FrmFormAction::form_has_action_type( $form_id, $action_type ); - if ( ! empty( $has_actions ) ) { + if ( $has_actions ) { // Don't migrate again. self::save_migrated_success_actions( $form ); return; diff --git a/classes/helpers/FrmStylesHelper.php b/classes/helpers/FrmStylesHelper.php index d9aa2b6bb8..740396fff5 100644 --- a/classes/helpers/FrmStylesHelper.php +++ b/classes/helpers/FrmStylesHelper.php @@ -699,7 +699,7 @@ public static function get_settings_for_output( $style ) { $settings['style_class'] = ''; - if ( ! empty( $style_name ) ) { + if ( $style_name ) { $settings['style_class'] = $style_name . '.'; } } else { diff --git a/classes/helpers/FrmXMLHelper.php b/classes/helpers/FrmXMLHelper.php index 5fd7dbc38c..f41a65f5cf 100644 --- a/classes/helpers/FrmXMLHelper.php +++ b/classes/helpers/FrmXMLHelper.php @@ -219,7 +219,7 @@ public static function import_xml_terms( $terms, $imported ) { private static function get_term_parent_id( $t ) { $parent = (string) $t->term_parent; - if ( ! empty( $parent ) ) { + if ( $parent ) { $parent = term_exists( (string) $t->term_parent, (string) $t->term_taxonomy ); $parent = $parent ? $parent['term_id'] : 0; @@ -250,7 +250,7 @@ public static function import_xml_forms( $forms, $imported ) { $old_id = false; $form_fields = false; - if ( ! empty( $this_form ) ) { + if ( $this_form ) { $form_id = $this_form->id; $old_id = $this_form->id; self::update_form( $this_form, $form, $imported ); @@ -1447,7 +1447,7 @@ private static function maybe_editing_post( &$post ) { $editing = get_posts( $match_by ); // phpcs:ignore Universal.Operators.StrictComparisons - if ( ! empty( $editing ) && current( $editing )->post_date == $post['post_date'] ) { + if ( $editing && current( $editing )->post_date == $post['post_date'] ) { // set the id of the post to edit $post['ID'] = current( $editing )->ID; } @@ -1552,7 +1552,7 @@ public static function parse_message( $result, &$message, &$errors ) { } } - if ( ! empty( $error_details ) ) { + if ( $error_details ) { $errors[] = '
' . esc_html_x( 'Error details:', 'import xml message', 'formidable' ) . '
' . esc_html( print_r( $error_details, 1 ) ); } @@ -1675,7 +1675,7 @@ private static function add_form_link_to_message( $result, &$message ) { $primary_form = reset( $result['forms'] ); - if ( ! empty( $primary_form ) ) { + if ( $primary_form ) { $primary_form = FrmForm::getOne( $primary_form ); $form_id = empty( $primary_form->parent_form_id ) ? $primary_form->id : $primary_form->parent_form_id; @@ -2132,7 +2132,7 @@ private static function migrate_email_settings_to_action( $form_options, $form_i ) ); - if ( empty( $exists ) ) { + if ( ! $exists ) { FrmDb::save_json_post( $new_notification ); ++$imported['imported']['actions']; } @@ -2390,11 +2390,11 @@ private static function migrate_autoresponder_to_action( $form_options, $form_id $reply_to = $notification['ar_reply_to'] ?? ''; $reply_to_name = $notification['ar_reply_to_name'] ?? ''; - if ( ! empty( $reply_to ) ) { + if ( $reply_to ) { $new_notification2['post_content']['reply_to'] = $reply_to; } - if ( ! empty( $reply_to ) || ! empty( $reply_to_name ) ) { + if ( $reply_to || ! empty( $reply_to_name ) ) { $new_notification2['post_content']['from'] = ( empty( $reply_to_name ) ? '[sitename]' : $reply_to_name ) . ' <' . ( empty( $reply_to ) ? '[admin_email]' : $reply_to ) . '>'; } diff --git a/classes/models/FrmAddon.php b/classes/models/FrmAddon.php index 7165587b09..97deff86cb 100644 --- a/classes/models/FrmAddon.php +++ b/classes/models/FrmAddon.php @@ -163,7 +163,7 @@ public function edd_plugin_updater() { add_action( 'after_plugin_row_' . plugin_basename( $this->plugin_file ), array( $this, 'maybe_show_license_message' ), 10, 2 ); - if ( ! empty( $license ) ) { + if ( $license ) { if ( 'formidable/formidable.php' !== $this->plugin_folder ) { add_filter( 'plugins_api', array( &$this, 'plugins_api_filter' ), 10, 3 ); @@ -230,7 +230,7 @@ public function plugins_api_filter( $_data, $_action = '', $_args = null ) { public function get_license() { $license = $this->maybe_get_pro_license(); - if ( ! empty( $license ) ) { + if ( $license ) { return $license; } @@ -283,7 +283,7 @@ protected function maybe_get_pro_license() { public function activate_defined_license() { $license = $this->get_defined_license(); - if ( ! empty( $license ) && ! $this->is_active() && ! $this->checked_recently( '1 day' ) ) { + if ( $license && ! $this->is_active() && ! $this->checked_recently( '1 day' ) ) { $response = $this->activate_license( $license ); if ( ! $response['success'] ) { @@ -485,7 +485,7 @@ public function show_license_message( $file, $plugin ) { $api = new FrmFormApi( $this->license ); $errors = $api->error_for_license(); - if ( ! empty( $errors ) ) { + if ( $errors ) { $message = reset( $errors ); } } @@ -605,7 +605,7 @@ protected function get_api_info( $license ) { private function clear_old_plugin_version( &$version_info ) { $timeout = ! empty( $version_info->timeout ) ? $version_info->timeout : 0; - if ( ! empty( $timeout ) && time() > $timeout ) { + if ( $timeout && time() > $timeout ) { // Cache is expired. $version_info = false; $api = new FrmFormApi( $this->license ); diff --git a/classes/models/FrmCreateFile.php b/classes/models/FrmCreateFile.php index 619eb375dc..940c9f1108 100644 --- a/classes/models/FrmCreateFile.php +++ b/classes/models/FrmCreateFile.php @@ -174,7 +174,7 @@ private function check_permission() { $this->has_permission = true; - if ( empty( $creds ) || ! WP_Filesystem( $creds ) ) { + if ( ! $creds || ! WP_Filesystem( $creds ) ) { // initialize the API - any problems and we exit $this->show_error_message(); $this->has_permission = false; diff --git a/classes/models/FrmDb.php b/classes/models/FrmDb.php index 33f7fd9dbe..7c05b7ffb5 100644 --- a/classes/models/FrmDb.php +++ b/classes/models/FrmDb.php @@ -841,7 +841,7 @@ public static function delete_cache_and_transient( $cache_key, $group = 'default public static function cache_delete_group( $group ) { $cached_keys = self::get_group_cached_keys( $group ); - if ( ! empty( $cached_keys ) ) { + if ( $cached_keys ) { foreach ( $cached_keys as $key ) { wp_cache_delete( $key, $group ); } diff --git a/classes/models/FrmEntryMeta.php b/classes/models/FrmEntryMeta.php index f0f444bd2e..18d6885265 100644 --- a/classes/models/FrmEntryMeta.php +++ b/classes/models/FrmEntryMeta.php @@ -170,7 +170,7 @@ public static function update_entry_metas( $entry_id, $values ) { } }//end foreach - if ( empty( $previous_field_ids ) ) { + if ( ! $previous_field_ids ) { return; } diff --git a/classes/models/FrmEntryValidate.php b/classes/models/FrmEntryValidate.php index 4b0991e6ac..c5ac10264f 100644 --- a/classes/models/FrmEntryValidate.php +++ b/classes/models/FrmEntryValidate.php @@ -437,7 +437,7 @@ public static function validate_field_types( &$errors, $posted_field, $value, $a $new_errors = $field_obj->validate( $args ); - if ( ! empty( $new_errors ) ) { + if ( $new_errors ) { $errors = array_merge( $errors, $new_errors ); } } diff --git a/classes/models/FrmField.php b/classes/models/FrmField.php index 55244dd803..649cb387ae 100644 --- a/classes/models/FrmField.php +++ b/classes/models/FrmField.php @@ -903,7 +903,7 @@ public static function get_all_types_in_form( $form_id, $type, $limit = '', $inc ) ); - if ( ! empty( $results ) ) { + if ( $results ) { $fields = array(); $count = 0; @@ -960,7 +960,7 @@ public static function get_all_for_form( $form_id, $limit = '', $inc_embed = 'ex $results = self::get_fields_from_transients( $form_id, compact( 'inc_embed', 'inc_repeat' ) ); - if ( ! empty( $results ) ) { + if ( $results ) { if ( ! $limit ) { return $results; } @@ -1052,7 +1052,7 @@ public static function include_sub_fields( &$results, $inc_embed, $type = 'all', $sub_fields = self::get_all_types_in_form( $field->field_options['form_select'], $type ); } - if ( ! empty( $sub_fields ) ) { + if ( $sub_fields ) { $index = $k + $index_offset; $index_offset += count( $sub_fields ); array_splice( $results, $index, 0, $sub_fields ); @@ -1337,7 +1337,7 @@ public static function get_original_field_type( $field ) { $field_type = self::get_field_type( $field ); $original_type = self::get_option( $field, 'original_type' ); - if ( ! empty( $original_type ) && $original_type !== $field_type ) { + if ( $original_type && $original_type !== $field_type ) { // Check the original type for arrays. $field_type = $original_type; } diff --git a/classes/models/FrmFieldFormHtml.php b/classes/models/FrmFieldFormHtml.php index ed24cd6acb..3459c3681b 100644 --- a/classes/models/FrmFieldFormHtml.php +++ b/classes/models/FrmFieldFormHtml.php @@ -288,7 +288,7 @@ private function replace_error_shortcode() { $this->maybe_add_error_id(); $error = $this->pass_args['errors'][ 'field' . $this->field_id ] ?? false; - if ( ! empty( $error ) && ! str_contains( $this->html, 'role="alert"' ) && FrmAppHelper::should_include_alert_role_on_field_errors() ) { + if ( $error && ! str_contains( $this->html, 'role="alert"' ) && FrmAppHelper::should_include_alert_role_on_field_errors() ) { $error_body = self::get_error_body( $this->html ); if ( is_string( $error_body ) && ! str_contains( $error_body, 'role=' ) ) { @@ -545,7 +545,7 @@ private function get_field_div_classes() { // Add CSS layout classes $extra_classes = $this->field_obj->get_field_column( 'classes' ); - if ( ! empty( $extra_classes ) ) { + if ( $extra_classes ) { if ( ! str_contains( $this->html, 'frm_form_field ' ) ) { $classes .= ' frm_form_field'; } diff --git a/classes/models/FrmForm.php b/classes/models/FrmForm.php index ee1fbbba4a..7bc7b93d2b 100644 --- a/classes/models/FrmForm.php +++ b/classes/models/FrmForm.php @@ -277,7 +277,7 @@ public static function update( $id, $values, $create_link = false ) { $new_values['status'] = $values['new_status']; } - if ( ! empty( $new_values ) ) { + if ( $new_values ) { $query_results = $wpdb->update( $wpdb->prefix . 'frm_forms', $new_values, array( 'id' => $id ) ); if ( $query_results ) { diff --git a/classes/models/FrmFormAction.php b/classes/models/FrmFormAction.php index 0c4bc8f70f..fe932ff7a3 100644 --- a/classes/models/FrmFormAction.php +++ b/classes/models/FrmFormAction.php @@ -601,7 +601,7 @@ public function get_one( $form_id ) { public static function get_action_for_form( $form_id, $type = 'all', $atts = array() ) { $action_controls = FrmFormActionsController::get_form_actions( $type ); - if ( empty( $action_controls ) ) { + if ( ! $action_controls ) { // don't continue if there are no available actions return array(); } @@ -754,7 +754,7 @@ public function get_all( $form_id = false, $atts = array() ) { remove_filter( 'posts_where', 'FrmFormActionsController::limit_by_type' ); - if ( empty( $actions ) ) { + if ( ! $actions ) { return array(); } @@ -938,7 +938,7 @@ public function migrate_to_2( $form, $update = 'update' ) { ) ); - if ( empty( $post_id ) ) { + if ( ! $post_id ) { // create action now $post_id = $this->save_settings( $action ); } diff --git a/classes/models/FrmFormApi.php b/classes/models/FrmFormApi.php index 264dffa252..f85bd5464e 100644 --- a/classes/models/FrmFormApi.php +++ b/classes/models/FrmFormApi.php @@ -50,7 +50,7 @@ private function set_license( $license ) { if ( $license === null ) { $edd_update = $this->get_pro_updater(); - if ( ! empty( $edd_update ) ) { + if ( $edd_update ) { $license = $edd_update->license; } } @@ -260,7 +260,7 @@ public function get_addon_for_license( $license_plugin, $addons = array() ) { $download_id = $license_plugin->download_id; $plugin = array(); - if ( empty( $download_id ) && ! empty( $addons ) ) { + if ( ! $download_id && ! empty( $addons ) ) { foreach ( $addons as $addon ) { if ( is_array( $addon ) && ! empty( $addon['title'] ) && strtolower( $license_plugin->plugin_name ) === strtolower( $addon['title'] ) ) { return $addon; @@ -297,7 +297,7 @@ public function get_pro_updater() { protected function get_cached() { $cache = $this->get_cached_option(); - if ( empty( $cache ) ) { + if ( ! $cache ) { return false; } diff --git a/classes/models/FrmFormMigrator.php b/classes/models/FrmFormMigrator.php index 7f75543643..b9a2224640 100644 --- a/classes/models/FrmFormMigrator.php +++ b/classes/models/FrmFormMigrator.php @@ -215,7 +215,7 @@ protected function import_form( $source_id ) { $this->current_source_form = $source_form; // If form does not contain fields, bail. - if ( empty( $source_fields ) ) { + if ( ! $source_fields ) { wp_send_json_success( array( 'error' => true, diff --git a/classes/models/FrmMigrate.php b/classes/models/FrmMigrate.php index a1e9a1daaf..4404a30415 100644 --- a/classes/models/FrmMigrate.php +++ b/classes/models/FrmMigrate.php @@ -544,7 +544,7 @@ private function migrate_to_placeholder( $type = 'clear_on_focus' ) { FrmAppHelper::unserialize_or_decode( $field->options ); $update_values = FrmXMLHelper::migrate_field_placeholder( $field, $type ); - if ( empty( $update_values ) ) { + if ( ! $update_values ) { continue; } @@ -596,7 +596,7 @@ private function migrate_to_86() { // reverse the extra size changes in widgets $widgets = get_option( 'widget_frm_show_form' ); - if ( empty( $widgets ) ) { + if ( ! $widgets ) { return; } @@ -641,7 +641,7 @@ private function get_fields_with_size() { private function revert_widget_field_size() { $widgets = get_option( 'widget_frm_show_form' ); - if ( empty( $widgets ) ) { + if ( ! $widgets ) { return; } @@ -697,7 +697,7 @@ private function migrate_to_25() { $frm_style = new FrmStyle(); $styles = $frm_style->get_all( 'post_date', 'ASC', 1 ); - if ( empty( $styles ) ) { + if ( ! $styles ) { return; } @@ -723,7 +723,7 @@ private function migrate_to_23() { global $wpdb; $exists = $wpdb->get_row( 'SHOW COLUMNS FROM ' . $this->forms . ' LIKE "parent_form_id"' ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared - if ( empty( $exists ) ) { + if ( ! $exists ) { $wpdb->query( 'ALTER TABLE ' . $this->forms . ' ADD parent_form_id int(11) default 0' ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared } } @@ -760,7 +760,7 @@ private function migrate_to_17() { private function adjust_widget_size() { $widgets = get_option( 'widget_frm_show_form' ); - if ( empty( $widgets ) ) { + if ( ! $widgets ) { return; } diff --git a/classes/models/FrmPluginSearch.php b/classes/models/FrmPluginSearch.php index f05d9f7acb..f99dcc2422 100644 --- a/classes/models/FrmPluginSearch.php +++ b/classes/models/FrmPluginSearch.php @@ -209,7 +209,7 @@ public function plugin_details( $url ) { private function maybe_dismiss() { $addon = FrmAppHelper::get_param( 'frm-dismiss', '', 'get', 'absint' ); - if ( ! empty( $addon ) ) { + if ( $addon ) { $this->add_to_dismissed_hints( $addon ); } } diff --git a/classes/models/FrmReviews.php b/classes/models/FrmReviews.php index 9e23acf992..e8c436d43a 100644 --- a/classes/models/FrmReviews.php +++ b/classes/models/FrmReviews.php @@ -109,7 +109,7 @@ private function review() { $name = $user->first_name; - if ( ! empty( $name ) ) { + if ( $name ) { $name = ' ' . $name; } diff --git a/classes/models/FrmSolution.php b/classes/models/FrmSolution.php index 621a66cd65..77d69020e0 100644 --- a/classes/models/FrmSolution.php +++ b/classes/models/FrmSolution.php @@ -408,7 +408,7 @@ protected function get_steps_data() { protected function adjust_plugin_install_step( &$steps ) { $plugins = $this->required_plugins(); - if ( empty( $plugins ) ) { + if ( ! $plugins ) { unset( $steps['plugin'] ); $steps['import']['num'] = 2; $steps['complete']['num'] = 3; @@ -682,7 +682,7 @@ protected function show_import_options( $options, $importing, $xml = '' ) { protected function show_page_options() { $pages = $this->needed_pages(); - if ( empty( $pages ) ) { + if ( ! $pages ) { return; } diff --git a/classes/models/FrmSpamCheckWPDisallowedWords.php b/classes/models/FrmSpamCheckWPDisallowedWords.php index 9e50ac9966..7068ba17b2 100644 --- a/classes/models/FrmSpamCheckWPDisallowedWords.php +++ b/classes/models/FrmSpamCheckWPDisallowedWords.php @@ -16,7 +16,7 @@ class FrmSpamCheckWPDisallowedWords extends FrmSpamCheck { public function check() { $mod_keys = trim( $this->get_disallowed_words() ); - if ( empty( $mod_keys ) ) { + if ( ! $mod_keys ) { return false; } diff --git a/classes/models/FrmStyle.php b/classes/models/FrmStyle.php index 566b2594af..5b0ce0b7a1 100644 --- a/classes/models/FrmStyle.php +++ b/classes/models/FrmStyle.php @@ -240,7 +240,7 @@ private function maybe_sanitize_rgba_value( &$color_val ) { // phpcs:ignore Slev $insert_values = 4 === $length_of_color_codes ? array( 1 ) : array( 0 ); } - if ( ! empty( $insert_values ) ) { + if ( $insert_values ) { $new_color_values = array_merge( $new_color_values, $insert_values ); } @@ -523,13 +523,13 @@ public function get_all( $orderby = 'title', $order = 'ASC', $limit = 99 ) { $temp_styles = FrmDb::check_cache( json_encode( $post_atts ), 'frm_styles', $post_atts, 'get_posts' ); - if ( empty( $temp_styles ) ) { + if ( ! $temp_styles ) { global $wpdb; // make sure there wasn't a conflict with the query $query = $wpdb->prepare( 'SELECT * FROM ' . $wpdb->posts . ' WHERE post_type=%s AND post_status=%s ORDER BY post_title ASC LIMIT 99', FrmStylesController::$post_type, 'publish' ); $temp_styles = FrmDb::check_cache( 'frm_backup_style_check', 'frm_styles', $query, 'get_results' ); - if ( empty( $temp_styles ) ) { + if ( ! $temp_styles ) { // create a new style if there are none $new = $this->get_new(); $new->post_title = __( 'Formidable Style', 'formidable' ); @@ -853,7 +853,7 @@ public function force_balanced_quotation( $value ) { public function get_default_template_style( $style_id ) { $default_template = get_post_meta( (int) $style_id, $this->default_template_style_meta_name, true ); - if ( empty( $default_template ) ) { + if ( ! $default_template ) { return FrmAppHelper::prepare_and_encode( $this->get_defaults() ); } diff --git a/classes/models/fields/FrmFieldDefault.php b/classes/models/fields/FrmFieldDefault.php index 42cd78fcaa..b2ab77baf8 100644 --- a/classes/models/fields/FrmFieldDefault.php +++ b/classes/models/fields/FrmFieldDefault.php @@ -41,7 +41,7 @@ public function show_on_form_builder( $name = '' ) { $input_html = ob_get_contents(); ob_end_clean(); - if ( empty( $input_html ) ) { + if ( ! $input_html ) { echo $this->builder_text_field( $name ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } else { echo $input_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped diff --git a/classes/models/fields/FrmFieldType.php b/classes/models/fields/FrmFieldType.php index a2f82d7083..d8e8a6ffa3 100644 --- a/classes/models/fields/FrmFieldType.php +++ b/classes/models/fields/FrmFieldType.php @@ -270,7 +270,7 @@ public function show_on_form_builder( $name = '' ) { $field = FrmFieldsHelper::setup_edit_vars( $this->field ); $include_file = $this->include_form_builder_file(); - if ( ! empty( $include_file ) ) { + if ( $include_file ) { $this->include_on_form_builder( $name, $field ); } elseif ( $this->has_input ) { echo $this->builder_text_field( $name ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped @@ -1073,7 +1073,7 @@ public function get_container_class() { $class = ''; - if ( ! empty( $align ) && ( $is_radio || $is_checkbox ) ) { + if ( $align && ( $is_radio || $is_checkbox ) ) { self::prepare_align_class( $align ); $class .= ' ' . $align; } @@ -1114,7 +1114,7 @@ protected function add_input_class() { $input_class = FrmField::get_option( $this->field, 'input_class' ); $extra_classes = $this->get_input_class(); - if ( ! empty( $extra_classes ) ) { + if ( $extra_classes ) { $input_class .= ' ' . $extra_classes; } @@ -1161,7 +1161,7 @@ public function set_aria_invalid_error( &$shortcode_atts, $args ) { public function include_front_field_input( $args, $shortcode_atts ) { $include_file = $this->include_front_form_file(); - if ( ! empty( $include_file ) ) { + if ( $include_file ) { $input = $this->include_on_front_form( $args, $shortcode_atts ); } else { $input = $this->front_field_input( $args, $shortcode_atts ); @@ -1190,7 +1190,7 @@ protected function include_on_front_form( $args, $shortcode_atts ) { $include_file = $this->include_front_form_file(); - if ( empty( $include_file ) ) { + if ( ! $include_file ) { return null; } diff --git a/classes/models/fields/FrmFieldUrl.php b/classes/models/fields/FrmFieldUrl.php index a9d2a40c54..374f79edfa 100644 --- a/classes/models/fields/FrmFieldUrl.php +++ b/classes/models/fields/FrmFieldUrl.php @@ -80,7 +80,7 @@ public function validate( $args ) { $errors = array(); // validate the url format - if ( ! empty( $value ) && ! preg_match( '/^http(s)?:\/\/(?:localhost|(?:[\da-z\.-]+\.[\da-z\.-]+))/i', $value ) ) { + if ( $value && ! preg_match( '/^http(s)?:\/\/(?:localhost|(?:[\da-z\.-]+\.[\da-z\.-]+))/i', $value ) ) { $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $this->field, 'invalid' ); } elseif ( $this->field->required == '1' && empty( $value ) ) { // phpcs:ignore Universal.Operators.StrictComparisons $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $this->field, 'blank' ); diff --git a/phpcs-sniffs/Formidable/Sniffs/CodeAnalysis/RedundantEmptyOnAssignedVariableSniff.php b/phpcs-sniffs/Formidable/Sniffs/CodeAnalysis/RedundantEmptyOnAssignedVariableSniff.php new file mode 100644 index 0000000000..4171b89b17 --- /dev/null +++ b/phpcs-sniffs/Formidable/Sniffs/CodeAnalysis/RedundantEmptyOnAssignedVariableSniff.php @@ -0,0 +1,270 @@ +getTokens(); + + // Only process if empty() is directly inside an if/elseif condition. + if ( ! $this->isInIfCondition( $phpcsFile, $stackPtr ) ) { + return; + } + + // Find the opening parenthesis after empty. + $openParen = $phpcsFile->findNext( T_WHITESPACE, $stackPtr + 1, null, true ); + + if ( false === $openParen || $tokens[ $openParen ]['code'] !== T_OPEN_PARENTHESIS ) { + return; + } + + // Find the variable inside empty(). + $variablePtr = $phpcsFile->findNext( T_WHITESPACE, $openParen + 1, null, true ); + + if ( false === $variablePtr || $tokens[ $variablePtr ]['code'] !== T_VARIABLE ) { + return; + } + + $variableName = $tokens[ $variablePtr ]['content']; + + // Check if there's anything else inside the empty() call (like array access). + $closeParen = $tokens[ $openParen ]['parenthesis_closer']; + $nextToken = $phpcsFile->findNext( T_WHITESPACE, $variablePtr + 1, $closeParen, true ); + + if ( false !== $nextToken ) { + // There's something after the variable (like array access $var['key']). + // Skip this case as it's more complex. + return; + } + + // Find the containing function. + $functionToken = $this->findContainingFunction( $phpcsFile, $stackPtr ); + + if ( false === $functionToken ) { + return; + } + + // Check if the variable was assigned earlier in this function. + if ( ! $this->wasVariableAssigned( $phpcsFile, $functionToken, $stackPtr, $variableName ) ) { + return; + } + + // Check if there's a boolean NOT before empty. + $prevToken = $phpcsFile->findPrevious( T_WHITESPACE, $stackPtr - 1, null, true ); + $isNegated = ( false !== $prevToken && $tokens[ $prevToken ]['code'] === T_BOOLEAN_NOT ); + + // Determine the suggested replacement. + if ( $isNegated ) { + $suggestion = $variableName; + $message = 'Redundant empty() on assigned variable %s. Use "%s" instead of "! empty( %s )"'; + } else { + $suggestion = '! ' . $variableName; + $message = 'Redundant empty() on assigned variable %s. Use "%s" instead of "empty( %s )"'; + } + + $fix = $phpcsFile->addFixableError( + $message, + $stackPtr, + 'Found', + array( $variableName, $suggestion, $variableName ) + ); + + if ( true === $fix ) { + $phpcsFile->fixer->beginChangeset(); + + if ( $isNegated ) { + // Remove the "!" before empty. + $phpcsFile->fixer->replaceToken( $prevToken, '' ); + + // Remove any whitespace between "!" and "empty". + for ( $i = $prevToken + 1; $i < $stackPtr; $i++ ) { + if ( $tokens[ $i ]['code'] === T_WHITESPACE ) { + $phpcsFile->fixer->replaceToken( $i, '' ); + } + } + } + + // Replace empty( $var ) with $var or ! $var. + $phpcsFile->fixer->replaceToken( $stackPtr, '' ); + + // Remove whitespace after empty. + for ( $i = $stackPtr + 1; $i < $openParen; $i++ ) { + if ( $tokens[ $i ]['code'] === T_WHITESPACE ) { + $phpcsFile->fixer->replaceToken( $i, '' ); + } + } + + // Replace opening paren. + $phpcsFile->fixer->replaceToken( $openParen, '' ); + + // Remove whitespace after opening paren. + $nextAfterOpen = $openParen + 1; + + while ( $nextAfterOpen < $variablePtr && $tokens[ $nextAfterOpen ]['code'] === T_WHITESPACE ) { + $phpcsFile->fixer->replaceToken( $nextAfterOpen, '' ); + ++$nextAfterOpen; + } + + // Keep the variable, but add "! " prefix if not negated. + if ( ! $isNegated ) { + $phpcsFile->fixer->addContentBefore( $variablePtr, '! ' ); + } + + // Remove whitespace before closing paren. + $prevBeforeClose = $closeParen - 1; + + while ( $prevBeforeClose > $variablePtr && $tokens[ $prevBeforeClose ]['code'] === T_WHITESPACE ) { + $phpcsFile->fixer->replaceToken( $prevBeforeClose, '' ); + --$prevBeforeClose; + } + + // Replace closing paren. + $phpcsFile->fixer->replaceToken( $closeParen, '' ); + + $phpcsFile->fixer->endChangeset(); + } + } + + /** + * Check if the empty() call is directly inside an if/elseif condition. + * + * @param File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the empty token. + * + * @return bool True if inside an if/elseif condition, false otherwise. + */ + private function isInIfCondition( File $phpcsFile, $stackPtr ) { + $tokens = $phpcsFile->getTokens(); + + // Find the opening parenthesis that contains this empty() call. + for ( $i = $stackPtr - 1; $i >= 0; $i-- ) { + $code = $tokens[ $i ]['code']; + + // Skip whitespace and the "!" operator. + if ( $code === T_WHITESPACE || $code === T_BOOLEAN_NOT ) { + continue; + } + + // If we hit an open parenthesis, check if it belongs to if/elseif. + if ( $code === T_OPEN_PARENTHESIS ) { + $beforeParen = $phpcsFile->findPrevious( T_WHITESPACE, $i - 1, null, true ); + + if ( false !== $beforeParen ) { + $beforeCode = $tokens[ $beforeParen ]['code']; + + if ( $beforeCode === T_IF || $beforeCode === T_ELSEIF ) { + return true; + } + } + + return false; + } + + // If we hit something else, stop. + if ( $code !== T_OPEN_PARENTHESIS ) { + return false; + } + } + + return false; + } + + /** + * Find the function or method that contains the given token. + * + * @param File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token. + * + * @return int|false The position of the function token, or false if not found. + */ + private function findContainingFunction( File $phpcsFile, $stackPtr ) { + $tokens = $phpcsFile->getTokens(); + + for ( $i = $stackPtr - 1; $i >= 0; $i-- ) { + if ( $tokens[ $i ]['code'] === T_FUNCTION || $tokens[ $i ]['code'] === T_CLOSURE ) { + if ( isset( $tokens[ $i ]['scope_opener'], $tokens[ $i ]['scope_closer'] ) ) { + if ( $stackPtr > $tokens[ $i ]['scope_opener'] && $stackPtr < $tokens[ $i ]['scope_closer'] ) { + return $i; + } + } + } + } + + return false; + } + + /** + * Check if the variable was assigned earlier in the function. + * + * @param File $phpcsFile The file being scanned. + * @param int $functionToken The position of the function token. + * @param int $emptyPtr The position of the empty() call. + * @param string $variableName The variable name to check. + * + * @return bool True if the variable was assigned, false otherwise. + */ + private function wasVariableAssigned( File $phpcsFile, $functionToken, $emptyPtr, $variableName ) { + $tokens = $phpcsFile->getTokens(); + $scopeOpener = $tokens[ $functionToken ]['scope_opener']; + + // Search from the function start to the empty() call. + for ( $i = $scopeOpener + 1; $i < $emptyPtr; $i++ ) { + if ( $tokens[ $i ]['code'] !== T_VARIABLE ) { + continue; + } + + if ( $tokens[ $i ]['content'] !== $variableName ) { + continue; + } + + // Check if this variable is being assigned (has = after it). + $nextToken = $phpcsFile->findNext( T_WHITESPACE, $i + 1, null, true ); + + if ( false !== $nextToken && $tokens[ $nextToken ]['code'] === T_EQUAL ) { + return true; + } + } + + return false; + } +} diff --git a/phpcs.xml b/phpcs.xml index 2913bcaeb4..e3fdaa452c 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -283,6 +283,7 @@ + diff --git a/square/controllers/FrmSquareLiteActionsController.php b/square/controllers/FrmSquareLiteActionsController.php index b79b662fb8..f1f8e2b591 100644 --- a/square/controllers/FrmSquareLiteActionsController.php +++ b/square/controllers/FrmSquareLiteActionsController.php @@ -22,7 +22,7 @@ public static function maybe_show_card( $callback, $field = false ) { $form_id = is_object( $field ) ? $field->form_id : $field['form_id']; $actions = self::get_actions_before_submit( $form_id ); - if ( empty( $actions ) ) { + if ( ! $actions ) { return $callback; } @@ -59,7 +59,7 @@ public static function show_card( $field, $field_name, $atts ) { return; } - // Use the Pro function when there are no Stripe actions. + // Use the Pro function when there are no Square actions. // This is required for other gateways like Authorize.Net. if ( is_callable( 'FrmProCreditCardsController::show_in_form' ) ) { FrmProCreditCardsController::show_in_form( $field, $field_name, $atts ); @@ -111,7 +111,7 @@ public static function trigger_gateway( $action, $entry, $form ) { $amount = self::prepare_amount( $action->post_content['amount'], $atts ); // phpcs:ignore Universal.Operators.StrictComparisons - if ( empty( $amount ) || $amount == 000 ) { + if ( ! $amount || $amount == 000 ) { $response['error'] = __( 'Please specify an amount for the payment', 'formidable' ); return $response; } diff --git a/square/controllers/FrmSquareLiteAppController.php b/square/controllers/FrmSquareLiteAppController.php index 198799602e..b25c955487 100644 --- a/square/controllers/FrmSquareLiteAppController.php +++ b/square/controllers/FrmSquareLiteAppController.php @@ -80,7 +80,7 @@ public static function verify_buyer() { $actions = FrmSquareLiteActionsController::get_actions_before_submit( $form_id ); - if ( empty( $actions ) ) { + if ( ! $actions ) { wp_send_json_error( __( 'No Square actions found for this form', 'formidable' ) ); } diff --git a/stripe/controllers/FrmStrpLiteActionsController.php b/stripe/controllers/FrmStrpLiteActionsController.php index ce85171ef0..9cc14b5b23 100644 --- a/stripe/controllers/FrmStrpLiteActionsController.php +++ b/stripe/controllers/FrmStrpLiteActionsController.php @@ -30,7 +30,7 @@ public static function maybe_show_card( $callback, $field = false ) { $form_id = is_object( $field ) ? $field->form_id : $field['form_id']; $actions = self::get_actions_before_submit( $form_id ); - if ( empty( $actions ) ) { + if ( ! $actions ) { return $callback; } @@ -123,7 +123,7 @@ public static function trigger_gateway( $action, $entry, $form ) { $amount = self::prepare_amount( $action->post_content['amount'], $atts ); // phpcs:ignore Universal.Operators.StrictComparisons - if ( empty( $amount ) || $amount == 000 ) { + if ( ! $amount || $amount == 000 ) { $response['error'] = __( 'Please specify an amount for the payment', 'formidable' ); return $response; } diff --git a/stripe/controllers/FrmStrpLiteEventsController.php b/stripe/controllers/FrmStrpLiteEventsController.php index 8cb3001ce6..086947d7ad 100644 --- a/stripe/controllers/FrmStrpLiteEventsController.php +++ b/stripe/controllers/FrmStrpLiteEventsController.php @@ -171,7 +171,7 @@ private function reset_customer() { global $wpdb; $customer_id = $this->invoice->id; - if ( empty( $customer_id ) ) { + if ( ! $customer_id ) { return; } $wpdb->query( diff --git a/stripe/controllers/FrmTransLiteActionsController.php b/stripe/controllers/FrmTransLiteActionsController.php index 7663904684..c2d8b392a6 100755 --- a/stripe/controllers/FrmTransLiteActionsController.php +++ b/stripe/controllers/FrmTransLiteActionsController.php @@ -159,7 +159,7 @@ public static function replace_success_message() { global $frm_vars; $message = $frm_vars['frm_trans']['error'] ?? ''; - if ( empty( $message ) ) { + if ( ! $message ) { $message = __( 'There was an error processing your payment.', 'formidable' ); } @@ -285,7 +285,7 @@ public static function trigger_actions_after_payment( $payment, $atts = array() public static function prepare_description( &$action, $atts ) { $description = $action->post_content['description']; - if ( ! empty( $description ) ) { + if ( $description ) { $atts['value'] = $description; $description = FrmTransLiteAppHelper::process_shortcodes( $atts ); $action->post_content['description'] = $description; @@ -502,7 +502,7 @@ public static function fill_entry_from_previous( $values, $field ) { $previous_entry = $frm_vars['frm_trans']['pay_entry'] ?? false; // phpcs:ignore Universal.Operators.StrictComparisons - if ( empty( $previous_entry ) || $previous_entry->form_id != $field->form_id ) { + if ( ! $previous_entry || $previous_entry->form_id != $field->form_id ) { return $values; } diff --git a/stripe/helpers/FrmStrpLiteConnectApiAdapter.php b/stripe/helpers/FrmStrpLiteConnectApiAdapter.php index 9b83c20bee..09f9c72e57 100644 --- a/stripe/helpers/FrmStrpLiteConnectApiAdapter.php +++ b/stripe/helpers/FrmStrpLiteConnectApiAdapter.php @@ -113,7 +113,7 @@ public static function get_customer( $options = array() ) { delete_user_meta( $user_id, $meta_name ); } - if ( ! empty( $customer_id_error_message ) ) { + if ( $customer_id_error_message ) { return $customer_id_error_message; } diff --git a/stripe/helpers/FrmStrpLiteLinkRedirectHelper.php b/stripe/helpers/FrmStrpLiteLinkRedirectHelper.php index 0305c5243d..7a1330edc4 100644 --- a/stripe/helpers/FrmStrpLiteLinkRedirectHelper.php +++ b/stripe/helpers/FrmStrpLiteLinkRedirectHelper.php @@ -57,7 +57,7 @@ public function handle_error( $error_code, $charge_id = '' ) { $referer = FrmStrpLiteAuth::get_referer_url( $this->entry_id ); } - if ( empty( $referer ) ) { + if ( ! $referer ) { $referer = FrmAppHelper::get_server_value( 'HTTP_REFERER' ); } diff --git a/stripe/models/FrmStrpLiteAuth.php b/stripe/models/FrmStrpLiteAuth.php index 2611259674..ded4caaed1 100644 --- a/stripe/models/FrmStrpLiteAuth.php +++ b/stripe/models/FrmStrpLiteAuth.php @@ -224,7 +224,7 @@ public static function add_hidden_token_field( $form ) { $intents = self::get_payment_intents( 'frmintent' . $form->id ); - if ( ! empty( $intents ) ) { + if ( $intents ) { self::update_intent_pricing( $form->id, $intents ); } else { $intents = self::maybe_create_intents( $form->id ); @@ -302,7 +302,7 @@ public static function update_intent_ajax() { $form_id = absint( $form['form_id'] ); $intents = $form[ 'frmintent' . $form_id ] ?? array(); - if ( empty( $intents ) ) { + if ( ! $intents ) { wp_die(); } @@ -340,7 +340,7 @@ private static function update_intent_pricing( $form_id, &$intents ) { $actions = FrmStrpLiteActionsController::get_actions_before_submit( $form_id ); - if ( empty( $actions ) || empty( $intents ) ) { + if ( ! $actions || empty( $intents ) ) { return; } @@ -760,7 +760,7 @@ private static function get_redirect_url( $atts ) { $success_url = reset( $actions )->post_content['success_url']; } - if ( empty( $success_url ) ) { + if ( ! $success_url ) { $success_url = $atts['form']->options['success_url']; } diff --git a/stripe/models/FrmTransLiteDb.php b/stripe/models/FrmTransLiteDb.php index 7f467aa055..5e6cabb6c7 100755 --- a/stripe/models/FrmTransLiteDb.php +++ b/stripe/models/FrmTransLiteDb.php @@ -335,7 +335,7 @@ private function migrate_to_4() { global $wpdb; $result = $wpdb->get_results( $wpdb->prepare( 'SHOW COLUMNS FROM ' . $wpdb->prefix . 'frm_payments LIKE %s', 'completed' ) ); - if ( empty( $result ) ) { + if ( ! $result ) { return; } diff --git a/tests/phpunit/applications/test_FrmApplicationsController.php b/tests/phpunit/applications/test_FrmApplicationsController.php index bdf92e1248..d8bfb9ec76 100644 --- a/tests/phpunit/applications/test_FrmApplicationsController.php +++ b/tests/phpunit/applications/test_FrmApplicationsController.php @@ -24,7 +24,7 @@ public function test_get_prepared_template_data() { $data = $this->get_prepared_template_data(); $this->assertIsArray( $data ); - if ( empty( $data ) ) { + if ( ! $data ) { $this->markTestSkipped( 'We cannot currently reach the API, so skip the test.' ); } diff --git a/tests/phpunit/base/FrmUnitTest.php b/tests/phpunit/base/FrmUnitTest.php index acba30842d..dfbb5303ee 100644 --- a/tests/phpunit/base/FrmUnitTest.php +++ b/tests/phpunit/base/FrmUnitTest.php @@ -332,7 +332,7 @@ public function get_user_by_role( $role ) { ) ); - if ( empty( $users ) ) { + if ( ! $users ) { $this->fail( 'No users with this role currently exist.' ); return null; } diff --git a/tests/phpunit/fields/test_FrmFieldValidate.php b/tests/phpunit/fields/test_FrmFieldValidate.php index bb04deb057..673570e0eb 100644 --- a/tests/phpunit/fields/test_FrmFieldValidate.php +++ b/tests/phpunit/fields/test_FrmFieldValidate.php @@ -47,7 +47,7 @@ public function test_not_required_fields() { $errors = FrmEntryValidate::validate( $_POST ); $error_fields = array(); - if ( ! empty( $errors ) ) { + if ( $errors ) { $error_field_ids = array_keys( $errors ); foreach ( $error_field_ids as $error_field ) { @@ -139,7 +139,7 @@ public function test_empty_required_fields() { $this->assertNotEmpty( $errors ); $error_fields = array(); - if ( ! empty( $errors ) ) { + if ( $errors ) { foreach ( $fields as $field ) { if ( ! isset( $errors[ 'field' . $field->id ] ) ) { $error_fields[] = $field->type; @@ -157,7 +157,7 @@ public function test_filled_required_fields() { $error_fields = array(); - if ( ! empty( $errors ) ) { + if ( $errors ) { $error_field_ids = array_keys( $errors ); foreach ( $error_field_ids as $error_field ) {