From f74f767413c4eacf6ec7e1b6ee7fbebce8ce2647 Mon Sep 17 00:00:00 2001 From: hbhalodia Date: Wed, 8 Feb 2023 14:21:04 +0530 Subject: [PATCH 01/10] Fix: phpcs errors 1. Blank line after function. 2. Ignore WordPress.NamingConventions.ValidHookName.UseUnderscores because of backward compatibility --- src/Container.php | 2 +- src/Interfaces/Container.php | 1 + src/Modules/Block.php | 2 +- src/Modules/Login.php | 4 ++-- src/Modules/OneTapLogin.php | 4 ++-- src/Modules/Shortcode.php | 1 - src/Plugin.php | 2 +- src/Utils/Authenticator.php | 6 +++--- src/Utils/GoogleClient.php | 9 ++++----- src/Utils/TokenVerifier.php | 4 ++-- 10 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/Container.php b/src/Container.php index e8d92ac6..53487cd5 100644 --- a/src/Container.php +++ b/src/Container.php @@ -196,6 +196,6 @@ public function define_services(): void { * * @since 1.0.0 */ - do_action( 'rtcamp.google_login_services', $this ); + do_action( 'rtcamp.google_login_services', $this ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores -- Ignore as currently cannot change because of backward compatibility. } } diff --git a/src/Interfaces/Container.php b/src/Interfaces/Container.php index b83e9613..a5ff90ce 100644 --- a/src/Interfaces/Container.php +++ b/src/Interfaces/Container.php @@ -16,6 +16,7 @@ * @package WpGuruDev\OrderExport\Interfaces */ interface Container { + /** * Define services in container. * diff --git a/src/Modules/Block.php b/src/Modules/Block.php index abd73f3d..2fa3232d 100644 --- a/src/Modules/Block.php +++ b/src/Modules/Block.php @@ -155,7 +155,7 @@ public function render_login_button( $attributes ): string { * @since 1.2.3 */ $force_display = $attributes['forceDisplay'] ?? false; - if ( $force_display || ! is_user_logged_in() || apply_filters( 'rtcamp.google_login_button_display', false ) ) { + if ( $force_display || ! is_user_logged_in() || apply_filters( 'rtcamp.google_login_button_display', false ) ) { // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores -- Ignore as currently cannot change because of backward compatibility. $markup = $this->markup( [ 'login_url' => $this->client->authorization_url(), diff --git a/src/Modules/Login.php b/src/Modules/Login.php index 5e1a78fe..9fbd3263 100644 --- a/src/Modules/Login.php +++ b/src/Modules/Login.php @@ -151,7 +151,7 @@ public function authenticate( $user = null ) { * * @param WP_User $user WP User object. */ - do_action( 'rtcamp.google_user_authenticated', $user ); + do_action( 'rtcamp.google_user_authenticated', $user ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores -- Ignore as currently cannot change because of backward compatibility. return $user; } @@ -205,7 +205,7 @@ public function state_redirect( array $state ): array { * * @param string $admin_url Admin URL address. */ - $state['redirect_to'] = $redirect_to ?? apply_filters( 'rtcamp.google_default_redirect', admin_url() ); + $state['redirect_to'] = $redirect_to ?? apply_filters( 'rtcamp.google_default_redirect', admin_url() ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores -- Ignore as currently cannot change because of backward compatibility. return $state; } diff --git a/src/Modules/OneTapLogin.php b/src/Modules/OneTapLogin.php index 77c75f16..b8ddfd76 100644 --- a/src/Modules/OneTapLogin.php +++ b/src/Modules/OneTapLogin.php @@ -176,9 +176,9 @@ public function validate_token(): void { * * @since 1.0.16 */ - do_action( 'rtcamp.id_token_verified' ); + do_action( 'rtcamp.id_token_verified' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores -- Ignore as currently cannot change because of backward compatibility. - $redirect_to = apply_filters( 'rtcamp.google_default_redirect', admin_url() ); + $redirect_to = apply_filters( 'rtcamp.google_default_redirect', admin_url() ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores -- Ignore as currently cannot change because of backward compatibility. $state = Helper::filter_input( INPUT_POST, 'state', FILTER_SANITIZE_STRING ); $decoded_state = $state ? (array) ( json_decode( base64_decode( $state ) ) ) : null; diff --git a/src/Modules/Shortcode.php b/src/Modules/Shortcode.php index 0d9c87a5..05f86bfc 100644 --- a/src/Modules/Shortcode.php +++ b/src/Modules/Shortcode.php @@ -134,7 +134,6 @@ public function scan_shortcode( string $output, string $tag, $attrs ): string { return $output; } - /** * Filter redirect URL as per shortcode param. * diff --git a/src/Plugin.php b/src/Plugin.php index 934a3112..b118f5d2 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -104,7 +104,7 @@ public function run(): void { * * @since 1.0.0 */ - $this->active_modules = apply_filters( 'rtcamp.google_login_modules', $this->active_modules ); + $this->active_modules = apply_filters( 'rtcamp.google_login_modules', $this->active_modules ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores -- Ignore as currently cannot change because of backward compatibility. $this->container()->define_services(); $this->activate_modules(); diff --git a/src/Utils/Authenticator.php b/src/Utils/Authenticator.php index 78739869..ee748d3e 100644 --- a/src/Utils/Authenticator.php +++ b/src/Utils/Authenticator.php @@ -69,7 +69,7 @@ public function authenticate( stdClass $user ): WP_User { * @param WP_User $user_wp WP User data object. * @param stdClass $user User data object returned by Google. */ - do_action( 'rtcamp.google_user_logged_in', $user_wp, $user ); + do_action( 'rtcamp.google_user_logged_in', $user_wp, $user ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores -- Ignore as currently cannot change because of backward compatibility. return $user_wp; } @@ -80,7 +80,7 @@ public function authenticate( stdClass $user ): WP_User { * @param stdClass $user User object from google. * @since 1.0.0 */ - return apply_filters( 'rtcamp.google_register_user', $this->maybe_create_username( $user ) ); + return apply_filters( 'rtcamp.google_register_user', $this->maybe_create_username( $user ) ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores -- Ignore as currently cannot change because of backward compatibility. } /** @@ -115,7 +115,7 @@ public function register( stdClass $user ): ?WP_User { /** * Fires once the user has been registered successfully. */ - do_action( 'rtcamp.google_user_created', $uid, $user ); + do_action( 'rtcamp.google_user_created', $uid, $user ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores -- Ignore as currently cannot change because of backward compatibility. return get_user_by( 'id', $uid ); } diff --git a/src/Utils/GoogleClient.php b/src/Utils/GoogleClient.php index ea78f887..f2f0eb55 100644 --- a/src/Utils/GoogleClient.php +++ b/src/Utils/GoogleClient.php @@ -123,7 +123,7 @@ public function set_access_token( string $code ): self { * @return string */ public function gt_redirect_url(): string { - return apply_filters( 'rtcamp.google_redirect_url', $this->redirect_uri ); + return apply_filters( 'rtcamp.google_redirect_url', $this->redirect_uri ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores -- Ignore as currently cannot change because of backward compatibility. } /** @@ -152,7 +152,7 @@ public function authorization_url(): string { * * @param array $scope List of scopes. */ - $scope = apply_filters( 'rtcamp.google_scope', $scope ); + $scope = apply_filters( 'rtcamp.google_scope', $scope ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores -- Ignore as currently cannot change because of backward compatibility. $client_args = [ 'client_id' => $this->client_id, @@ -170,7 +170,7 @@ public function authorization_url(): string { * * @param array $client_args List of query arguments to send to Google OAuth. */ - $client_args = apply_filters( 'rtcamp.google_client_args', $client_args ); + $client_args = apply_filters( 'rtcamp.google_client_args', $client_args ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores -- Ignore as currently cannot change because of backward compatibility. return self::AUTHORIZE_URL . '?' . http_build_query( $client_args ); } @@ -245,10 +245,9 @@ public function user(): \stdClass { */ public function state(): string { $state_data['nonce'] = wp_create_nonce( 'login_with_google' ); - $state_data = apply_filters( 'rtcamp.google_login_state', $state_data ); + $state_data = apply_filters( 'rtcamp.google_login_state', $state_data ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores -- Ignore as currently cannot change because of backward compatibility. $state_data['provider'] = 'google'; return base64_encode( wp_json_encode( $state_data ) ); } - } diff --git a/src/Utils/TokenVerifier.php b/src/Utils/TokenVerifier.php index b9fdddc2..814fd6bb 100644 --- a/src/Utils/TokenVerifier.php +++ b/src/Utils/TokenVerifier.php @@ -78,7 +78,7 @@ public static function get_supported_algorithm( string $algo = '' ) { $find_algo = array_key_exists( $algo, self::SUPPORTED_ALGORITHMS ); if ( ! $find_algo ) { - return apply_filters( 'rtcamp.default_algorithm', OPENSSL_ALGO_SHA256, $algo ); + return apply_filters( 'rtcamp.default_algorithm', OPENSSL_ALGO_SHA256, $algo ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores -- Ignore as currently cannot change because of backward compatibility. } return self::SUPPORTED_ALGORITHMS[ $algo ]; @@ -103,7 +103,7 @@ public function verify_token( string $token ): bool { return true; } catch ( Exception $e ) { - do_action( 'rtcamp.login_with_google_exception', $e ); + do_action( 'rtcamp.login_with_google_exception', $e ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores -- Ignore as currently cannot change because of backward compatibility. throw $e; } From 76e35777052ca73cbae40a6ee519611e924943d1 Mon Sep 17 00:00:00 2001 From: hbhalodia Date: Wed, 8 Feb 2023 14:23:14 +0530 Subject: [PATCH 02/10] Fix: phpcs error for equal sign alignment --- templates/google-login-button.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/google-login-button.php b/templates/google-login-button.php index c010785f..93290387 100644 --- a/templates/google-login-button.php +++ b/templates/google-login-button.php @@ -20,7 +20,7 @@ if ( is_user_logged_in() ) { $button_text = __( 'Log out', 'login-with-google' ); - $button_url = wp_logout_url( get_permalink() ); + $button_url = wp_logout_url( get_permalink() ); } ?>