From a07e74299d2ab8efa57f20f6f1a54ebd95135383 Mon Sep 17 00:00:00 2001 From: Tosin Oguntuyi Date: Fri, 16 Feb 2024 10:10:34 +0100 Subject: [PATCH 1/6] Get the array of events user is attending --- ...ss-wporg-gp-translation-events-translation-listener.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/includes/class-wporg-gp-translation-events-translation-listener.php b/includes/class-wporg-gp-translation-events-translation-listener.php index 95a55f14..1cd2a69a 100644 --- a/includes/class-wporg-gp-translation-events-translation-listener.php +++ b/includes/class-wporg-gp-translation-events-translation-listener.php @@ -154,13 +154,12 @@ function ( $event ) use ( $at ) { * @param WPORG_GP_Translation_Events_Event[] $events Events. * @return WPORG_GP_Translation_Events_Event[] */ - // phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed - // phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.Found private function select_events_user_is_registered_for( array $events, int $user_id ): array { + $attending_events = get_user_meta( $user_id, 'translation-events-attending', true ); return array_filter( $events, - function ( $event ) use ( $attending_event_ids ) { - return isset( $attending_event_ids[ $event->ID ] ); + function ( $event ) use ( $attending_events ) { + return isset( $attending_events[ $event->id() ] ); } ); } From 9ae7586b67d83c02a79958d27424861f91ff678d Mon Sep 17 00:00:00 2001 From: Tosin Oguntuyi Date: Fri, 16 Feb 2024 10:15:59 +0100 Subject: [PATCH 2/6] Add back phpcs comments --- .../class-wporg-gp-translation-events-translation-listener.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/includes/class-wporg-gp-translation-events-translation-listener.php b/includes/class-wporg-gp-translation-events-translation-listener.php index 1cd2a69a..e20ac256 100644 --- a/includes/class-wporg-gp-translation-events-translation-listener.php +++ b/includes/class-wporg-gp-translation-events-translation-listener.php @@ -154,6 +154,8 @@ function ( $event ) use ( $at ) { * @param WPORG_GP_Translation_Events_Event[] $events Events. * @return WPORG_GP_Translation_Events_Event[] */ + // phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed + // phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.Found private function select_events_user_is_registered_for( array $events, int $user_id ): array { $attending_events = get_user_meta( $user_id, 'translation-events-attending', true ); return array_filter( From 5c0752ec82aea41ff65eff6558499c2bd78f4d4f Mon Sep 17 00:00:00 2001 From: Tosin Oguntuyi Date: Fri, 16 Feb 2024 11:52:25 +0100 Subject: [PATCH 3/6] Use USER_META_KEY_ATTENDING constant --- .../class-wporg-gp-translation-events-translation-listener.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/class-wporg-gp-translation-events-translation-listener.php b/includes/class-wporg-gp-translation-events-translation-listener.php index e20ac256..727dad25 100644 --- a/includes/class-wporg-gp-translation-events-translation-listener.php +++ b/includes/class-wporg-gp-translation-events-translation-listener.php @@ -157,7 +157,7 @@ function ( $event ) use ( $at ) { // phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed // phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.Found private function select_events_user_is_registered_for( array $events, int $user_id ): array { - $attending_events = get_user_meta( $user_id, 'translation-events-attending', true ); + $attending_events = get_user_meta( $user_id, WPORG_GP_Translation_Events_Route::USER_META_KEY_ATTENDING, true ); return array_filter( $events, function ( $event ) use ( $attending_events ) { From 9611feb9701de8a6b02dc671ce67163203cffded Mon Sep 17 00:00:00 2001 From: Alex Kirk Date: Fri, 16 Feb 2024 12:02:40 +0100 Subject: [PATCH 4/6] Reduce diff size --- ...ass-wporg-gp-translation-events-translation-listener.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/class-wporg-gp-translation-events-translation-listener.php b/includes/class-wporg-gp-translation-events-translation-listener.php index 727dad25..50639295 100644 --- a/includes/class-wporg-gp-translation-events-translation-listener.php +++ b/includes/class-wporg-gp-translation-events-translation-listener.php @@ -157,11 +157,11 @@ function ( $event ) use ( $at ) { // phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed // phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.Found private function select_events_user_is_registered_for( array $events, int $user_id ): array { - $attending_events = get_user_meta( $user_id, WPORG_GP_Translation_Events_Route::USER_META_KEY_ATTENDING, true ); + $attending_events_ids = get_user_meta( $user_id, WPORG_GP_Translation_Events_Route::USER_META_KEY_ATTENDING, true ); return array_filter( $events, - function ( $event ) use ( $attending_events ) { - return isset( $attending_events[ $event->id() ] ); + function ( $event ) use ( $attending_events_ids ) { + return isset( $attending_events_ids[ $event->id() ] ); } ); } From 32d2309ad3fedbaf2209a46f82852454787f4847 Mon Sep 17 00:00:00 2001 From: Alex Kirk Date: Fri, 16 Feb 2024 12:02:55 +0100 Subject: [PATCH 5/6] Reduce diff size --- ...ass-wporg-gp-translation-events-translation-listener.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/class-wporg-gp-translation-events-translation-listener.php b/includes/class-wporg-gp-translation-events-translation-listener.php index 50639295..b6499807 100644 --- a/includes/class-wporg-gp-translation-events-translation-listener.php +++ b/includes/class-wporg-gp-translation-events-translation-listener.php @@ -157,11 +157,11 @@ function ( $event ) use ( $at ) { // phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed // phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.Found private function select_events_user_is_registered_for( array $events, int $user_id ): array { - $attending_events_ids = get_user_meta( $user_id, WPORG_GP_Translation_Events_Route::USER_META_KEY_ATTENDING, true ); + $attending_event_ids = get_user_meta( $user_id, WPORG_GP_Translation_Events_Route::USER_META_KEY_ATTENDING, true ); return array_filter( $events, - function ( $event ) use ( $attending_events_ids ) { - return isset( $attending_events_ids[ $event->id() ] ); + function ( $event ) use ( $attending_event_ids ) { + return isset( $attending_event_ids[ $event->id() ] ); } ); } From 1f93e6cf8d243c3cac99ad7d124ef671e7f4c384 Mon Sep 17 00:00:00 2001 From: Tosin Oguntuyi Date: Fri, 16 Feb 2024 12:27:18 +0100 Subject: [PATCH 6/6] Add WPORG_GP_Translation_Events_Event type hint --- .../class-wporg-gp-translation-events-translation-listener.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/class-wporg-gp-translation-events-translation-listener.php b/includes/class-wporg-gp-translation-events-translation-listener.php index b6499807..df962058 100644 --- a/includes/class-wporg-gp-translation-events-translation-listener.php +++ b/includes/class-wporg-gp-translation-events-translation-listener.php @@ -160,7 +160,7 @@ private function select_events_user_is_registered_for( array $events, int $user_ $attending_event_ids = get_user_meta( $user_id, WPORG_GP_Translation_Events_Route::USER_META_KEY_ATTENDING, true ); return array_filter( $events, - function ( $event ) use ( $attending_event_ids ) { + function ( WPORG_GP_Translation_Events_Event $event ) use ( $attending_event_ids ) { return isset( $attending_event_ids[ $event->id() ] ); } );