From 585aecaee9de508d063dc9947eccae631c2a60f4 Mon Sep 17 00:00:00 2001 From: BrianHenryIE Date: Mon, 18 Nov 2024 19:29:47 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=20PHPCBF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- includes/Event.php | 2 - includes/EventQueue/EventQueue.php | 7 +- includes/EventQueue/Queryable.php | 5 +- includes/EventQueue/Queues/BatchQueue.php | 22 +++--- .../EventQueue/Queues/BatchQueueInterface.php | 9 +-- includes/Helpers/SiteHealth.php | 3 +- includes/Listeners/Content.php | 8 +- includes/Listeners/Listener.php | 1 - includes/Listeners/SiteHealth.php | 4 +- includes/Listeners/Theme.php | 16 +++- includes/Listeners/WonderCart.php | 6 +- includes/Listeners/Yoast.php | 76 +++++++++---------- includes/Logger.php | 2 +- includes/SiteClassification/PrimaryType.php | 2 +- includes/SiteClassification/SecondaryType.php | 2 +- .../SiteClassification/SiteClassification.php | 1 - includes/SiteClassification/Types.php | 2 - 17 files changed, 85 insertions(+), 83 deletions(-) diff --git a/includes/Event.php b/includes/Event.php index c435b8a..082f492 100644 --- a/includes/Event.php +++ b/includes/Event.php @@ -90,7 +90,5 @@ public function __construct( $category = 'Admin', $key = '', $data = array() ) { 'role' => ( ! empty( $user->roles[0] ) ) ? $user->roles[0] : '', 'locale' => get_user_locale(), ); - } - } diff --git a/includes/EventQueue/EventQueue.php b/includes/EventQueue/EventQueue.php index 05ef3f4..7a629c9 100644 --- a/includes/EventQueue/EventQueue.php +++ b/includes/EventQueue/EventQueue.php @@ -36,16 +36,16 @@ public static function getInstance() { /** * Constructor * - * @param Container $container + * @param Container $container */ private function __construct() { global $wpdb; $container = new Container( - [ + array( 'table' => "{$wpdb->prefix}nfd_data_event_queue", - ] + ) ); $container->set( @@ -86,5 +86,4 @@ public function container() { public function queue() { return $this->container->get( 'queue' ); } - } diff --git a/includes/EventQueue/Queryable.php b/includes/EventQueue/Queryable.php index 573cb3e..9d8a8b8 100644 --- a/includes/EventQueue/Queryable.php +++ b/includes/EventQueue/Queryable.php @@ -26,8 +26,8 @@ protected function table() { * Bulk inserts records into a table using WPDB. All rows must contain the same keys. * Returns number of affected (inserted) rows. * - * @param string $table - * @param non-empty-array $rows + * @param string $table + * @param non-empty-array $rows * * @return bool|int */ @@ -63,5 +63,4 @@ protected function bulkInsert( string $table, array $rows ) { // Run the query. Returns number of affected rows. return $wpdb->query( $wpdb->prepare( $sql, $data ) ); } - } diff --git a/includes/EventQueue/Queues/BatchQueue.php b/includes/EventQueue/Queues/BatchQueue.php index 2e2b45b..f27d690 100644 --- a/includes/EventQueue/Queues/BatchQueue.php +++ b/includes/EventQueue/Queues/BatchQueue.php @@ -20,7 +20,7 @@ class BatchQueue implements BatchQueueInterface { /** * Constructor * - * @param Container $container + * @param Container $container */ public function __construct( Container $container ) { $this->container = $container; @@ -29,7 +29,7 @@ public function __construct( Container $container ) { /** * Push events onto the queue * - * @param non-empty-array $events + * @param non-empty-array $events * * @return bool */ @@ -37,13 +37,13 @@ public function push( array $events ) { $time = current_time( 'mysql' ); - $inserts = []; + $inserts = array(); foreach ( $events as $event ) { - $inserts[] = [ + $inserts[] = array( 'event' => serialize( $event ), 'available_at' => current_time( 'mysql' ), 'created_at' => $time, - ]; + ); } return (bool) $this->bulkInsert( $this->table(), $inserts ); @@ -56,7 +56,7 @@ public function push( array $events ) { */ public function pull( int $count ) { - $events = []; + $events = array(); $rawEvents = $this ->query() @@ -84,7 +84,7 @@ public function pull( int $count ) { /** * Remove events from the queue * - * @param int[] $ids + * @param int[] $ids * * @return bool */ @@ -99,7 +99,7 @@ public function remove( array $ids ) { /** * Reserve events in the queue * - * @param int[] $ids + * @param int[] $ids * * @return bool */ @@ -108,13 +108,13 @@ public function reserve( array $ids ) { ->query() ->table( $this->table(), false ) ->whereIn( 'id', $ids ) - ->update( [ 'reserved_at' => current_time( 'mysql' ) ] ); + ->update( array( 'reserved_at' => current_time( 'mysql' ) ) ); } /** * Release events back onto the queue * - * @param int[] $ids + * @param int[] $ids * * @return bool */ @@ -123,7 +123,7 @@ public function release( array $ids ) { ->query() ->table( $this->table(), false ) ->whereIn( 'id', $ids ) - ->update( [ 'reserved_at' => null ] ); + ->update( array( 'reserved_at' => null ) ); } /** diff --git a/includes/EventQueue/Queues/BatchQueueInterface.php b/includes/EventQueue/Queues/BatchQueueInterface.php index 4f9726b..f2b4912 100644 --- a/includes/EventQueue/Queues/BatchQueueInterface.php +++ b/includes/EventQueue/Queues/BatchQueueInterface.php @@ -9,7 +9,7 @@ interface BatchQueueInterface { /** * Push one or more events onto the queue * - * @param Event[] $events + * @param Event[] $events * * @return bool */ @@ -25,7 +25,7 @@ public function pull( int $count ); /** * Remove one or more events from the queue * - * @param Event[] $events + * @param Event[] $events * * @return bool */ @@ -34,7 +34,7 @@ public function remove( array $events ); /** * Reserve one or more events in the queue * - * @param Event[] $events + * @param Event[] $events * * @return bool */ @@ -43,7 +43,7 @@ public function reserve( array $events ); /** * Release one or more events back onto the queue * - * @param Event[] $events + * @param Event[] $events * * @return bool */ @@ -55,5 +55,4 @@ public function release( array $events ); * @return int */ public function count(); - } diff --git a/includes/Helpers/SiteHealth.php b/includes/Helpers/SiteHealth.php index d57f6a8..6117ae3 100644 --- a/includes/Helpers/SiteHealth.php +++ b/includes/Helpers/SiteHealth.php @@ -122,7 +122,7 @@ public static function calculate_score( $results ) { $total_tests = array_reduce( $results, - function( $total, $item ) { + function ( $total, $item ) { return $total += (int) $item; } ); @@ -134,5 +134,4 @@ function( $total, $item ) { return round( (int) $results['good'] / $total_tests * 100 ); } - } diff --git a/includes/Listeners/Content.php b/includes/Listeners/Content.php index 3aab99b..6e16d22 100644 --- a/includes/Listeners/Content.php +++ b/includes/Listeners/Content.php @@ -25,8 +25,8 @@ public function register_hooks() { /** * Post status transition * - * @param string $new_status The new post status - * @param string $old_status The old post status + * @param string $new_status The new post status + * @param string $old_status The old post status * @param \WP_Post $post Post object * * @return void @@ -94,8 +94,8 @@ public function count_posts() { /** * Comment status transition * - * @param string $new_status The new comment status - * @param string $old_status The new comment status + * @param string $new_status The new comment status + * @param string $old_status The new comment status * @param WP_Comment $comment Comment object * * @return void diff --git a/includes/Listeners/Listener.php b/includes/Listeners/Listener.php index a65ad39..82561c7 100644 --- a/includes/Listeners/Listener.php +++ b/includes/Listeners/Listener.php @@ -55,5 +55,4 @@ protected function get_class_name() { return substr( $class, $position + 1 ); } - } diff --git a/includes/Listeners/SiteHealth.php b/includes/Listeners/SiteHealth.php index 2299bc4..4f28317 100644 --- a/includes/Listeners/SiteHealth.php +++ b/includes/Listeners/SiteHealth.php @@ -33,8 +33,8 @@ public function tests_run( $value ) { $this->push( 'site_health_score', array( - 'label_key' => 'score', - 'score' => SiteHealthHelper::calculate_score( $value ), + 'label_key' => 'score', + 'score' => SiteHealthHelper::calculate_score( $value ), ) ); $this->push( diff --git a/includes/Listeners/Theme.php b/includes/Listeners/Theme.php index 2764b1a..afe9dae 100644 --- a/includes/Listeners/Theme.php +++ b/includes/Listeners/Theme.php @@ -54,7 +54,13 @@ public function theme_changed( $new_option, $old_option ) { public function mojo_preview() { global $theme; if ( isset( $_GET['page'] ) && 'mojo-theme-preview' === $_GET['page'] && ! is_wp_error( $theme ) ) { - $this->push( 'mojo_theme_preview', array( 'label_key' => 'theme', 'theme' => $theme ) ); + $this->push( + 'mojo_theme_preview', + array( + 'label_key' => 'theme', + 'theme' => $theme, + ) + ); } } @@ -65,6 +71,12 @@ public function mojo_preview() { */ public function browse_wporg_themes() { $category = ( isset( $_GET['browse'] ) ) ? esc_attr( $_GET['browse'] ) : 'featured'; - $this->push( 'browse_wporg_themes', array( 'label_key' => 'category', 'category' => $category ) ); + $this->push( + 'browse_wporg_themes', + array( + 'label_key' => 'category', + 'category' => $category, + ) + ); } } diff --git a/includes/Listeners/WonderCart.php b/includes/Listeners/WonderCart.php index 7be3efc..7b84415 100644 --- a/includes/Listeners/WonderCart.php +++ b/includes/Listeners/WonderCart.php @@ -83,7 +83,7 @@ public function create_campaign_modal_open( $args, $event ) { public function campaign_selected( $args, $event ) { $data = array( 'label_key' => 'campaign_slug', - 'type' => $args['type'], + 'type' => $args['type'], 'campaign_slug' => $args['type'], ); @@ -105,7 +105,7 @@ public function campaign_selected( $args, $event ) { public function campaign_abandoned( $args, $event ) { $data = array( 'label_key' => 'campaign_slug', - 'type' => $args['type'], + 'type' => $args['type'], 'campaign_slug' => $args['type'] . '-' . $args['id'], ); @@ -155,7 +155,7 @@ public function checkout_campaigns_used() { if ( count( $campaigns ) > 0 ) { $data = array( 'label_key' => 'type', - 'type' => array_unique( $campaigns ), + 'type' => array_unique( $campaigns ), 'campaign_count' => count( $campaigns ), 'campaign_total' => '$' . $campaign_total, ); diff --git a/includes/Listeners/Yoast.php b/includes/Listeners/Yoast.php index fb69c8f..097ab78 100644 --- a/includes/Listeners/Yoast.php +++ b/includes/Listeners/Yoast.php @@ -7,23 +7,23 @@ */ class Yoast extends Listener { // We don't want to track these fields - private $site_representation_skip_fields = [ 'company_logo_id', 'person_logo_id', 'description' ]; + private $site_representation_skip_fields = array( 'company_logo_id', 'person_logo_id', 'description' ); // The names used for Hiive events tracking are different from the names used for the Yoast options - private $site_representation_map = [ + private $site_representation_map = array( 'company_or_person' => 'site_representation', 'company_name' => 'organization_name', 'company_logo' => 'organization_logo', 'person_logo' => 'logo', 'company_or_person_user_id' => 'name', 'website_name' => 'website_name', - ]; + ); - private $social_profiles_map = [ + private $social_profiles_map = array( 'facebook_site' => 'facebook_profile', 'twitter_site' => 'twitter_profile', 'other_social_urls' => 'other_profiles', - ]; + ); /** * Register the hooks for the listener @@ -32,9 +32,9 @@ class Yoast extends Listener { */ public function register_hooks() { // First time configuration - add_action('wpseo_ftc_post_update_site_representation', array( $this, 'site_representation_updated' ), 10, 3 ); - add_action('wpseo_ftc_post_update_social_profiles', array( $this, 'social_profiles_updated' ), 10, 3 ); - add_action('wpseo_ftc_post_update_enable_tracking', array( $this, 'tracking_updated' ), 10, 3 ); + add_action( 'wpseo_ftc_post_update_site_representation', array( $this, 'site_representation_updated' ), 10, 3 ); + add_action( 'wpseo_ftc_post_update_social_profiles', array( $this, 'social_profiles_updated' ), 10, 3 ); + add_action( 'wpseo_ftc_post_update_enable_tracking', array( $this, 'tracking_updated' ), 10, 3 ); } /** @@ -56,7 +56,7 @@ public function site_representation_updated( $new_values, $old_values, $failures $mapped_old_values = $this->map_params_names_to_hiive_names( $old_values, $this->site_representation_map, $this->site_representation_skip_fields ); $mapped_failures = $this->map_failures_to_hiive_names( $failures, $this->site_representation_map, $this->site_representation_skip_fields ); - foreach ($mapped_new_values as $key => $value) { + foreach ( $mapped_new_values as $key => $value ) { $this->maybe_push_site_representation_event( $key, $value, $mapped_old_values[ $key ], \in_array( $key, $mapped_failures ) ); } } @@ -72,8 +72,8 @@ public function site_representation_updated( $new_values, $old_values, $failures */ public function social_profiles_updated( $new_values, $old_values, $failures ) { // Yoast stores only twitter username, and $new_values stores the pre-processed values - if ( strpos( $new_values[ 'twitter_site' ], 'twitter.com/' ) !== false ) { - $new_values[ 'twitter_site' ] = (explode( 'twitter.com/', $new_values[ 'twitter_site' ])[ 1 ] ); + if ( strpos( $new_values['twitter_site'], 'twitter.com/' ) !== false ) { + $new_values['twitter_site'] = ( explode( 'twitter.com/', $new_values['twitter_site'] )[1] ); } // All the options are unchanged, opt out @@ -88,10 +88,10 @@ public function social_profiles_updated( $new_values, $old_values, $failures ) { $mapped_old_values = $this->map_params_names_to_hiive_names( $old_values, $this->social_profiles_map ); $mapped_failures = $this->map_failures_to_hiive_names( $cleaned_failures, $this->social_profiles_map ); - foreach ($mapped_values as $key => $value) { + foreach ( $mapped_values as $key => $value ) { // The option update failed if ( \in_array( $key, $mapped_failures ) ) { - $this->push( "failed_$key", [ 'category' => 'ftc_personal_profiles' ] ); + $this->push( "failed_$key", array( 'category' => 'ftc_personal_profiles' ) ); return; } @@ -116,7 +116,7 @@ public function tracking_updated( $new_value, $old_value, $failed ) { return; } - $failed ? $this->push( "failed_usage_tracking", [ 'category' => 'ftc_tracking' ] ) : $this->push( "changed_usage_tracking", [ 'category' => 'ftc_tracking' ] ); + $failed ? $this->push( 'failed_usage_tracking', array( 'category' => 'ftc_tracking' ) ) : $this->push( 'changed_usage_tracking', array( 'category' => 'ftc_tracking' ) ); } /** @@ -134,7 +134,7 @@ private function maybe_push_site_representation_event( $key, $value, $old_value, // The option update failed if ( $failure ) { - $this->push( "failed_$key", [ 'category' => $category] ); + $this->push( "failed_$key", array( 'category' => $category ) ); return; } @@ -154,8 +154,8 @@ private function maybe_push_site_representation_event( $key, $value, $old_value, // switched from organisation to person, and then the person id is being set. // Once the name is assigned an integer > 0, it can never go back to 0, even if the user switches back to organisation // ( it "caches" the last user id that was set) - if ( ( $this->is_param_empty( $old_value) ) || ( $key === 'name' && $old_value === 0 ) ){ - $this->push( "set_$key", [ 'category' => $category] ); + if ( ( $this->is_param_empty( $old_value ) ) || ( $key === 'name' && $old_value === 0 ) ) { + $this->push( "set_$key", array( 'category' => $category ) ); return; } @@ -164,7 +164,7 @@ private function maybe_push_site_representation_event( $key, $value, $old_value, 'category' => $category, 'data' => array( 'label_key' => $key, - 'new_value' => $value + 'new_value' => $value, ), ); @@ -190,7 +190,7 @@ private function maybe_push_social_profiles_event( $key, $value, $old_value, $fa // The option update failed if ( $failure ) { - $this->push( "failed_$key", [ 'category' => $category] ); + $this->push( "failed_$key", array( 'category' => $category ) ); return; } @@ -202,13 +202,13 @@ private function maybe_push_social_profiles_event( $key, $value, $old_value, $fa } // The option was set for the first time - if ( $this->is_param_empty( $old_value) ){ - $this->push( "set_$key", [ 'category' => $category] ); + if ( $this->is_param_empty( $old_value ) ) { + $this->push( "set_$key", array( 'category' => $category ) ); return; } // The option was updated - $this->push( "changed_$key", [ 'category' => $category ] ); + $this->push( "changed_$key", array( 'category' => $category ) ); } } @@ -225,13 +225,13 @@ private function maybe_push_social_profiles_event( $key, $value, $old_value, $fa */ private function push_other_social_profiles( $key, $new_value, $old_value, $category ) { // The option was set for the first time - if ( $this->is_param_empty( $old_value) ){ - $this->push( "set_$key", [ 'category' => $category] ); + if ( $this->is_param_empty( $old_value ) ) { + $this->push( "set_$key", array( 'category' => $category ) ); return; } $changed_profiles = \array_map( - function( $value ) { + function ( $value ) { return $this->get_base_url( \wp_unslash( $value ) ); }, $new_value @@ -242,11 +242,11 @@ function( $value ) { 'category' => $category, 'data' => array( 'label_key' => $key, - 'new_value' => $changed_profiles - ), - ); - - $this->push( "changed_other_profiles", $data ); + 'new_value' => $changed_profiles, + ), + ); + + $this->push( 'changed_other_profiles', $data ); } /** @@ -258,8 +258,8 @@ function( $value ) { * * @return array The mapped params. */ - private function map_params_names_to_hiive_names( $params, $map, $skip_fields=[] ) { - $mapped_params = []; + private function map_params_names_to_hiive_names( $params, $map, $skip_fields = array() ) { + $mapped_params = array(); foreach ( $params as $param_name => $param_value ) { if ( in_array( $param_name, $skip_fields, true ) ) { @@ -282,10 +282,10 @@ private function map_params_names_to_hiive_names( $params, $map, $skip_fields=[] * * @return array The mapped params names. */ - private function map_failures_to_hiive_names( $failures, $map, $skip_fields=[] ) { - $mapped_failures = []; + private function map_failures_to_hiive_names( $failures, $map, $skip_fields = array() ) { + $mapped_failures = array(); - foreach ( $failures as $failed_field_name) { + foreach ( $failures as $failed_field_name ) { if ( in_array( $failed_field_name, $skip_fields, true ) ) { continue; } @@ -331,8 +331,8 @@ private function get_base_url( $url ) { * * @return array The cleaned failures array */ - private function clean_social_profiles_failures ( $failures ) { - $cleaned_failures = []; + private function clean_social_profiles_failures( $failures ) { + $cleaned_failures = array(); $other_social_profiles_failed = false; foreach ( $failures as $failure ) { @@ -349,4 +349,4 @@ private function clean_social_profiles_failures ( $failures ) { return $cleaned_failures; } -} \ No newline at end of file +} diff --git a/includes/Logger.php b/includes/Logger.php index e8dcb9c..28d05d6 100644 --- a/includes/Logger.php +++ b/includes/Logger.php @@ -18,7 +18,7 @@ public function notify( $events ) { return; } $log = wp_json_encode( $event, JSON_UNESCAPED_SLASHES ) . "\n"; - file_put_contents( dirname( dirname( __FILE__ ) ) . '/debug.log', $log, FILE_APPEND ); + file_put_contents( dirname( __DIR__ ) . '/debug.log', $log, FILE_APPEND ); } } } diff --git a/includes/SiteClassification/PrimaryType.php b/includes/SiteClassification/PrimaryType.php index 26e4261..2f9b080 100644 --- a/includes/SiteClassification/PrimaryType.php +++ b/includes/SiteClassification/PrimaryType.php @@ -61,7 +61,7 @@ public static function instantiate_from_option() { return false; } - $instance = new static( $data['refers'], $data['value'] ); + $instance = new self( $data['refers'], $data['value'] ); if ( ! $instance->validate() ) { delete_option( self::$primary_option_name ); return false; diff --git a/includes/SiteClassification/SecondaryType.php b/includes/SiteClassification/SecondaryType.php index 7ddbb7f..429c3be 100644 --- a/includes/SiteClassification/SecondaryType.php +++ b/includes/SiteClassification/SecondaryType.php @@ -68,7 +68,7 @@ public static function instantiate_from_option() { return false; } - $instance = new static( $data['refers'], $data['value'] ); + $instance = new self( $data['refers'], $data['value'] ); if ( ! $instance->validate() ) { delete_option( self::$secondary_option_name ); return false; diff --git a/includes/SiteClassification/SiteClassification.php b/includes/SiteClassification/SiteClassification.php index 6270a09..d0ee617 100644 --- a/includes/SiteClassification/SiteClassification.php +++ b/includes/SiteClassification/SiteClassification.php @@ -115,6 +115,5 @@ public static function fetch_from_static_file( $locale = 'en-US' ) { } return $data; - } } diff --git a/includes/SiteClassification/Types.php b/includes/SiteClassification/Types.php index 269a3c2..4be6375 100644 --- a/includes/SiteClassification/Types.php +++ b/includes/SiteClassification/Types.php @@ -71,7 +71,6 @@ public function save() { } update_option( $this->option_name, $this->to_array() ); return true; - } /** @@ -92,5 +91,4 @@ public function to_array() { * @return boolean */ abstract public function validate(); - }