Skip to content

Commit ef524d1

Browse files
committed
Allow short ternary (Elvis) operator in codebase
Removes all inline phpcs ignore comments for the Universal.Operators.DisallowShortTernary rule and updates phpcs.xml to exclude this rule, permitting use of the short ternary (Elvis) operator throughout the codebase.
1 parent afd6e00 commit ef524d1

File tree

9 files changed

+13
-12
lines changed

9 files changed

+13
-12
lines changed

includes/class-avatars.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public static function pre_get_avatar_data( $args, $id_or_email ) {
4343
* @param array $allowed_comment_types Array of allowed comment types.
4444
*/
4545
$allowed_comment_types = \apply_filters( 'get_avatar_comment_types', array( 'comment' ) );
46-
if ( ! \in_array( $id_or_email->comment_type ?: 'comment', $allowed_comment_types, true ) ) { // phpcs:ignore Universal.Operators.DisallowShortTernary
46+
if ( ! \in_array( $id_or_email->comment_type ?: 'comment', $allowed_comment_types, true ) ) {
4747
return $args;
4848
}
4949

includes/class-moderation.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public static function add_user_block( $user_id, $type, $value ) {
116116

117117
case self::TYPE_DOMAIN:
118118
case self::TYPE_KEYWORD:
119-
$blocks = \get_user_meta( $user_id, self::USER_META_KEYS[ $type ], true ) ?: array(); // phpcs:ignore Universal.Operators.DisallowShortTernary.Found
119+
$blocks = \get_user_meta( $user_id, self::USER_META_KEYS[ $type ], true ) ?: array();
120120

121121
if ( ! \in_array( $value, $blocks, true ) ) {
122122
/**
@@ -152,7 +152,7 @@ public static function remove_user_block( $user_id, $type, $value ) {
152152

153153
case self::TYPE_DOMAIN:
154154
case self::TYPE_KEYWORD:
155-
$blocks = \get_user_meta( $user_id, self::USER_META_KEYS[ $type ], true ) ?: array(); // phpcs:ignore Universal.Operators.DisallowShortTernary.Found
155+
$blocks = \get_user_meta( $user_id, self::USER_META_KEYS[ $type ], true ) ?: array();
156156
$key = \array_search( $value, $blocks, true );
157157

158158
if ( false !== $key ) {
@@ -183,8 +183,8 @@ public static function remove_user_block( $user_id, $type, $value ) {
183183
public static function get_user_blocks( $user_id ) {
184184
return array(
185185
'actors' => \wp_list_pluck( Blocked_Actors::get_many( $user_id ), 'guid' ),
186-
'domains' => \get_user_meta( $user_id, self::USER_META_KEYS[ self::TYPE_DOMAIN ], true ) ?: array(), // phpcs:ignore Universal.Operators.DisallowShortTernary.Found
187-
'keywords' => \get_user_meta( $user_id, self::USER_META_KEYS[ self::TYPE_KEYWORD ], true ) ?: array(), // phpcs:ignore Universal.Operators.DisallowShortTernary.Found
186+
'domains' => \get_user_meta( $user_id, self::USER_META_KEYS[ self::TYPE_DOMAIN ], true ) ?: array(),
187+
'keywords' => \get_user_meta( $user_id, self::USER_META_KEYS[ self::TYPE_KEYWORD ], true ) ?: array(),
188188
);
189189
}
190190

includes/class-move.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ public static function internally( $from, $to ) {
172172
* @param string $from The current account URL.
173173
*/
174174
private static function update_user_also_known_as( $user_id, $from ) {
175-
// phpcs:ignore Universal.Operators.DisallowShortTernary.Found
176175
$also_known_as = \get_user_option( 'activitypub_also_known_as', $user_id ) ?: array();
177176
$also_known_as[] = $from;
178177

includes/collection/class-inbox.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,9 @@ private static function get_object_title( $activity_object ) {
143143
return $post_id ? \get_the_title( $post_id ) : '';
144144
}
145145

146-
// phpcs:ignore Universal.Operators.DisallowShortTernary.Found
147146
$title = $activity_object->get_name() ?: $activity_object->get_content();
148147

149148
if ( ! $title && $activity_object->get_object() instanceof Base_Object ) {
150-
// phpcs:ignore Universal.Operators.DisallowShortTernary.Found
151149
$title = $activity_object->get_object()->get_name() ?: $activity_object->get_object()->get_content();
152150
}
153151

includes/model/class-user.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,6 @@ public function get_also_known_as() {
452452
$this->get_alternate_url(),
453453
);
454454

455-
// phpcs:ignore Universal.Operators.DisallowShortTernary.Found
456455
$also_known_as = array_merge( $also_known_as, \get_user_option( 'activitypub_also_known_as', $this->_id ) ?: array() );
457456

458457
return array_unique( $also_known_as );

includes/transformer/class-post.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,7 @@ protected function get_context() {
891891
*/
892892
protected function get_post_content_template() {
893893
$content = \get_option( 'activitypub_custom_post_content', ACTIVITYPUB_CUSTOM_POST_CONTENT );
894-
$template = $content ?: ACTIVITYPUB_CUSTOM_POST_CONTENT; // phpcs:ignore Universal.Operators.DisallowShortTernary.Found
894+
$template = $content ?: ACTIVITYPUB_CUSTOM_POST_CONTENT;
895895

896896
$post_format_setting = \get_option( 'activitypub_object_type', ACTIVITYPUB_DEFAULT_OBJECT_TYPE );
897897
$type = $this->get_type();

integration/class-classic-editor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public static function render_meta_box( $post ) {
131131
$content_warning = \get_post_meta( $post->ID, 'activitypub_content_warning', true );
132132
$max_image_attachments = \get_post_meta( $post->ID, 'activitypub_max_image_attachments', true );
133133
$content_visibility = self::get_default_visibility( $post );
134-
$quote_interaction = \get_post_meta( $post->ID, 'activitypub_interaction_policy_quote', true ) ?: ACTIVITYPUB_INTERACTION_POLICY_ANYONE; // phpcs:ignore Universal.Operators.DisallowShortTernary
134+
$quote_interaction = \get_post_meta( $post->ID, 'activitypub_interaction_policy_quote', true ) ?: ACTIVITYPUB_INTERACTION_POLICY_ANYONE;
135135

136136
?>
137137
<p>

integration/class-wp-rest-cache.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public static function transition_comment_status( $new_status, $old_status, $com
126126
$comment_types = Comment::get_comment_type_slugs();
127127
$comment_types[] = 'comment';
128128

129-
if ( ! \in_array( $comment->comment_type ?: 'comment', $comment_types, true ) ) { // phpcs:ignore Universal.Operators.DisallowShortTernary
129+
if ( ! \in_array( $comment->comment_type ?: 'comment', $comment_types, true ) ) {
130130
return;
131131
}
132132

phpcs.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,9 @@
3131
</property>
3232
</properties>
3333
</rule>
34+
35+
<!-- Allow short ternary operators (Elvis operator) -->
36+
<rule ref="WordPress">
37+
<exclude name="Universal.Operators.DisallowShortTernary" />
38+
</rule>
3439
</ruleset>

0 commit comments

Comments
 (0)