From fb010f37fe040ad527734472f24062db04bf8f94 Mon Sep 17 00:00:00 2001 From: Erik Golinelli Date: Fri, 26 Jan 2024 19:43:23 +0100 Subject: [PATCH] linting / wpcs --- admin/CF7_AntiSpam_Admin_Customizations.php | 5 +-- admin/CF7_AntiSpam_Admin_Display.php | 2 +- composer.lock | 47 +++++++++++---------- core/CF7_AntiSpam_Filters.php | 12 +++--- core/CF7_AntiSpam_Flamingo.php | 4 +- core/CF7_AntiSpam_Frontend.php | 4 +- core/CF7_Antispam_Service.php | 10 ++--- 7 files changed, 43 insertions(+), 41 deletions(-) diff --git a/admin/CF7_AntiSpam_Admin_Customizations.php b/admin/CF7_AntiSpam_Admin_Customizations.php index 9c2f25d..743ad3c 100644 --- a/admin/CF7_AntiSpam_Admin_Customizations.php +++ b/admin/CF7_AntiSpam_Admin_Customizations.php @@ -1050,9 +1050,9 @@ private function cf7a_clean_recursive( $json_data ) { public function cf7a_sanitize_options( $input ) { /* get the import options */ $new_input = $this->options; - $import_data = isset( $_POST['to-import'] ) ? $_POST['to-import'] : false; + $import_data = isset( $_POST['to-import'] ) ? sanitize_text_field( $_POST['to-import'] ) : false; if ( ! empty( $import_data ) ) { - $json_data = json_decode( wp_unslash( $_POST['to-import'] ) ); + $json_data = json_decode( wp_unslash( $import_data ) ); $input = $this->cf7a_clean_recursive( $json_data ); // monkey pathing arrays that needs to be imploded $input['bad_ip_list'] = implode( ',', $input['bad_ip_list'] ); @@ -1068,7 +1068,6 @@ public function cf7a_sanitize_options( $input ) { $input['cf7a_enable'] = 1; $input['cf7a_version'] = CF7ANTISPAM_VERSION; } - error_log( print_r( $input, true ) ); $new_input['cf7a_enabled'] = isset( $input['cf7a_enabled'] ) ? 1 : 0; diff --git a/admin/CF7_AntiSpam_Admin_Display.php b/admin/CF7_AntiSpam_Admin_Display.php index f8a332e..ea051be 100644 --- a/admin/CF7_AntiSpam_Admin_Display.php +++ b/admin/CF7_AntiSpam_Admin_Display.php @@ -196,7 +196,7 @@ private function cf7a_export_options() { ?>

-
+ =5.4.0" }, "require-dev": { - "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.0" + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.3.4" }, "bin": [ - "bin/phpcs", - "bin/phpcbf" + "bin/phpcbf", + "bin/phpcs" ], "type": "library", "extra": { @@ -2839,7 +2839,7 @@ "type": "open_collective" } ], - "time": "2023-12-08T12:32:31+00:00" + "time": "2024-01-11T20:47:48+00:00" }, { "name": "symfony/console", @@ -4446,7 +4446,10 @@ "stability-flags": [], "prefer-stable": true, "prefer-lowest": false, - "platform": [], + "platform": { + "ext-json": "*", + "ext-openssl": "*" + }, "platform-dev": { "php": ">=7.4", "ext-dom": "*", diff --git a/core/CF7_AntiSpam_Filters.php b/core/CF7_AntiSpam_Filters.php index 84ba6fd..648889d 100644 --- a/core/CF7_AntiSpam_Filters.php +++ b/core/CF7_AntiSpam_Filters.php @@ -244,15 +244,15 @@ public function cf7a_cron_unban() { public function cf7a_check_length_exclusive( $el, $n ) { if ( strlen( $el ) >= 5 ) { $l = explode( '-', $el ); - if ( $n == 0 ) { + if ( 0 == $n ) { return strtolower( $l[0] ); - } elseif ( $n == 1 ) { + } elseif ( 1 == $n ) { return strtoupper( $l[1] ); } } elseif ( strlen( $el ) === 2 && ctype_alpha( $el ) ) { - if ( $n == 0 && ctype_lower( $el ) ) { + if ( 0 == $n && ctype_lower( $el ) ) { return $el; - } elseif ( $n == 1 && ctype_upper( $el ) ) { + } elseif ( 1 == $n && ctype_upper( $el ) ) { return $el; } } @@ -270,9 +270,9 @@ public function cf7a_check_length_exclusive( $el, $n ) { public function cf7a_get_languages_or_locales( $option, $key ) { $languages = array(); foreach ( $option as $item ) { - if ( $key == 'languages' ) { + if ( 'languages' === $key ) { $l = $this->cf7a_check_length_exclusive( $item, 0 ); - } elseif ( $key == 'locales' ) { + } elseif ( 'locales' === $key ) { $l = $this->cf7a_check_length_exclusive( $item, 1 ); } if ( ! empty( $l ) ) { diff --git a/core/CF7_AntiSpam_Flamingo.php b/core/CF7_AntiSpam_Flamingo.php index 1d80bd0..7f62153 100644 --- a/core/CF7_AntiSpam_Flamingo.php +++ b/core/CF7_AntiSpam_Flamingo.php @@ -241,9 +241,9 @@ public function cf7a_resend_mail( $mail_id ) { $recipient = $form_props['mail']['recipient']; if ( $form_props['mail']['recipient'] || ! empty( $flamingo_data->meta['recipient'] ) ) { if ( ! filter_var( $recipient, FILTER_VALIDATE_EMAIL ) || ! empty( $recipient ) ) { - if ( $recipient === '[_site_admin_email]' ) { + if ( '[_site_admin_email]' === $recipient ) { $recipient = $flamingo_data->meta['site_admin_email']; - } elseif ( $recipient === '[_post_author]' ) { + } elseif ( '[_post_author]' === $recipient ) { $recipient = get_option( 'post_author_email' ); // check this, not sure 🤔 } else { $recipient = get_option( 'admin_email' ); diff --git a/core/CF7_AntiSpam_Frontend.php b/core/CF7_AntiSpam_Frontend.php index 44751ea..7f64a4f 100644 --- a/core/CF7_AntiSpam_Frontend.php +++ b/core/CF7_AntiSpam_Frontend.php @@ -277,8 +277,8 @@ function generateHash( $length = 12 ) { for ( $i = 0; $i < $length; $i++ ) { // TODO: after upgrade to PHP>7.x, use random_int() - $randIndex = rand( 0, strlen( $characters ) - 1 ); - $hash .= $characters[ $randIndex ]; + $rand_index = wp_rand( 0, strlen( $characters ) - 1 ); + $hash .= $characters[ $rand_index ]; } return $hash; diff --git a/core/CF7_Antispam_Service.php b/core/CF7_Antispam_Service.php index 1acf4f8..5ad5c76 100644 --- a/core/CF7_Antispam_Service.php +++ b/core/CF7_Antispam_Service.php @@ -202,9 +202,6 @@ public function load( $action = '' ) { /** * The `display` function is used to display information about the Antispam plugin and provide options for * setup integration. - * - * @param string The "action" parameter is used to determine the specific action to be performed in the - * "display" function. It is a string that can have two possible values: */ public function display( $action = '' ) { echo sprintf( @@ -252,9 +249,12 @@ public function display( $action = '' ) { // Display the form echo '
'; echo ''; - printf( '', $checked ? __( 'Disable', 'cf7-antispam' ) : __( 'Enable', 'cf7-antispam' ) ); + printf( + '', + $checked ? esc_html__( 'Disable', 'cf7-antispam' ) : esc_html__( 'Enable', 'cf7-antispam' ) + ); if ( $checked ) { - echo 'Settings Page'; + printf( 'Settings Page', esc_url_raw( admin_url( 'admin.php?page=cf7-antispam' ) ) ); } echo ''; echo '
';