Skip to content

Commit

Permalink
Update whitespace and errors
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewheberle committed Nov 9, 2023
1 parent a473c92 commit 968be7a
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions includes/class-ahjwtauthsignin.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ public function ahjwtauth_admin_notice() {
* Schedules the refresh of the JWKS via WP Cron
*
* @return void
*/
*/
public function ahjwtauth_schedule_refresh_jwks() {
if (!wp_next_scheduled('ahjwtauth_refresh_jwks')) {
wp_schedule_event(time(), 'daily', 'ahjwtauth_refresh_jwks');
if (!wp_next_scheduled( 'ahjwtauth_refresh_jwks' )) {

Check failure on line 135 in includes/class-ahjwtauthsignin.php

View workflow job for this annotation

GitHub Actions / WPCS

No space after opening parenthesis is prohibited

Check failure on line 135 in includes/class-ahjwtauthsignin.php

View workflow job for this annotation

GitHub Actions / WPCS

Expected 1 space before "!"; 0 found

Check failure on line 135 in includes/class-ahjwtauthsignin.php

View workflow job for this annotation

GitHub Actions / WPCS

Expected 1 space after "!"; 0 found

Check failure on line 135 in includes/class-ahjwtauthsignin.php

View workflow job for this annotation

GitHub Actions / WPCS

No space before closing parenthesis is prohibited
wp_schedule_event( time(), 'daily', 'ahjwtauth_refresh_jwks' );
}
}

Expand All @@ -149,22 +149,21 @@ private function ahjwtauth_refresh_jwks() {
if ( '' === $jwks_url ) {
return true;
}

// retrieve json from JWKS URL with caching.
$keys = get_transient( 'ahjwtauth_jwks' );

// transient existed

Check failure on line 156 in includes/class-ahjwtauthsignin.php

View workflow job for this annotation

GitHub Actions / WPCS

Inline comments must end in full-stops, exclamation marks, or question marks
if ( false !== $keys ) {
return $keys;
}

// if transient did not exist, attempt to get url.
$jwks_url = get_option( 'ahjwtauth-jwks-url' );
$response = wp_remote_get( $jwks_url );
if ( is_wp_error( $response ) ) {
$msg = 'error retrieving the JWKS URL';
$this->error = __( 'AH JWT Auth: ' . $msg, 'ah-jwt-auth' );
error_log( 'AH JWT Auth: ERROR: ' . $msg );
$this->error = __( 'AH JWT Auth: error retrieving the JWKS URL', 'ah-jwt-auth' );
error_log( 'AH JWT Auth: ERROR: error retrieving the JWKS URL' );
return false;
}

Expand All @@ -173,18 +172,16 @@ private function ahjwtauth_refresh_jwks() {

// check that response was not empty.
if ( '' === $json ) {
$msg = 'could not retrieve the specified JWKS URL';
$this->error = __( 'AH JWT Auth ' . $msg, 'ah-jwt-auth' );
error_log( 'AH JWT Auth: ERROR: ' . $msg );
$this->error = __( 'AH JWT Auth could not retrieve the specified JWKS URL', 'ah-jwt-auth' );
error_log( 'AH JWT Auth: ERROR: could not retrieve the specified JWKS URL' );
return false;
}

// try to decode json.
$jwks = @json_decode( $json, true );
if ( null === $jwks ) {
$msg = 'cannot decode the JSON retrieved from the JWKS URL';
$this->error = __( 'AH JWT Auth ' . $msg, 'ah-jwt-auth' );
error_log( 'AH JWT Auth: ERROR: ' . $msg );
$this->error = __( 'AH JWT Auth cannot decode the JSON retrieved from the JWKS URL', 'ah-jwt-auth' );
error_log( 'AH JWT Auth: ERROR: cannot decode the JSON retrieved from the JWKS URL' );
return false;
}

Expand All @@ -197,7 +194,7 @@ private function ahjwtauth_refresh_jwks() {
error_log( $json );
return false;
}

// cache JWKS for future.
set_transient( 'ahjwtauth_jwks', $keys, WEEK_IN_SECONDS );

Expand Down

0 comments on commit 968be7a

Please sign in to comment.