From 5b153eb9db5a56622f23e151bc02f434e693e624 Mon Sep 17 00:00:00 2001 From: sancodes Date: Wed, 13 Apr 2022 11:45:49 -0700 Subject: [PATCH 1/4] add function and replace logic --- includes/Modules/AdSense.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/includes/Modules/AdSense.php b/includes/Modules/AdSense.php index ffc3dea935a..712bb7eac3a 100644 --- a/includes/Modules/AdSense.php +++ b/includes/Modules/AdSense.php @@ -403,7 +403,8 @@ function( Google_Service_Adsense_Alert $alert ) { protected function parse_data_response( Data_Request $data, $response ) { switch ( "{$data->method}:{$data->datapoint}" ) { case 'GET:accounts': - return array_map( array( self::class, 'filter_account_with_ids' ), $response->getAccounts() ); + $accounts = $response->getAccounts(); + return array_filter($accounts,'filter_account_with_state_closed'); case 'GET:adunits': return array_map( array( self::class, 'filter_adunit_with_ids' ), $response->getAdUnits() ); case 'GET:alerts': @@ -421,6 +422,20 @@ protected function parse_data_response( Data_Request $data, $response ) { return parent::parse_data_response( $data, $response ); } + /** + * Checks for the state of an Account, whether close or not. + * + * @since 1.71.0 + * + * @param account array + * + * @return boolean + */ + public static function is_account_not_closed($account){ + + return $account.state == 'CLOSED'; + } + /** * Gets the service URL for the current account or signup if none. * From 77b3007ec9bf1bbd97484b9fac67b74f7359c31f Mon Sep 17 00:00:00 2001 From: sancodes Date: Thu, 14 Apr 2022 12:31:07 -0700 Subject: [PATCH 2/4] fix styling and add suggestions --- includes/Modules/AdSense.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/includes/Modules/AdSense.php b/includes/Modules/AdSense.php index 712bb7eac3a..3a4274da574 100644 --- a/includes/Modules/AdSense.php +++ b/includes/Modules/AdSense.php @@ -404,7 +404,7 @@ protected function parse_data_response( Data_Request $data, $response ) { switch ( "{$data->method}:{$data->datapoint}" ) { case 'GET:accounts': $accounts = $response->getAccounts(); - return array_filter($accounts,'filter_account_with_state_closed'); + return array_filter( array_map( array( $accounts, 'filter_account_with_state_closed' ) ) ); case 'GET:adunits': return array_map( array( self::class, 'filter_adunit_with_ids' ), $response->getAdUnits() ); case 'GET:alerts': @@ -425,15 +425,19 @@ protected function parse_data_response( Data_Request $data, $response ) { /** * Checks for the state of an Account, whether close or not. * - * @since 1.71.0 + * @since n.e.x.t * - * @param account array + * @param object $account The AdSense account object. * - * @return boolean + * @return bool */ public static function is_account_not_closed($account){ - return $account.state == 'CLOSED'; + if( $account->getState() === 'CLOSED' ) { + return true; + } + + return false; } /** From 6da1dc7f596d6199cab1d794cf3a7e6adeb3d4bf Mon Sep 17 00:00:00 2001 From: sancodes Date: Thu, 14 Apr 2022 13:42:40 -0700 Subject: [PATCH 3/4] fix logics --- includes/Modules/AdSense.php | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/includes/Modules/AdSense.php b/includes/Modules/AdSense.php index 3a4274da574..fd0a4cd1352 100644 --- a/includes/Modules/AdSense.php +++ b/includes/Modules/AdSense.php @@ -403,8 +403,8 @@ function( Google_Service_Adsense_Alert $alert ) { protected function parse_data_response( Data_Request $data, $response ) { switch ( "{$data->method}:{$data->datapoint}" ) { case 'GET:accounts': - $accounts = $response->getAccounts(); - return array_filter( array_map( array( $accounts, 'filter_account_with_state_closed' ) ) ); + $accounts = array_filter( $response->getAccounts(), array( self::class, 'is_account_not_closed' ) ); + return array_map( array( self::class, 'filter_account_with_ids' ), $accounts ); case 'GET:adunits': return array_map( array( self::class, 'filter_adunit_with_ids' ), $response->getAdUnits() ); case 'GET:alerts': @@ -429,15 +429,11 @@ protected function parse_data_response( Data_Request $data, $response ) { * * @param object $account The AdSense account object. * - * @return bool + * @return bool Whether the account is not closed. */ public static function is_account_not_closed($account){ - if( $account->getState() === 'CLOSED' ) { - return true; - } - - return false; + return 'CLOSED' !== $account->getState(); } /** From 1b46cfceffd57c76bc3e58ba6ded6956f7f2c3b1 Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Fri, 15 Apr 2022 10:28:07 -0700 Subject: [PATCH 4/4] Fix linting errors and formatting. --- includes/Modules/AdSense.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/includes/Modules/AdSense.php b/includes/Modules/AdSense.php index fd0a4cd1352..ea380921bcf 100644 --- a/includes/Modules/AdSense.php +++ b/includes/Modules/AdSense.php @@ -423,16 +423,14 @@ protected function parse_data_response( Data_Request $data, $response ) { } /** - * Checks for the state of an Account, whether close or not. - * + * Checks for the state of an Account, whether closed or not. + * * @since n.e.x.t - * - * @param object $account The AdSense account object. - * + * + * @param Google_Model $account Account model. * @return bool Whether the account is not closed. */ - public static function is_account_not_closed($account){ - + public static function is_account_not_closed( $account ) { return 'CLOSED' !== $account->getState(); }