Skip to content

Commit 2b2f646

Browse files
authored
Replace null coalescing with short ternary operators (#2433)
1 parent afd6e00 commit 2b2f646

File tree

10 files changed

+32
-15
lines changed

10 files changed

+32
-15
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: fixed
3+
4+
Improved handling of empty fields for better compatibility with Pixelfed and more consistent fallback behavior across actor names, URLs, and related data.

build/followers/render.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,10 @@ function ( $follower ) {
6464
return array(
6565
'handle' => '@' . $username,
6666
'icon' => $actor->get_icon(),
67-
'name' => $actor->get_name() ?? $username,
68-
'url' => object_to_uri( $actor->get_url() ) ?? $actor->get_id(),
67+
// phpcs:ignore Universal.Operators.DisallowShortTernary.Found
68+
'name' => $actor->get_name() ?: $username,
69+
// phpcs:ignore Universal.Operators.DisallowShortTernary.Found
70+
'url' => object_to_uri( $actor->get_url() ) ?: $actor->get_id(),
6971
);
7072
},
7173
$follower_data['followers']

includes/class-embed.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public static function get_html_for_object( $activity_object, $inline_css = true
5858
$author = Http::get_remote_object( $author_url );
5959
if ( ! is_wp_error( $author ) ) {
6060
$avatar_url = $author['icon']['url'] ?? '';
61-
$author_name = $author['name'] ?? $author_name;
61+
$author_name = empty( $author['name'] ) ? $author_name : $author['name'];
6262
}
6363
}
6464

includes/collection/class-interactions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public static function update_comment( $activity ) {
7878
}
7979

8080
// Found a local comment id.
81-
$comment_data['comment_author'] = \esc_attr( $meta['name'] ?? $meta['preferredUsername'] );
81+
$comment_data['comment_author'] = \esc_attr( empty( $meta['name'] ) ? $meta['preferredUsername'] : $meta['name'] );
8282
$comment_data['comment_content'] = \addslashes( $activity['object']['content'] );
8383

8484
return self::persist( $comment_data, self::UPDATE );

includes/collection/class-outbox.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,10 +385,12 @@ private static function get_object_title( $activity_object ) {
385385
return $post_id ? get_the_title( $post_id ) : '';
386386
}
387387

388-
$title = $activity_object->get_name() ?? $activity_object->get_content();
388+
// phpcs:ignore Universal.Operators.DisallowShortTernary.Found
389+
$title = $activity_object->get_name() ?: $activity_object->get_content();
389390

390391
if ( ! $title && $activity_object->get_object() instanceof Base_Object ) {
391-
$title = $activity_object->get_object()->get_name() ?? $activity_object->get_object()->get_content();
392+
// phpcs:ignore Universal.Operators.DisallowShortTernary.Found
393+
$title = $activity_object->get_object()->get_name() ?: $activity_object->get_object()->get_content();
392394
}
393395

394396
return $title;

includes/collection/class-remote-actors.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,8 @@ private static function prepare_custom_post_type( $actor ) {
527527

528528
return array(
529529
'guid' => \esc_url_raw( $actor->get_id() ),
530-
'post_title' => \wp_strip_all_tags( \wp_slash( $actor->get_name() ?? $actor->get_preferred_username() ) ),
530+
// phpcs:ignore Universal.Operators.DisallowShortTernary.Found
531+
'post_title' => \wp_strip_all_tags( \wp_slash( $actor->get_name() ?: $actor->get_preferred_username() ) ),
531532
'post_author' => 0,
532533
'post_type' => self::POST_TYPE,
533534
'post_content' => \wp_slash( $actor_json ),

includes/wp-admin/table/class-blocked-actors.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,11 @@ public function prepare_items() {
231231
$this->items[] = array(
232232
'id' => $blocked_actor_post->ID,
233233
'icon' => object_to_uri( $actor->get_icon() ?? ACTIVITYPUB_PLUGIN_URL . 'assets/img/mp.jpg' ),
234-
'post_title' => $actor->get_name() ?? $actor->get_preferred_username(),
234+
// phpcs:ignore Universal.Operators.DisallowShortTernary.Found
235+
'post_title' => $actor->get_name() ?: $actor->get_preferred_username(),
235236
'username' => $actor->get_preferred_username(),
236-
'url' => object_to_uri( $actor->get_url() ?? $actor->get_id() ),
237+
// phpcs:ignore Universal.Operators.DisallowShortTernary.Found
238+
'url' => object_to_uri( $actor->get_url() ?: $actor->get_id() ),
237239
'webfinger' => Remote_Actors::get_acct( $blocked_actor_post->ID ),
238240
'identifier' => $actor->get_id(),
239241
'modified' => $blocked_actor_post->post_modified_gmt,

includes/wp-admin/table/class-followers.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,9 +283,11 @@ public function prepare_items() {
283283
$this->items[] = array(
284284
'id' => $follower->ID,
285285
'icon' => object_to_uri( $actor->get_icon() ?? ACTIVITYPUB_PLUGIN_URL . 'assets/img/mp.jpg' ),
286-
'post_title' => $actor->get_name() ?? $actor->get_preferred_username(),
286+
// phpcs:ignore Universal.Operators.DisallowShortTernary.Found
287+
'post_title' => $actor->get_name() ?: $actor->get_preferred_username(),
287288
'username' => $actor->get_preferred_username(),
288-
'url' => object_to_uri( $actor->get_url() ?? $actor->get_id() ),
289+
// phpcs:ignore Universal.Operators.DisallowShortTernary.Found
290+
'url' => object_to_uri( $actor->get_url() ?: $actor->get_id() ),
289291
'webfinger' => Remote_Actors::get_acct( $follower->ID ),
290292
'identifier' => $actor->get_id(),
291293
'modified' => $follower->post_modified_gmt,

includes/wp-admin/table/class-following.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,11 @@ public function prepare_items() {
251251
$this->items[] = array(
252252
'id' => $following->ID,
253253
'icon' => object_to_uri( $actor->get_icon() ?? ACTIVITYPUB_PLUGIN_URL . 'assets/img/mp.jpg' ),
254-
'post_title' => $actor->get_name() ?? $actor->get_preferred_username(),
254+
// phpcs:ignore Universal.Operators.DisallowShortTernary.Found
255+
'post_title' => $actor->get_name() ?: $actor->get_preferred_username(),
255256
'username' => $actor->get_preferred_username(),
256-
'url' => object_to_uri( $actor->get_url() ?? $actor->get_id() ),
257+
// phpcs:ignore Universal.Operators.DisallowShortTernary.Found
258+
'url' => object_to_uri( $actor->get_url() ?: $actor->get_id() ),
257259
'webfinger' => Remote_Actors::get_acct( $following->ID ),
258260
'status' => Following_Collection::check_status( $this->user_id, $following->ID ),
259261
'identifier' => $actor->get_id(),

src/followers/render.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,10 @@ function ( $follower ) {
6464
return array(
6565
'handle' => '@' . $username,
6666
'icon' => $actor->get_icon(),
67-
'name' => $actor->get_name() ?? $username,
68-
'url' => object_to_uri( $actor->get_url() ) ?? $actor->get_id(),
67+
// phpcs:ignore Universal.Operators.DisallowShortTernary.Found
68+
'name' => $actor->get_name() ?: $username,
69+
// phpcs:ignore Universal.Operators.DisallowShortTernary.Found
70+
'url' => object_to_uri( $actor->get_url() ) ?: $actor->get_id(),
6971
);
7072
},
7173
$follower_data['followers']

0 commit comments

Comments
 (0)